diff --git a/README.md b/README.md index 3f13c8c81b2fa653165a3610f5b3a0d6110dc4fa..f6bb1363d6979b4576ee643bb8787be7c7a52d39 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ class Party extends Component { <div id={/* The video container needs a special id */ `${this.webrtc.getContainerId(p)}`}> <video // Important: The video element needs both an id and ref - id={this.webrtc.getId(p)} + id={this.webrtc.getDomId(p)} ref={(v) => this.remoteVideos[p.id] = v} /> </div> @@ -368,7 +368,7 @@ room via the signaling server (similar to `shout`, but not p2p). Listen for peer `getMyId()` - get your own peer ID -`getId(peer)` - get the DOM id associated with a peer's media stream. In JSX, you will need to set the id of the peer's media element to this value. +`getDomId(peer)` - get the DOM id associated with a peer's media stream. In JSX, you will need to set the id of the peer's media element to this value. - `Peer peer` - the object representing the peer and its peer connection `getPeerById(id)` - returns a peer with a given `id` diff --git a/src/liowebrtc.js b/src/liowebrtc.js index 2de8ca8f82315a28bc23005ec0501fd85048e75c..b24599fd16ab25023bf640b7583c9fd0ca4c50d9 100644 --- a/src/liowebrtc.js +++ b/src/liowebrtc.js @@ -70,7 +70,7 @@ class LioWebRTC extends WildEmitter { }); // if (!peer) peer = peers[0]; // fallback for old protocol versions } - if (this.config.dataOnly && this.config.network.maxPeers > 0 && totalPeers >= this.config.network.maxPeers) { + if (this.config.dataOnly && this.config.constraints.maxPeers > 0 && totalPeers >= this.config.constraints.maxPeers) { return; } if (!peer) { @@ -82,7 +82,12 @@ class LioWebRTC extends WildEmitter { sharemyscreen: message.roomType === 'screen' && !message.broadcaster, broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null, }); - this.sendPing(peer, peer.id, true); + if (this.config.dataOnly) { + this.sendPing(peer, peer.id, true); + } else { + peer.start(); + this.emit('createdPeer', peer); + } } else { return; } @@ -177,8 +182,8 @@ class LioWebRTC extends WildEmitter { self.on('channelClose', (channel) => { if (channel.label === 'liowebrtc' && this.config.dataOnly && - this.config.network.maxPeers > 0 && - getNeighbors(this.id).length < this.config.network.minPeers) { + this.config.constraints.maxPeers > 0 && + getNeighbors(this.id).length < this.config.constraints.minPeers) { this.connectToRandomPeer(); } }); @@ -220,7 +225,7 @@ class LioWebRTC extends WildEmitter { } this.cachePeerEvent(data._id, peer.id); self.emit('receivedPeerData', data.type, data.payload, peer); - if (this.config.network.maxPeers > 0 && data.shout) { + if (this.config.constraints.maxPeers > 0 && data.shout) { data.senderId = peer.id; const fwdData = Object.assign({}, { senderId: peer.id, senderNick: peer.nick }, data); this.propagateMessage(fwdData); @@ -338,10 +343,9 @@ class LioWebRTC extends WildEmitter { delete this.connection; } - handlePeerStreamAdded(peer) { + handlePeerStreamAdded(stream, peer) { const self = this; - - this.emit('peerStreamAdded', peer.stream, peer); + //this.emit('peerStreamAdded', stream, peer); // send our mute status to new peer if we're muted // currently called with a small delay because it arrives before @@ -361,7 +365,7 @@ class LioWebRTC extends WildEmitter { // (this.config.media.video) this.emit('peerStreamRemoved', peer); } - getId(peer) { // eslint-disable-line + getDomId(peer) { // eslint-disable-line return [peer.id, peer.type, peer.broadcaster ? 'broadcasting' : 'incoming'].join('_'); } @@ -370,7 +374,7 @@ class LioWebRTC extends WildEmitter { } getContainerId(peer) { - return `container_${this.getId(peer)}`; + return `container_${this.getDomId(peer)}`; } // set volume on video tag for all peers takse a value between 0 and 1 @@ -408,7 +412,7 @@ class LioWebRTC extends WildEmitter { for (type in client) { if (client[type]) { const peerCount = this.webrtc.getPeers().length; - if (this.config.dataOnly && this.config.network.maxPeers > 0 && (peerCount >= this.config.network.minPeers || peerCount >= this.config.network.maxPeers)) { + if (this.config.dataOnly && this.config.constraints.maxPeers > 0 && (peerCount >= this.config.constraints.minPeers || peerCount >= this.config.constraints.maxPeers)) { break; } peer = self.webrtc.createPeer({ @@ -420,7 +424,12 @@ class LioWebRTC extends WildEmitter { offerToReceiveVideo: !this.config.dataOnly && self.config.receiveMedia.offerToReceiveVideo ? 1 : 0, }, }); - this.sendPing(peer, peer.id, true); + if (this.config.dataOnly) { + this.sendPing(peer, peer.id, true); + } else { + peer.start(); + this.emit('createdPeer', peer); + } } } } @@ -483,7 +492,7 @@ class LioWebRTC extends WildEmitter { for (type in client) { if (client[type]) { const peerCount = this.webrtc.getPeers().length; - if (this.config.network.maxPeers > 0 && peerCount >= this.config.network.maxPeers) { + if (this.config.constraints.maxPeers > 0 && peerCount >= this.config.constraints.maxPeers) { break; } peer = this.webrtc.createPeer({ @@ -495,7 +504,12 @@ class LioWebRTC extends WildEmitter { offerToReceiveVideo: !this.config.dataOnly && this.config.receiveMedia.offerToReceiveVideo ? 1 : 0, }, }); - this.sendPing(peer, peerId, true); + if (this.config.dataOnly) { + this.sendPing(peer, peerId, true); + } else { + peer.start(); + this.emit('createdPeer', peer); + } } } }