* Refactor peer.ts to use call both handle and on* callbacks for open and close

* emit "peerChannelOpen" event on new channel open.
This commit is contained in:
Derrick Hammer 2023-04-16 07:11:39 -04:00
parent 85ff38d871
commit bc85076e7f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 11 additions and 2 deletions

View File

@ -105,14 +105,23 @@ export default abstract class Peer {
this._channel = await this._muxer.createChannel({ this._channel = await this._muxer.createChannel({
protocol: this._proxy.protocol, protocol: this._proxy.protocol,
onopen: this.handleChannelOnOpen.bind(this), onopen: async (m: any) => {
onclose: this.handleChannelOnClose.bind(this), await this.handleChannelOnOpen(m);
// @ts-ignore
await this._onopen?.(this._channel);
},
onclose: async (socket: Socket) => {
await this.handleChannelOnClose(socket);
// @ts-ignore
await this._onclose?.();
},
}); });
await this.initMessages(); await this.initMessages();
await this._onchannel?.(this._channel); await this._onchannel?.(this._channel);
await this._channel.open(); await this._channel.open();
this._proxy.emit("peerChannelOpen", this);
} }
async init() { async init() {