Explorar el Código

fix(e2ee) fix race condition when restarting media sessions

Make sure the P2P tracks are not added to the JVB session when we are restarting
the media sessions, since the PC has not been created with the encoded streams
constraint yet.
dev1
Saúl Ibarra Corretgé hace 3 años
padre
commit
5a4232f908
Se han modificado 1 ficheros con 38 adiciones y 17 borrados
  1. 38
    17
      JitsiConference.js

+ 38
- 17
JitsiConference.js Ver fichero

@@ -2363,6 +2363,8 @@ JitsiConference.prototype.onCallEnded = function(
2363 2363
         // Let the RTC service do any cleanups
2364 2364
         this.rtc.onCallEnded();
2365 2365
     } else if (jingleSession === this.p2pJingleSession) {
2366
+        const stopOptions = {};
2367
+
2366 2368
         // It's the responder who decides to enforce JVB mode, so that both
2367 2369
         // initiator and responder are aware if it was intentional.
2368 2370
         if (reasonCondition === 'decline' && reasonText === 'force JVB121') {
@@ -2374,8 +2376,12 @@ JitsiConference.prototype.onCallEnded = function(
2374 2376
             // terminates the session, before we get the event on our side.
2375 2377
             // But we are able to parse the reason and mark it here.
2376 2378
             Statistics.analytics.addPermanentProperties({ p2pFailed: true });
2379
+        } else if (reasonCondition === 'success' && reasonText === 'restart') {
2380
+            // When we are restarting media sessions we don't want to switch the tracks
2381
+            // to the JVB just yet.
2382
+            stopOptions.requestRestart = true;
2377 2383
         }
2378
-        this._stopP2PSession();
2384
+        this._stopP2PSession(stopOptions);
2379 2385
     } else {
2380 2386
         logger.error(
2381 2387
             'Received onCallEnded for invalid session',
@@ -2923,7 +2929,10 @@ JitsiConference.prototype._onIceConnectionFailed = function(session) {
2923 2929
                     }));
2924 2930
 
2925 2931
         }
2926
-        this._stopP2PSession('connectivity-error', 'ICE FAILED');
2932
+        this._stopP2PSession({
2933
+            reason: 'connectivity-error',
2934
+            reasonDescription: 'ICE FAILED'
2935
+        });
2927 2936
     } else if (session && this.jvbJingleSession === session) {
2928 2937
         this._delayedIceFailed = new IceFailedHandling(this);
2929 2938
         this._delayedIceFailed.start(session);
@@ -3073,7 +3082,10 @@ JitsiConference.prototype._onIceConnectionEstablished = function(
3073 3082
         && Math.random() < forceJVB121Ratio) {
3074 3083
         logger.info(`Forcing JVB 121 mode (ratio=${forceJVB121Ratio})...`);
3075 3084
         Statistics.analytics.addPermanentProperties({ forceJvb121: true });
3076
-        this._stopP2PSession('decline', 'force JVB121');
3085
+        this._stopP2PSession({
3086
+            reason: 'decline',
3087
+            reasonDescription: 'force JVB121'
3088
+        });
3077 3089
 
3078 3090
         done = true;
3079 3091
     }
@@ -3463,15 +3475,22 @@ JitsiConference.prototype._shouldBeInP2PMode = function() {
3463 3475
 
3464 3476
 /**
3465 3477
  * Stops the current P2P session.
3466
- * @param {string} [reason="success"] one of the Jingle "reason" element
3478
+ * @param {Object} options - Options for stopping P2P.
3479
+ * @param {string} options.reason - One of the Jingle "reason" element
3467 3480
  * names as defined by https://xmpp.org/extensions/xep-0166.html#def-reason
3468
- * @param {string} [reasonDescription="Turing off P2P session"] text
3481
+ * @param {string} options.reasonDescription - Text
3469 3482
  * description that will be included in the session terminate message
3483
+ * @param {boolean} requestRestart - Whether this is due to a session restart, in which case
3484
+ * media will not be resumed on the JVB.
3470 3485
  * @private
3471 3486
  */
3472
-JitsiConference.prototype._stopP2PSession = function(
3473
-        reason,
3474
-        reasonDescription) {
3487
+JitsiConference.prototype._stopP2PSession = function(options = {}) {
3488
+    const {
3489
+        reason = 'success',
3490
+        reasonDescription = 'Turning off P2P session',
3491
+        requestRestart = false
3492
+    } = options;
3493
+
3475 3494
     if (!this.p2pJingleSession) {
3476 3495
         logger.error('No P2P session to be stopped!');
3477 3496
 
@@ -3482,7 +3501,7 @@ JitsiConference.prototype._stopP2PSession = function(
3482 3501
 
3483 3502
     // Swap remote tracks, but only if the P2P has been fully established
3484 3503
     if (wasP2PEstablished) {
3485
-        if (this.jvbJingleSession) {
3504
+        if (this.jvbJingleSession && !requestRestart) {
3486 3505
             this._resumeMediaTransferForJvbConnection();
3487 3506
         }
3488 3507
 
@@ -3520,9 +3539,8 @@ JitsiConference.prototype._stopP2PSession = function(
3520 3539
                         + ' P2P Jingle session', error);
3521 3540
             }
3522 3541
         }, {
3523
-            reason: reason ? reason : 'success',
3524
-            reasonDescription: reasonDescription
3525
-                ? reasonDescription : 'Turing off P2P session',
3542
+            reason,
3543
+            reasonDescription,
3526 3544
             sendSessionTerminate: this.room
3527 3545
                 && this.getParticipantById(
3528 3546
                     Strophe.getResourceFromJid(this.p2pJingleSession.remoteJid))
@@ -3535,7 +3553,7 @@ JitsiConference.prototype._stopP2PSession = function(
3535 3553
 
3536 3554
     if (wasP2PEstablished) {
3537 3555
         // Add back remote JVB tracks
3538
-        if (this.jvbJingleSession) {
3556
+        if (this.jvbJingleSession && !requestRestart) {
3539 3557
             this._addRemoteJVBTracks();
3540 3558
         } else {
3541 3559
             logger.info('Not adding remote JVB tracks - no session yet');
@@ -3609,10 +3627,10 @@ JitsiConference.prototype.startP2PSession = function() {
3609 3627
 };
3610 3628
 
3611 3629
 /**
3612
- * Manually stops the current P2P session (should be used only in the tests)
3630
+ * Manually stops the current P2P session (should be used only in the tests).
3613 3631
  */
3614
-JitsiConference.prototype.stopP2PSession = function() {
3615
-    this._stopP2PSession();
3632
+JitsiConference.prototype.stopP2PSession = function(options) {
3633
+    this._stopP2PSession(options);
3616 3634
 };
3617 3635
 
3618 3636
 /**
@@ -3738,7 +3756,10 @@ JitsiConference.prototype._sendConferenceLeftAnalyticsEvent = function() {
3738 3756
  */
3739 3757
 JitsiConference.prototype._restartMediaSessions = function() {
3740 3758
     if (this.p2pJingleSession) {
3741
-        this.stopP2PSession();
3759
+        this._stopP2PSession({
3760
+            reasonDescription: 'restart',
3761
+            requestRestart: true
3762
+        });
3742 3763
     }
3743 3764
 
3744 3765
     if (this.jvbJingleSession) {

Loading…
Cancelar
Guardar