Merge branch 'show_peer_on_channel_open' into add_device_pairing
# Conflicts: # client/scripts/network.js
This commit is contained in:
commit
fdb0bbf098
|
@ -187,12 +187,12 @@ class Peer {
|
||||||
|
|
||||||
_onChunkReceived(chunk) {
|
_onChunkReceived(chunk) {
|
||||||
if(!chunk.byteLength) return;
|
if(!chunk.byteLength) return;
|
||||||
|
|
||||||
this._digester.unchunk(chunk);
|
this._digester.unchunk(chunk);
|
||||||
const progress = this._digester.progress;
|
const progress = this._digester.progress;
|
||||||
this._onDownloadProgress(progress);
|
this._onDownloadProgress(progress);
|
||||||
|
|
||||||
// occasionally notify sender about our progress
|
// occasionally notify sender about our progress
|
||||||
if (progress - this._lastProgress < 0.01) return;
|
if (progress - this._lastProgress < 0.01) return;
|
||||||
this._lastProgress = progress;
|
this._lastProgress = progress;
|
||||||
this._sendProgress(progress);
|
this._sendProgress(progress);
|
||||||
|
@ -254,7 +254,7 @@ class RTCPeer extends Peer {
|
||||||
}
|
}
|
||||||
|
|
||||||
_openChannel() {
|
_openChannel() {
|
||||||
const channel = this._conn.createDataChannel('data-channel', {
|
const channel = this._conn.createDataChannel('data-channel', {
|
||||||
ordered: true,
|
ordered: true,
|
||||||
reliable: true // Obsolete. See https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/reliable
|
reliable: true // Obsolete. See https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/reliable
|
||||||
});
|
});
|
||||||
|
@ -293,6 +293,7 @@ class RTCPeer extends Peer {
|
||||||
|
|
||||||
_onChannelOpened(event) {
|
_onChannelOpened(event) {
|
||||||
console.log('RTC: channel opened with', this._peerId);
|
console.log('RTC: channel opened with', this._peerId);
|
||||||
|
Events.fire('peer-connected', this._peerId);
|
||||||
const channel = event.channel || event.target;
|
const channel = event.channel || event.target;
|
||||||
channel.binaryType = 'arraybuffer';
|
channel.binaryType = 'arraybuffer';
|
||||||
channel.onmessage = e => this._onMessage(e.data);
|
channel.onmessage = e => this._onMessage(e.data);
|
||||||
|
@ -302,6 +303,7 @@ class RTCPeer extends Peer {
|
||||||
|
|
||||||
_onChannelClosed() {
|
_onChannelClosed() {
|
||||||
console.log('RTC: channel closed', this._peerId);
|
console.log('RTC: channel closed', this._peerId);
|
||||||
|
Events.fire('peer-left', this._peerId);
|
||||||
if (!this._isCaller) return;
|
if (!this._isCaller) return;
|
||||||
this._connect(this._peerId, true); // reopen the channel
|
this._connect(this._peerId, true); // reopen the channel
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,6 @@ class PeersUI {
|
||||||
_onPeerJoined(peer) {
|
_onPeerJoined(peer) {
|
||||||
if ($(peer.id)) return; // peer already exists
|
if ($(peer.id)) return; // peer already exists
|
||||||
const peerUI = new PeerUI(peer);
|
const peerUI = new PeerUI(peer);
|
||||||
$$('x-peers').appendChild(peerUI.$el);
|
|
||||||
setTimeout(e => window.animateBackground(false), 1750); // Stop animation
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onPeers(peers) {
|
_onPeers(peers) {
|
||||||
|
@ -91,8 +89,18 @@ class PeerUI {
|
||||||
|
|
||||||
constructor(peer) {
|
constructor(peer) {
|
||||||
this._peer = peer;
|
this._peer = peer;
|
||||||
this._initDom();
|
this.callbackFunction = (e) => this._onPeerConnected(e.detail);
|
||||||
this._bindListeners(this.$el);
|
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() {
|
_initDom() {
|
||||||
|
|
Loading…
Reference in New Issue