teleportxr 1.0.40 → 1.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/connections/webrtcconnection.js +24 -16
- package/package.json +1 -1
|
@@ -103,6 +103,21 @@ class WebRtcConnection extends EventEmitter
|
|
|
103
103
|
}
|
|
104
104
|
reconnect()
|
|
105
105
|
{
|
|
106
|
+
// Close and clean up the previous PeerConnection before creating a new one.
|
|
107
|
+
// Failing to do so leaves the old ICE agent (and its UDP socket) alive, which
|
|
108
|
+
// causes it to keep sending/receiving STUN messages with stale credentials and
|
|
109
|
+
// confuses the peer's new ICE agent (ufrag mismatch).
|
|
110
|
+
if (this.peerConnection)
|
|
111
|
+
{
|
|
112
|
+
this.peerConnection.removeEventListener('iceconnectionstatechange', this._onIceConnectionStateChange);
|
|
113
|
+
this.peerConnection.removeEventListener('icegatheringstatechange', this._onIceGatheringStateChange);
|
|
114
|
+
this.peerConnection.removeEventListener("icecandidateerror", this._onIceCandidateError);
|
|
115
|
+
this.peerConnection.removeEventListener("connectionstatechange", this._onConnectionStateChange);
|
|
116
|
+
if (this.onIceCandidate)
|
|
117
|
+
this.peerConnection.removeEventListener('icecandidate', this.onIceCandidate);
|
|
118
|
+
try { this.peerConnection.close(); } catch (e) {}
|
|
119
|
+
this.peerConnection = null;
|
|
120
|
+
}
|
|
106
121
|
this.peerConnection =new DefaultRTCPeerConnection({ sdpSemantics: 'unified-plan', iceServers: this.iceServers, iceTransportPolicy: this.iceTransportPolicy});
|
|
107
122
|
this.beforeOffer();
|
|
108
123
|
this.connectionTimer = this.options.setTimeout(() =>
|
|
@@ -267,8 +282,9 @@ class WebRtcConnection extends EventEmitter
|
|
|
267
282
|
} else if (this.peerConnection.iceConnectionState === 'disconnected'
|
|
268
283
|
|| this.peerConnection.iceConnectionState === 'failed')
|
|
269
284
|
{
|
|
270
|
-
|
|
271
|
-
|
|
285
|
+
// Do not call restartIce() here: reconnect() below creates a brand-new
|
|
286
|
+
// PeerConnection, so any ICE restart on the old PC is immediately
|
|
287
|
+
// abandoned and produces a third set of dangling ICE credentials.
|
|
272
288
|
if (!this.connectionTimer && !this.reconnectionTimer)
|
|
273
289
|
{
|
|
274
290
|
const self = this;
|
|
@@ -312,21 +328,13 @@ class WebRtcConnection extends EventEmitter
|
|
|
312
328
|
this.reconnectionTimer = null;
|
|
313
329
|
}
|
|
314
330
|
|
|
315
|
-
//
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
331
|
+
// Always close the PeerConnection regardless of connectionState.
|
|
332
|
+
// Previously it was only closed when state was "connected" or "failed",
|
|
333
|
+
// which left the ICE agent alive (and its socket bound) when state was
|
|
334
|
+
// "disconnected", causing stale STUN traffic toward the peer on reconnect.
|
|
335
|
+
if (this.peerConnection)
|
|
319
336
|
{
|
|
320
|
-
|
|
321
|
-
/* this.peerConnection.cl.forEach(mediaStream => { {
|
|
322
|
-
mediaStream.videoTracks.forEach( it => {it.setEnabled(false); });
|
|
323
|
-
mediaStream.audioTracks.forEach( it => {it.setEnabled(false); });
|
|
324
|
-
|
|
325
|
-
};
|
|
326
|
-
});;6'7*/
|
|
327
|
-
|
|
328
|
-
// Close the connection
|
|
329
|
-
this.peerConnection.close();
|
|
337
|
+
try { this.peerConnection.close(); } catch (e) {}
|
|
330
338
|
}
|
|
331
339
|
|
|
332
340
|
// Nullify the reference
|
package/package.json
CHANGED