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 9a30503 commit 8964623
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 @@ -26,11 +26,6 @@ const ChatContentTopic = 'dingpu';
console.log(`\t- ${address}`);
});

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

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
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 @@ -34,9 +34,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 @@ -107,7 +104,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 @@ -180,8 +176,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 @@ -276,8 +270,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 8964623

Please sign in to comment.