From bc85076e7ff3a3414813cfd22a9892ddd035a660 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 16 Apr 2023 07:11:39 -0400 Subject: [PATCH] * Refactor peer.ts to use call both handle and on* callbacks for open and close * emit "peerChannelOpen" event on new channel open. --- src/peer.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/peer.ts b/src/peer.ts index a8c39b7..eddfdab 100644 --- a/src/peer.ts +++ b/src/peer.ts @@ -105,14 +105,23 @@ export default abstract class Peer { this._channel = await this._muxer.createChannel({ protocol: this._proxy.protocol, - onopen: this.handleChannelOnOpen.bind(this), - onclose: this.handleChannelOnClose.bind(this), + onopen: async (m: any) => { + 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._onchannel?.(this._channel); await this._channel.open(); + this._proxy.emit("peerChannelOpen", this); } async init() {