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); + } } }