*make joining the topic optional
This commit is contained in:
parent
0fb85e3e5b
commit
aefa2712db
24
src/index.ts
24
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();
|
||||
|
||||
if (this._join) {
|
||||
const topic = b4a.from(PROTOCOL);
|
||||
const topicHash = b4a.allocUnsafe(32);
|
||||
sodium.crypto_generichash(topicHash, topic);
|
||||
this.swarm.join(topicHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue