mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-21 23:36:17 -04:00
Refactor deprecated WebRTC api
This commit is contained in:
parent
983a2d116b
commit
b95e9d019e
1 changed files with 10 additions and 9 deletions
|
@ -253,14 +253,14 @@ class RTCPeer extends Peer {
|
||||||
const channel = this._conn.createDataChannel('data-channel', { reliable: true });
|
const channel = this._conn.createDataChannel('data-channel', { reliable: true });
|
||||||
channel.binaryType = 'arraybuffer';
|
channel.binaryType = 'arraybuffer';
|
||||||
channel.onopen = e => this._onChannelOpened(e);
|
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) {
|
_onDescription(description) {
|
||||||
// description.sdp = description.sdp.replace('b=AS:30', 'b=AS:1638400');
|
// description.sdp = description.sdp.replace('b=AS:30', 'b=AS:1638400');
|
||||||
this._conn.setLocalDescription(description,
|
this._conn.setLocalDescription(description)
|
||||||
_ => this._sendSignal({ sdp: description }),
|
.then(_ => this._sendSignal({ sdp: description }))
|
||||||
e => this._onError(e));
|
.catch(e => this._onError(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onIceCandidate(event) {
|
_onIceCandidate(event) {
|
||||||
|
@ -272,10 +272,10 @@ class RTCPeer extends Peer {
|
||||||
if (!this._conn) this._connect(message.sender, false);
|
if (!this._conn) this._connect(message.sender, false);
|
||||||
|
|
||||||
if (message.sdp) {
|
if (message.sdp) {
|
||||||
this._conn.setRemoteDescription(new RTCSessionDescription(message.sdp), () => {
|
this._conn.setRemoteDescription(new RTCSessionDescription(message.sdp))
|
||||||
if (message.sdp.type !== 'offer') return;
|
.then( _ => this._conn.createAnswer())
|
||||||
this._conn.createAnswer(d => this._onDescription(d), e => this._onError(e));
|
.then(d => this._onDescription(d))
|
||||||
}, e => this._onError(e));
|
.catch(e => this._onError(e));
|
||||||
} else if (message.ice) {
|
} else if (message.ice) {
|
||||||
this._conn.addIceCandidate(new RTCIceCandidate(message.ice));
|
this._conn.addIceCandidate(new RTCIceCandidate(message.ice));
|
||||||
}
|
}
|
||||||
|
@ -323,6 +323,7 @@ class RTCPeer extends Peer {
|
||||||
}
|
}
|
||||||
|
|
||||||
_send(message) {
|
_send(message) {
|
||||||
|
if (!this._channel) return this.refresh();
|
||||||
this._channel.send(message);
|
this._channel.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue