* 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:
parent
85ff38d871
commit
bc85076e7f
13
src/peer.ts
13
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() {
|
||||
|
|
Loading…
Reference in New Issue