chore: workaround for using this before super call

This commit is contained in:
Danish Arora 2024-09-10 17:02:39 +05:30
parent b95436576e
commit 72a521f4e1
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
2 changed files with 35 additions and 28 deletions

View File

@ -31,12 +31,13 @@ export const FilterCodecs = {
};
export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
private handleIncomingMessage: (
pubsubTopic: PubsubTopic,
message: WakuMessage,
peerId: string
) => void = () => {};
public constructor(
private handleIncomingMessage: (
pubsubTopic: PubsubTopic,
wakuMessage: WakuMessage,
peerIdStr: string
) => void,
public readonly pubsubTopics: PubsubTopic[],
libp2p: Libp2p
) {
@ -51,6 +52,16 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
});
}
public set incomingMessageHandler(
handler: (
pubsubTopic: PubsubTopic,
message: WakuMessage,
peerId: string
) => void
) {
this.handleIncomingMessage = handler;
}
public async subscribe(
pubsubTopic: PubsubTopic,
peer: Peer,

View File

@ -39,32 +39,12 @@ class FilterSDK extends BaseProtocolSDK implements IFilterSDK {
public activeSubscriptions = new Map<PubsubTopic, SubscriptionManager>();
public constructor(
connectionManager: ConnectionManager,
libp2p: Libp2p,
options?: ProtocolCreateOptions
) {
super(
new FilterCore(
(pubsubTopic, message, peerIdStr) =>
this.handleIncomingMessage(pubsubTopic, message, peerIdStr),
connectionManager.configuredPubsubTopics,
libp2p
),
connectionManager,
{ numPeersToUse: options?.numPeersToUse }
);
this.protocol = this.core as FilterCore;
this._connectionManager = connectionManager;
}
public handleIncomingMessage: (
public handleIncomingMessage = (
pubsubTopic: PubsubTopic,
message: WakuMessage,
peerIdStr: PeerIdStr
) => void = (pubsubTopic, message) => {
): void => {
log.info(`Received message from ${peerIdStr} on topic ${pubsubTopic}`);
const subscription = this.getActiveSubscription(pubsubTopic);
if (!subscription) {
log.error(`No subscription locally registered for topic ${pubsubTopic}`);
@ -74,6 +54,22 @@ class FilterSDK extends BaseProtocolSDK implements IFilterSDK {
void subscription.processIncomingMessage(message);
};
public constructor(
connectionManager: ConnectionManager,
libp2p: Libp2p,
options?: ProtocolCreateOptions
) {
super(
new FilterCore(connectionManager.configuredPubsubTopics, libp2p),
connectionManager,
{ numPeersToUse: options?.numPeersToUse }
);
this.protocol = this.core as FilterCore;
this.protocol.incomingMessageHandler = this.handleIncomingMessage;
this._connectionManager = connectionManager;
}
public setIncomingMessageHandler(
handler: (
pubsubTopic: PubsubTopic,