mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-13 22:15:04 +00:00
chore: workaround for using this before super call
This commit is contained in:
parent
b95436576e
commit
72a521f4e1
@ -31,12 +31,13 @@ export const FilterCodecs = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
||||||
|
private handleIncomingMessage: (
|
||||||
|
pubsubTopic: PubsubTopic,
|
||||||
|
message: WakuMessage,
|
||||||
|
peerId: string
|
||||||
|
) => void = () => {};
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private handleIncomingMessage: (
|
|
||||||
pubsubTopic: PubsubTopic,
|
|
||||||
wakuMessage: WakuMessage,
|
|
||||||
peerIdStr: string
|
|
||||||
) => void,
|
|
||||||
public readonly pubsubTopics: PubsubTopic[],
|
public readonly pubsubTopics: PubsubTopic[],
|
||||||
libp2p: Libp2p
|
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(
|
public async subscribe(
|
||||||
pubsubTopic: PubsubTopic,
|
pubsubTopic: PubsubTopic,
|
||||||
peer: Peer,
|
peer: Peer,
|
||||||
|
@ -39,32 +39,12 @@ class FilterSDK extends BaseProtocolSDK implements IFilterSDK {
|
|||||||
|
|
||||||
public activeSubscriptions = new Map<PubsubTopic, SubscriptionManager>();
|
public activeSubscriptions = new Map<PubsubTopic, SubscriptionManager>();
|
||||||
|
|
||||||
public constructor(
|
public handleIncomingMessage = (
|
||||||
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: (
|
|
||||||
pubsubTopic: PubsubTopic,
|
pubsubTopic: PubsubTopic,
|
||||||
message: WakuMessage,
|
message: WakuMessage,
|
||||||
peerIdStr: PeerIdStr
|
peerIdStr: PeerIdStr
|
||||||
) => void = (pubsubTopic, message) => {
|
): void => {
|
||||||
|
log.info(`Received message from ${peerIdStr} on topic ${pubsubTopic}`);
|
||||||
const subscription = this.getActiveSubscription(pubsubTopic);
|
const subscription = this.getActiveSubscription(pubsubTopic);
|
||||||
if (!subscription) {
|
if (!subscription) {
|
||||||
log.error(`No subscription locally registered for topic ${pubsubTopic}`);
|
log.error(`No subscription locally registered for topic ${pubsubTopic}`);
|
||||||
@ -74,6 +54,22 @@ class FilterSDK extends BaseProtocolSDK implements IFilterSDK {
|
|||||||
void subscription.processIncomingMessage(message);
|
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(
|
public setIncomingMessageHandler(
|
||||||
handler: (
|
handler: (
|
||||||
pubsubTopic: PubsubTopic,
|
pubsubTopic: PubsubTopic,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user