Skip to content
Snippets Groups Projects
Commit 1fd19586 authored by lazorfuzz's avatar lazorfuzz
Browse files

channelOpen emit fix

parent 9a0a0d8c
No related branches found
No related tags found
No related merge requests found
...@@ -162,14 +162,14 @@ class Peer extends WildEmitter { ...@@ -162,14 +162,14 @@ class Peer extends WildEmitter {
} }
// Internal method registering handlers for a data channel and emitting events on the peer // Internal method registering handlers for a data channel and emitting events on the peer
_observeDataChannel(channel) { _observeDataChannel(channel, peer) {
const self = this; const self = this;
channel.onclose = this.emit.bind(this, 'channelClose', channel); channel.onclose = this.emit.bind(this, 'channelClose', channel);
channel.onerror = this.emit.bind(this, 'channelError', channel); channel.onerror = this.emit.bind(this, 'channelError', channel);
channel.onmessage = (event) => { channel.onmessage = (event) => {
self.emit('channelMessage', self, channel.label, JSON.parse(event.data), channel, event); self.emit('channelMessage', self, channel.label, JSON.parse(event.data), channel, event);
}; };
channel.onopen = this.emit.bind(this, 'channelOpen', channel, this); channel.onopen = this.emit.bind(this, 'channelOpen', channel, peer);
} }
// Fetch or create a data channel by the given name // Fetch or create a data channel by the given name
...@@ -179,7 +179,7 @@ class Peer extends WildEmitter { ...@@ -179,7 +179,7 @@ class Peer extends WildEmitter {
if (channel) return channel; if (channel) return channel;
// if we don't have one by this label, create it // if we don't have one by this label, create it
channel = this.channels[name] = this.pc.createDataChannel(name, opts); channel = this.channels[name] = this.pc.createDataChannel(name, opts);
this._observeDataChannel(channel); this._observeDataChannel(channel, this);
return channel; return channel;
} }
...@@ -260,7 +260,7 @@ class Peer extends WildEmitter { ...@@ -260,7 +260,7 @@ class Peer extends WildEmitter {
handleDataChannelAdded(channel) { handleDataChannelAdded(channel) {
this.channels[channel.label] = channel; this.channels[channel.label] = channel;
this._observeDataChannel(channel); this._observeDataChannel(channel, this);
} }
sendFile(file) { sendFile(file) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment