Ver código fonte

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é 3 anos atrás
pai
commit
5a4232f908
1 arquivos alterados com 38 adições e 17 exclusões
  1. 38
    17
      JitsiConference.js

+ 38
- 17
JitsiConference.js Ver arquivo

2363
         // Let the RTC service do any cleanups
2363
         // Let the RTC service do any cleanups
2364
         this.rtc.onCallEnded();
2364
         this.rtc.onCallEnded();
2365
     } else if (jingleSession === this.p2pJingleSession) {
2365
     } else if (jingleSession === this.p2pJingleSession) {
2366
+        const stopOptions = {};
2367
+
2366
         // It's the responder who decides to enforce JVB mode, so that both
2368
         // It's the responder who decides to enforce JVB mode, so that both
2367
         // initiator and responder are aware if it was intentional.
2369
         // initiator and responder are aware if it was intentional.
2368
         if (reasonCondition === 'decline' && reasonText === 'force JVB121') {
2370
         if (reasonCondition === 'decline' && reasonText === 'force JVB121') {
2374
             // terminates the session, before we get the event on our side.
2376
             // terminates the session, before we get the event on our side.
2375
             // But we are able to parse the reason and mark it here.
2377
             // But we are able to parse the reason and mark it here.
2376
             Statistics.analytics.addPermanentProperties({ p2pFailed: true });
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
     } else {
2385
     } else {
2380
         logger.error(
2386
         logger.error(
2381
             'Received onCallEnded for invalid session',
2387
             'Received onCallEnded for invalid 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
     } else if (session && this.jvbJingleSession === session) {
2936
     } else if (session && this.jvbJingleSession === session) {
2928
         this._delayedIceFailed = new IceFailedHandling(this);
2937
         this._delayedIceFailed = new IceFailedHandling(this);
2929
         this._delayedIceFailed.start(session);
2938
         this._delayedIceFailed.start(session);
3073
         && Math.random() < forceJVB121Ratio) {
3082
         && Math.random() < forceJVB121Ratio) {
3074
         logger.info(`Forcing JVB 121 mode (ratio=${forceJVB121Ratio})...`);
3083
         logger.info(`Forcing JVB 121 mode (ratio=${forceJVB121Ratio})...`);
3075
         Statistics.analytics.addPermanentProperties({ forceJvb121: true });
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
         done = true;
3090
         done = true;
3079
     }
3091
     }
3463
 
3475
 
3464
 /**
3476
 /**
3465
  * Stops the current P2P session.
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
  * names as defined by https://xmpp.org/extensions/xep-0166.html#def-reason
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
  * description that will be included in the session terminate message
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
  * @private
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
     if (!this.p2pJingleSession) {
3494
     if (!this.p2pJingleSession) {
3476
         logger.error('No P2P session to be stopped!');
3495
         logger.error('No P2P session to be stopped!');
3477
 
3496
 
3482
 
3501
 
3483
     // Swap remote tracks, but only if the P2P has been fully established
3502
     // Swap remote tracks, but only if the P2P has been fully established
3484
     if (wasP2PEstablished) {
3503
     if (wasP2PEstablished) {
3485
-        if (this.jvbJingleSession) {
3504
+        if (this.jvbJingleSession && !requestRestart) {
3486
             this._resumeMediaTransferForJvbConnection();
3505
             this._resumeMediaTransferForJvbConnection();
3487
         }
3506
         }
3488
 
3507
 
3520
                         + ' P2P Jingle session', error);
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
             sendSessionTerminate: this.room
3544
             sendSessionTerminate: this.room
3527
                 && this.getParticipantById(
3545
                 && this.getParticipantById(
3528
                     Strophe.getResourceFromJid(this.p2pJingleSession.remoteJid))
3546
                     Strophe.getResourceFromJid(this.p2pJingleSession.remoteJid))
3535
 
3553
 
3536
     if (wasP2PEstablished) {
3554
     if (wasP2PEstablished) {
3537
         // Add back remote JVB tracks
3555
         // Add back remote JVB tracks
3538
-        if (this.jvbJingleSession) {
3556
+        if (this.jvbJingleSession && !requestRestart) {
3539
             this._addRemoteJVBTracks();
3557
             this._addRemoteJVBTracks();
3540
         } else {
3558
         } else {
3541
             logger.info('Not adding remote JVB tracks - no session yet');
3559
             logger.info('Not adding remote JVB tracks - no session yet');
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
  */
3756
  */
3739
 JitsiConference.prototype._restartMediaSessions = function() {
3757
 JitsiConference.prototype._restartMediaSessions = function() {
3740
     if (this.p2pJingleSession) {
3758
     if (this.p2pJingleSession) {
3741
-        this.stopP2PSession();
3759
+        this._stopP2PSession({
3760
+            reasonDescription: 'restart',
3761
+            requestRestart: true
3762
+        });
3742
     }
3763
     }
3743
 
3764
 
3744
     if (this.jvbJingleSession) {
3765
     if (this.jvbJingleSession) {

Carregando…
Cancelar
Salvar