From 714e26257bb06c92363633aafc7ca03a5fc7dec9 Mon Sep 17 00:00:00 2001 From: lazorfuzz <leontosy@gmail.com> Date: Thu, 7 Jun 2018 09:47:11 -0700 Subject: [PATCH] Add getPeerById method and options for attachStream --- README.md | 13 +++++++++---- src/liowebrtc.js | 42 +++++++++++++++++++++++++++++++++--------- src/localmedia.js | 1 + src/webrtc.js | 4 ++++ 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7155b53..fbcb0e5 100644 --- a/README.md +++ b/README.md @@ -215,10 +215,7 @@ class Party extends Component { /> <p>{this.state.nick}</p> </div> - - <div id="remoteVideos"> - {this.generateRemotes()} - </div> + {this.generateRemotes()} </div> ); } @@ -306,6 +303,9 @@ ending all peers, and stopping the local screen stream `'localScreenAdded', el` - emitted after triggering the start of screen sharing - `el` the element that contains the local screen stream +`'mute', data` - emitted when a peer mutes their video or audioOn +- `data` an object that contains an `id` property that returns the id of the peer, and a `name` property that indicates which stream was muted, `video` or `audio` + `'receivedPeerData', type, payload, peer` - emitted when a peer sends data via `shout` or `whisper` - `type` a label, usually a string, that describes the payload - `payload` any kind of data sent by the peer, usually an object @@ -320,6 +320,9 @@ ending all peers, and stopping the local screen stream `'turnservers', [...args]` - emitted when the signaling server emits a list of turn servers. +`'unmute', data` - emitted when a peer mutes their video or audioOn +- `data` an object that contains an `id` property for the id of the peer that sent the event, and a `name` property that indicates which stream was muted, `video` or `audio` + `'videoAdded', stream, peer` - emitted when a peer's MediaStream becomes available - `stream` - the MediaStream associated with the peer - `peer` - the peer associated with the stream that was added @@ -350,6 +353,8 @@ room via the signaling server (similar to `shout`, but not p2p). Listen for peer `getLocalScreen()` - returns the local screen stream +`getPeerById(id)` - returns a peer with a given `id` + `getPeerByNick(nick)` - returns a peer with a given `nick` `getPeers(sessionId, type)` - returns all peers by `sessionId` and/or `type` diff --git a/src/liowebrtc.js b/src/liowebrtc.js index fb03f1b..29a8c0c 100644 --- a/src/liowebrtc.js +++ b/src/liowebrtc.js @@ -33,8 +33,9 @@ class LioWebRTC extends WildEmitter { }, localVideo: { autoplay: true, - mirror: false, + mirror: true, muted: true, + audio: false, }, }; @@ -61,6 +62,10 @@ class LioWebRTC extends WildEmitter { this.config.receiveMedia.offerToReceiveVideo = false; } + if (!this.config.media.video && this.config.media.audio) { + this.config.localVideo.audio = true; + } + // attach detected support for convenience this.capabilities = webrtcSupport; @@ -120,7 +125,23 @@ class LioWebRTC extends WildEmitter { this.webrtc = new WebRTC(opts); // attach a few methods from underlying lib to liowebrtc. - ['mute', 'unmute', 'pauseVideo', 'resumeVideo', 'pause', 'resume', 'sendToAll', 'sendDirectlyToAll', 'getPeers', 'getPeerByNick', 'shout', 'whisper', 'broadcast', 'transmit'].forEach((method) => { + [ + 'mute', + 'unmute', + 'pauseVideo', + 'resumeVideo', + 'pause', + 'resume', + 'sendToAll', + 'sendDirectlyToAll', + 'getPeers', + 'getPeerByNick', + 'getPeerById', + 'shout', + 'whisper', + 'broadcast', + 'transmit', + ].forEach((method) => { self[method] = self.webrtc[method].bind(self.webrtc); }); @@ -345,13 +366,20 @@ class LioWebRTC extends WildEmitter { if (err) { self.emit('localMediaError', err); } else { - attachMediaStream(stream, this.config.localVideoEl, { muted: true }); + attachMediaStream(stream, this.config.localVideoEl, this.config.localVideo); } }); } - attachStream(stream, el) { - attachMediaStream(stream, el); + attachStream(stream, el, opts) { // eslint-disable-line + let options = { + autoplay: true, + muted: false, + mirror: true, + audio: false, + }; + if (opts) options = opts; + attachMediaStream(stream, el, options); } stopLocalVideo() { @@ -390,10 +418,6 @@ class LioWebRTC extends WildEmitter { }); } - attachStream(stream, el) { - attachMediaStream(stream, el); - } - testReadiness() { const self = this; if (this.sessionReady) { diff --git a/src/localmedia.js b/src/localmedia.js index 5106376..24e9c0c 100644 --- a/src/localmedia.js +++ b/src/localmedia.js @@ -160,6 +160,7 @@ class LocalMedia extends WildEmitter { self.emit('localScreen', stream); } else { + console.error(err); self.emit('localScreenRequestFailed'); } diff --git a/src/webrtc.js b/src/webrtc.js index a4add9a..76b97cb 100644 --- a/src/webrtc.js +++ b/src/webrtc.js @@ -125,6 +125,10 @@ class WebRTC extends LocalMedia { return this.peers.filter(peer => (!sessionId || peer.id === sessionId) && (!type || peer.type === type)); } + getPeerById(id) { + return this.peers.filter(p => p.id === id)[0]; + } + getPeerByNick(nick) { return this.peers.filter(p => p.nick === nick)[0]; } -- GitLab