mirror of https://github.com/status-im/js-waku.git
fix: pass pubsub topic when creating waku filter
This commit is contained in:
parent
275eb72959
commit
8922511cc9
|
@ -104,8 +104,7 @@ export async function createWaku(options?: CreateOptions): Promise<Waku> {
|
||||||
|
|
||||||
const wakuStore = new WakuStore(libp2p, options);
|
const wakuStore = new WakuStore(libp2p, options);
|
||||||
const wakuLightPush = new WakuLightPush(libp2p, options);
|
const wakuLightPush = new WakuLightPush(libp2p, options);
|
||||||
// TODO pass options
|
const wakuFilter = new WakuFilter(libp2p, options);
|
||||||
const wakuFilter = new WakuFilter(libp2p);
|
|
||||||
|
|
||||||
await libp2p.start();
|
await libp2p.start();
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,18 @@ export const FilterCodec = "/vac/waku/filter/2.0.0-beta1";
|
||||||
|
|
||||||
const log = debug("waku:filter");
|
const log = debug("waku:filter");
|
||||||
|
|
||||||
|
export interface CreateOptions {
|
||||||
|
/**
|
||||||
|
* The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}.
|
||||||
|
*
|
||||||
|
* The usage of the default pubsub topic is recommended.
|
||||||
|
* See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
|
||||||
|
*
|
||||||
|
* @default {@link DefaultPubSubTopic}
|
||||||
|
*/
|
||||||
|
pubSubTopic?: string;
|
||||||
|
}
|
||||||
|
|
||||||
type FilterSubscriptionOpts = {
|
type FilterSubscriptionOpts = {
|
||||||
/**
|
/**
|
||||||
* The Pubsub topic for the subscription
|
* The Pubsub topic for the subscription
|
||||||
|
@ -43,16 +55,17 @@ type UnsubscribeFunction = () => Promise<void>;
|
||||||
* - https://github.com/status-im/nwaku/issues/948
|
* - https://github.com/status-im/nwaku/issues/948
|
||||||
*/
|
*/
|
||||||
export class WakuFilter {
|
export class WakuFilter {
|
||||||
|
pubSubTopic: string;
|
||||||
private subscriptions: Map<string, FilterCallback>;
|
private subscriptions: Map<string, FilterCallback>;
|
||||||
public decryptionKeys: Map<
|
public decryptionKeys: Map<
|
||||||
Uint8Array,
|
Uint8Array,
|
||||||
{ method?: DecryptionMethod; contentTopics?: string[] }
|
{ method?: DecryptionMethod; contentTopics?: string[] }
|
||||||
>;
|
>;
|
||||||
|
|
||||||
// TODO: Accept options (pubsubtopic)
|
constructor(public libp2p: Libp2p, options?: CreateOptions) {
|
||||||
constructor(public libp2p: Libp2p) {
|
|
||||||
this.subscriptions = new Map();
|
this.subscriptions = new Map();
|
||||||
this.decryptionKeys = new Map();
|
this.decryptionKeys = new Map();
|
||||||
|
this.pubSubTopic = options?.pubSubTopic ?? DefaultPubSubTopic;
|
||||||
this.libp2p
|
this.libp2p
|
||||||
.handle(FilterCodec, this.onRequest.bind(this))
|
.handle(FilterCodec, this.onRequest.bind(this))
|
||||||
.catch((e) => log("Failed to register filter protocol", e));
|
.catch((e) => log("Failed to register filter protocol", e));
|
||||||
|
@ -69,7 +82,7 @@ export class WakuFilter {
|
||||||
contentTopics: string[],
|
contentTopics: string[],
|
||||||
opts?: FilterSubscriptionOpts
|
opts?: FilterSubscriptionOpts
|
||||||
): Promise<UnsubscribeFunction> {
|
): Promise<UnsubscribeFunction> {
|
||||||
const topic = opts?.pubsubTopic || DefaultPubSubTopic;
|
const topic = opts?.pubsubTopic ?? this.pubSubTopic;
|
||||||
const contentFilters = contentTopics.map((contentTopic) => ({
|
const contentFilters = contentTopics.map((contentTopic) => ({
|
||||||
contentTopic,
|
contentTopic,
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue