Simplify API

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.
This commit is contained in:
Franck Royer 2021-04-15 14:32:22 +10:00
parent 9a305033bc
commit 896462340a
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 2 additions and 18 deletions

View File

@ -26,11 +26,6 @@ const ChatContentTopic = 'dingpu';
console.log(`\t- ${address}`); 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({ const rl = readline.createInterface({
input: process.stdin, input: process.stdin,
output: process.stdout, output: process.stdout,

View File

@ -34,9 +34,6 @@ describe('Waku Relay', () => {
await waku1.dialWithMultiAddr(waku2.libp2p.peerId, waku2.libp2p.multiaddrs); await waku1.dialWithMultiAddr(waku2.libp2p.peerId, waku2.libp2p.multiaddrs);
await waku1.relay.subscribe();
await waku2.relay.subscribe();
await Promise.all([ await Promise.all([
new Promise((resolve) => new Promise((resolve) =>
waku1.libp2p.pubsub.once('pubsub:subscription-change', () => waku1.libp2p.pubsub.once('pubsub:subscription-change', () =>
@ -107,7 +104,6 @@ describe('Waku Relay', () => {
nimWaku = new NimWaku(makeLogFileName(this)); nimWaku = new NimWaku(makeLogFileName(this));
await nimWaku.start({ staticnode: multiAddrWithId }); await nimWaku.start({ staticnode: multiAddrWithId });
await waku.relay.subscribe();
await new Promise((resolve) => await new Promise((resolve) =>
waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve) waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve)
); );
@ -180,8 +176,6 @@ describe('Waku Relay', () => {
nimWaku = new NimWaku(this.test?.ctx?.currentTest?.title + ''); nimWaku = new NimWaku(this.test?.ctx?.currentTest?.title + '');
await nimWaku.start(); await nimWaku.start();
await waku.relay.subscribe();
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nimWaku.getMultiaddrWithId());
// Wait for identify protocol to finish // Wait for identify protocol to finish
@ -276,8 +270,6 @@ describe('Waku Relay', () => {
waku2.dial(nimWakuMultiaddr), waku2.dial(nimWakuMultiaddr),
]); ]);
await Promise.all([waku1.relay.subscribe(), waku2.relay.subscribe()]);
await Promise.all([ await Promise.all([
new Promise((resolve) => new Promise((resolve) =>
waku1.libp2p.pubsub.once('gossipsub:heartbeat', resolve) waku1.libp2p.pubsub.once('gossipsub:heartbeat', resolve)

View File

@ -294,11 +294,8 @@ export class WakuRelayPubsub extends Gossipsub {
// This class provides an interface to execute the waku relay protocol // This class provides an interface to execute the waku relay protocol
export class WakuRelay { export class WakuRelay {
constructor(private pubsub: Pubsub) {} constructor(private pubsub: Pubsub) {
this.pubsub.subscribe(constants.RelayDefaultTopic);
// 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);
} }
async publish(message: WakuMessage) { async publish(message: WakuMessage) {