mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-22 17:18:15 +00:00
add: peerId to ping
and unsubscribeAll
This commit is contained in:
parent
c5a9f19a84
commit
d0090e8a0c
@ -1,4 +1,5 @@
|
||||
import type { Libp2p } from "@libp2p/interface-libp2p";
|
||||
import { PeerId } from "@libp2p/interface-peer-id";
|
||||
import type { Peer } from "@libp2p/interface-peer-store";
|
||||
import { IncomingStreamData } from "@libp2p/interface-registrar";
|
||||
import type {
|
||||
@ -143,12 +144,12 @@ class FilterV2 extends BaseProtocol implements IFilterV2 {
|
||||
};
|
||||
}
|
||||
|
||||
public async unsubscribeAll(): Promise<void> {
|
||||
public async unsubscribeAll(peerId: PeerId): Promise<void> {
|
||||
const { pubSubTopic = DefaultPubSubTopic } = this.options;
|
||||
|
||||
const request = FilterSubscribeRpc.createUnsubscribeAllRequest(pubSubTopic);
|
||||
|
||||
const peer = await this.getPeer();
|
||||
const peer = await this.getPeer(peerId);
|
||||
const stream = await this.newStream(peer);
|
||||
|
||||
try {
|
||||
@ -177,12 +178,12 @@ class FilterV2 extends BaseProtocol implements IFilterV2 {
|
||||
}
|
||||
}
|
||||
|
||||
public async ping(): Promise<void> {
|
||||
public async ping(peerId: PeerId): Promise<void> {
|
||||
const { pubSubTopic = DefaultPubSubTopic } = this.options;
|
||||
|
||||
const request = FilterSubscribeRpc.createSubscriberPingRequest(pubSubTopic);
|
||||
|
||||
const peer = await this.getPeer();
|
||||
const peer = await this.getPeer(peerId);
|
||||
const stream = await this.newStream(peer);
|
||||
|
||||
try {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { PeerId } from "@libp2p/interface-peer-id";
|
||||
|
||||
import type { IDecodedMessage, IDecoder } from "./message.js";
|
||||
import type { Callback, ProtocolOptions } from "./protocols.js";
|
||||
|
||||
@ -17,6 +19,6 @@ export interface IReceiverV1 {
|
||||
}
|
||||
|
||||
export interface IReceiverV2 extends IReceiverV1 {
|
||||
ping: () => Promise<void>;
|
||||
unsubscribeAll: () => Promise<void>;
|
||||
ping: (peerId: PeerId) => Promise<void>;
|
||||
unsubscribeAll: (peerId: PeerId) => Promise<void>;
|
||||
}
|
||||
|
@ -172,14 +172,14 @@ describe("Waku Filter: V2", () => {
|
||||
const callback = (): void => {
|
||||
messageCount++;
|
||||
};
|
||||
await waku.filter.subscribe([TestDecoder], callback);
|
||||
const peerId = await waku.filter.subscribe([TestDecoder], callback);
|
||||
|
||||
await delay(200);
|
||||
await waku.lightPush.send(TestEncoder, {
|
||||
payload: utf8ToBytes("This should be received"),
|
||||
});
|
||||
await delay(100);
|
||||
await waku.filter.ping();
|
||||
await waku.filter.ping(peerId);
|
||||
await waku.lightPush.send(TestEncoder, {
|
||||
payload: utf8ToBytes("This should be received"),
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user