Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stability] Only Show New Peer On Open Channel #537

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion client/scripts/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class RTCPeer extends Peer {

_onChannelOpened(event) {
console.log('RTC: channel opened with', this._peerId);
Events.fire('peer-connected', this._peerId);
const channel = event.channel || event.target;
channel.binaryType = 'arraybuffer';
channel.onmessage = e => this._onMessage(e.data);
Expand All @@ -302,7 +303,8 @@ class RTCPeer extends Peer {

_onChannelClosed() {
console.log('RTC: channel closed', this._peerId);
if (!this.isCaller) return;
Events.fire('peer-left', this._peerId);
if (!this._isCaller) return;
this._connect(this._peerId, true); // reopen the channel
}

Expand Down
16 changes: 12 additions & 4 deletions client/scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class PeersUI {
_onPeerJoined(peer) {
if ($(peer.id)) return; // peer already exists
const peerUI = new PeerUI(peer);
$$('x-peers').appendChild(peerUI.$el);
setTimeout(e => window.animateBackground(false), 1750); // Stop animation
}

_onPeers(peers) {
Expand Down Expand Up @@ -91,8 +89,18 @@ class PeerUI {

constructor(peer) {
this._peer = peer;
this._initDom();
this._bindListeners(this.$el);
this.callbackFunction = (e) => this._onPeerConnected(e.detail);
Events.on('peer-connected', this.callbackFunction);
}

_onPeerConnected(peerId) {
if (peerId === this._peer.id) {
Events.off('peer-connected', this.callbackFunction)
this._initDom();
this._bindListeners(this.$el);
$$('x-peers').appendChild(this.$el);
setTimeout(e => window.animateBackground(false), 1750); // Stop animation
}
}

_initDom() {
Expand Down