snapdrop

A Progressive Web App for local file sharing
git clone http://git.hanabi.in/repos/snapdrop.git
Log | Files | Refs | README | LICENSE

commit b95e9d019e85a977ed4485ebf3f6cc4f5e4c9735
parent 983a2d116b1d724f31338ffa6aed45d255aa5f10
Author: RobinLinus <robinlinus@users.noreply.github.com>
Date:   Tue,  9 Oct 2018 23:00:18 +0200

Refactor deprecated WebRTC api

Diffstat:
Mclient/scripts/network.js | 19++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/client/scripts/network.js b/client/scripts/network.js @@ -253,14 +253,14 @@ class RTCPeer extends Peer { const channel = this._conn.createDataChannel('data-channel', { reliable: true }); channel.binaryType = 'arraybuffer'; channel.onopen = e => this._onChannelOpened(e); - this._conn.createOffer(d => this._onDescription(d), e => this._onError(e)); + this._conn.createOffer().then(d => this._onDescription(d)).catch(e => this._onError(e)); } _onDescription(description) { // description.sdp = description.sdp.replace('b=AS:30', 'b=AS:1638400'); - this._conn.setLocalDescription(description, - _ => this._sendSignal({ sdp: description }), - e => this._onError(e)); + this._conn.setLocalDescription(description) + .then(_ => this._sendSignal({ sdp: description })) + .catch(e => this._onError(e)); } _onIceCandidate(event) { @@ -272,10 +272,10 @@ class RTCPeer extends Peer { if (!this._conn) this._connect(message.sender, false); if (message.sdp) { - this._conn.setRemoteDescription(new RTCSessionDescription(message.sdp), () => { - if (message.sdp.type !== 'offer') return; - this._conn.createAnswer(d => this._onDescription(d), e => this._onError(e)); - }, e => this._onError(e)); + this._conn.setRemoteDescription(new RTCSessionDescription(message.sdp)) + .then( _ => this._conn.createAnswer()) + .then(d => this._onDescription(d)) + .catch(e => this._onError(e)); } else if (message.ice) { this._conn.addIceCandidate(new RTCIceCandidate(message.ice)); } @@ -323,6 +323,7 @@ class RTCPeer extends Peer { } _send(message) { + if (!this._channel) return this.refresh(); this._channel.send(message); } @@ -411,7 +412,7 @@ class WSPeer { class FileChunker { constructor(file, onChunk, onPartitionEnd) { - this._chunkSize = 64000; // 64 KB + this._chunkSize = 64000; // 64 KB this._maxPartitionSize = 1e6; // 1 MB this._offset = 0; this._partitionSize = 0;