*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";
|
} 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;
|
||||||
|
@ -73,19 +83,23 @@ export default class HandshakeProxy extends Proxy {
|
||||||
createSocket,
|
createSocket,
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue