From 8de33f8c1e20b501dcbf0b6796cf4bed0341dc97 Mon Sep 17 00:00:00 2001 From: lazorfuzz <leontosy@gmail.com> Date: Thu, 27 Dec 2018 14:00:57 -0800 Subject: [PATCH] Modify channelOepn event to include peer --- README.md | 3 ++- src/peer.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e66ff26..d53e370 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ const webrtc = new LioWebRTC({ ``` ### Partial mesh network -Peers only form direct connections with a maximum of maxPeers and a minimum of minPeers. shout()ing still works because peers wil re-propagate messages to other peers. Note: partial mesh networks only work if you're only using data channels. +Peers only form direct connections with a maximum of maxPeers and a minimum of minPeers. shout()ing still works because peers wil re-propagate messages to other peers. Note: partial mesh networks only work if you're only using `dataOnly`. ```js const webrtc = new LioWebRTC({ dataOnly: true, @@ -304,6 +304,7 @@ this.webrtc.on('receivedPeerData', (type, payload, peer) => { // Find something to do with the data }); ``` +`'channelOpen', RTCDataChannel, peer` - emitted when a new channel is established with a peer. `'connectionReady', sessionId` - emitted when the signaling connection emits the `connect` event, with the unique id for the session. diff --git a/src/peer.js b/src/peer.js index 9464f48..92a873f 100644 --- a/src/peer.js +++ b/src/peer.js @@ -169,7 +169,7 @@ class Peer extends WildEmitter { channel.onmessage = (event) => { self.emit('channelMessage', self, channel.label, JSON.parse(event.data), channel, event); }; - channel.onopen = this.emit.bind(this, 'channelOpen', channel); + channel.onopen = this.emit.bind(this, 'channelOpen', channel, self); } // Fetch or create a data channel by the given name -- GitLab