From aefa2712db688fb8762fd09a1742a311306d7e55 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 17 Feb 2023 19:28:33 -0500 Subject: [PATCH] *make joining the topic optional --- src/index.ts | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9f38a16..c0c2e32 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,7 +19,16 @@ import { } from "@lumeweb/libhyperproxy"; export default class HandshakeProxy extends Proxy { - constructor({ swarm, listen = false }: { swarm: any; listen?: boolean }) { + private _join: boolean; + constructor({ + swarm, + listen = false, + join = false, + }: { + swarm: any; + listen?: boolean; + join?: boolean; + }) { super({ swarm, listen, @@ -49,6 +58,7 @@ export default class HandshakeProxy extends Proxy { }, }); const self = this; + this._join = join; } private _node?: any; @@ -73,19 +83,23 @@ export default class HandshakeProxy extends Proxy { createSocket, }); - if(this?._node?.http?.http?.listen){ - this._node.http.http.listen = (port: number, host: string, cb: Function) => - cb(); + if (this?._node?.http?.http?.listen) { + this._node.http.http.listen = ( + port: number, + host: string, + cb: Function + ) => cb(); } - await this._node.open(); this._node.pool.connected = true; this._node.startSync(); - const topic = b4a.from(PROTOCOL); - const topicHash = b4a.allocUnsafe(32); - sodium.crypto_generichash(topicHash, topic); - this.swarm.join(topicHash); + if (this._join) { + const topic = b4a.from(PROTOCOL); + const topicHash = b4a.allocUnsafe(32); + sodium.crypto_generichash(topicHash, topic); + this.swarm.join(topicHash); + } } }