Skip to content

Commit

Permalink
Simplify API
Browse files Browse the repository at this point in the history
At this stage, if waku relay is mounted then we always want to subscribe
to default topic.

We can re-introduce the flexibility once we know what matters to the user.

Resolves #17.
  • Loading branch information
D4nte committed Apr 15, 2021
1 parent 552a530 commit 144b74d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 18 deletions.
5 changes: 0 additions & 5 deletions src/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ const ChatContentTopic = 'dingpu';
await waku.dial(opts.staticNode);
}

// TODO: Automatically subscribe, tracked with
// https://github.com/status-im/js-waku/issues/17
await waku.relay.subscribe();
console.log('Subscribed to waku relay');

// If we connect to a peer with WakuStore, we run the protocol
// TODO: Instead of doing it `once` it should always be done but
// only new messages should be printed
Expand Down
8 changes: 0 additions & 8 deletions src/lib/waku_relay/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ describe('Waku Relay', () => {

await waku1.dialWithMultiAddr(waku2.libp2p.peerId, waku2.libp2p.multiaddrs);

await waku1.relay.subscribe();
await waku2.relay.subscribe();

await Promise.all([
new Promise((resolve) =>
waku1.libp2p.pubsub.once('pubsub:subscription-change', () =>
Expand Down Expand Up @@ -95,7 +92,6 @@ describe('Waku Relay', () => {
nimWaku = new NimWaku(makeLogFileName(this));
await nimWaku.start({ staticnode: multiAddrWithId });

await waku.relay.subscribe();
await new Promise((resolve) =>
waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve)
);
Expand Down Expand Up @@ -165,8 +161,6 @@ describe('Waku Relay', () => {
nimWaku = new NimWaku(this.test?.ctx?.currentTest?.title + '');
await nimWaku.start();

await waku.relay.subscribe();

await waku.dial(await nimWaku.getMultiaddrWithId());

// Wait for identify protocol to finish
Expand Down Expand Up @@ -253,8 +247,6 @@ describe('Waku Relay', () => {
waku2.dial(nimWakuMultiaddr),
]);

await Promise.all([waku1.relay.subscribe(), waku2.relay.subscribe()]);

await Promise.all([
new Promise((resolve) =>
waku1.libp2p.pubsub.once('gossipsub:heartbeat', resolve)
Expand Down
7 changes: 2 additions & 5 deletions src/lib/waku_relay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,8 @@ export class WakuRelayPubsub extends Gossipsub {

// This class provides an interface to execute the waku relay protocol
export class WakuRelay {
constructor(private pubsub: Pubsub) {}

// At this stage we are always using the same topic so we do not pass it as a parameter
async subscribe() {
await this.pubsub.subscribe(constants.RelayDefaultTopic);
constructor(private pubsub: Pubsub) {
this.pubsub.subscribe(constants.RelayDefaultTopic);
}

async publish(message: WakuMessage) {
Expand Down

0 comments on commit 144b74d

Please sign in to comment.