*make joining the topic optional

This commit is contained in:
Derrick Hammer 2023-02-17 19:28:33 -05:00
parent 0fb85e3e5b
commit aefa2712db
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 23 additions and 9 deletions

View File

@ -19,7 +19,16 @@ import {
} from "@lumeweb/libhyperproxy"; } from "@lumeweb/libhyperproxy";
export default class HandshakeProxy extends Proxy { 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({ super({
swarm, swarm,
listen, listen,
@ -49,6 +58,7 @@ export default class HandshakeProxy extends Proxy {
}, },
}); });
const self = this; const self = this;
this._join = join;
} }
private _node?: any; private _node?: any;
@ -74,18 +84,22 @@ export default class HandshakeProxy extends Proxy {
}); });
if (this?._node?.http?.http?.listen) { if (this?._node?.http?.http?.listen) {
this._node.http.http.listen = (port: number, host: string, cb: Function) => this._node.http.http.listen = (
cb(); port: number,
host: string,
cb: Function
) => cb();
} }
await this._node.open(); await this._node.open();
this._node.pool.connected = true; this._node.pool.connected = true;
this._node.startSync(); this._node.startSync();
if (this._join) {
const topic = b4a.from(PROTOCOL); const topic = b4a.from(PROTOCOL);
const topicHash = b4a.allocUnsafe(32); const topicHash = b4a.allocUnsafe(32);
sodium.crypto_generichash(topicHash, topic); sodium.crypto_generichash(topicHash, topic);
this.swarm.join(topicHash); this.swarm.join(topicHash);
} }
} }
}