Reorder parameters

To match `waku.relay.addObserver`.
This commit is contained in:
Franck Royer 2022-05-26 16:03:46 +10:00
parent 4cf3d3ffd8
commit 5687908ca0
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 16 additions and 26 deletions

View File

@ -42,10 +42,7 @@ describe("Waku Filter", () => {
expect(msg.contentTopic).to.eq(TestContentTopic);
expect(msg.payloadAsUtf8).to.eq(messageText);
};
await waku.filter.subscribe(
{ contentTopics: [TestContentTopic] },
callback
);
await waku.filter.subscribe(callback, [TestContentTopic]);
const message = await WakuMessage.fromUtf8String(
messageText,
TestContentTopic
@ -65,10 +62,7 @@ describe("Waku Filter", () => {
messageCount++;
expect(msg.contentTopic).to.eq(TestContentTopic);
};
await waku.filter.subscribe(
{ contentTopics: [TestContentTopic] },
callback
);
await waku.filter.subscribe(callback, [TestContentTopic]);
await waku.relay.send(
await WakuMessage.fromUtf8String("Filtering works!", TestContentTopic)
);
@ -89,10 +83,9 @@ describe("Waku Filter", () => {
const callback = (): void => {
messageCount++;
};
const unsubscribe = await waku.filter.subscribe(
{ contentTopics: [TestContentTopic] },
callback
);
const unsubscribe = await waku.filter.subscribe(callback, [
TestContentTopic,
]);
await waku.relay.send(
await WakuMessage.fromUtf8String(
"This should be received",

View File

@ -25,10 +25,6 @@ type FilterSubscriptionOpts = {
* Optionally specify a PeerId for the subscription. If not included, will use a random peer.
*/
peerId?: PeerId;
/**
* Array of ContentTopics to subscribe to. If empty, no messages will be returned from the filter.
*/
contentTopics: string[];
};
type FilterCallback = (msg: WakuMessage) => void | Promise<void>;
@ -56,17 +52,18 @@ export class WakuFilter {
}
/**
*
* @param opts The FilterSubscriptionOpts used to narrow which messages are returned, and which peer to connect to
* @param callback A function that will be called on each message returned by the filter
* @returns Unsubscribe function that can be used to end the subscription
* @param contentTopics Array of ContentTopics to subscribe to. If empty, no messages will be returned from the filter.
* @param callback A function that will be called on each message returned by the filter.
* @param opts The FilterSubscriptionOpts used to narrow which messages are returned, and which peer to connect to.
* @returns Unsubscribe function that can be used to end the subscription.
*/
async subscribe(
opts: FilterSubscriptionOpts,
callback: FilterCallback
callback: FilterCallback,
contentTopics: string[],
opts?: FilterSubscriptionOpts
): Promise<UnsubscribeFunction> {
const topic = opts.pubsubTopic || DefaultPubSubTopic;
const contentFilters = opts.contentTopics.map((contentTopic) => ({
const topic = opts?.pubsubTopic || DefaultPubSubTopic;
const contentFilters = contentTopics.map((contentTopic) => ({
contentTopic,
}));
const request = FilterRPC.createRequest(
@ -76,7 +73,7 @@ export class WakuFilter {
true
);
const peer = await this.getPeer(opts.peerId);
const peer = await this.getPeer(opts?.peerId);
const stream = await this.newStream(peer);
try {
@ -86,7 +83,7 @@ export class WakuFilter {
"Error subscribing to peer ",
peer.id.toB58String(),
"for content topics",
opts.contentTopics,
contentTopics,
": ",
e
);