瀏覽代碼

ref: recreate peerconnections to enable e2ee

Delays e2e encryption initialization until any encryption key is set.
Recreates peerconnections in order to enable insertable streams
only if the e2ee is used. This is to avoid bug around insertable streams
which may cause audio issue when the main JavaScript thread is loaded:

https://bugs.chromium.org/p/chromium/issues/detail?id=1103280
master
paweldomas 5 年之前
父節點
當前提交
1c4622c865
共有 4 個檔案被更改,包括 62 行新增11 行删除
  1. 51
    9
      JitsiConference.js
  2. 3
    1
      modules/RTC/RTC.js
  3. 2
    0
      modules/xmpp/JingleSession.js
  4. 6
    1
      modules/xmpp/JingleSessionPC.js

+ 51
- 9
JitsiConference.js 查看文件

@@ -234,10 +234,6 @@ export default function JitsiConference(options) {
234 234
     this.videoSIPGWHandler = new VideoSIPGW(this.room);
235 235
     this.recordingManager = new RecordingManager(this.room);
236 236
     this._conferenceJoinAnalyticsEventSent = false;
237
-
238
-    if (this.isE2EESupported()) {
239
-        this._e2eEncryption = new E2EEncryption(this, { salt: this.options.name });
240
-    }
241 237
 }
242 238
 
243 239
 // FIXME convert JitsiConference to ES6 - ASAP !
@@ -1880,7 +1876,10 @@ JitsiConference.prototype._acceptJvbIncomingCall = function(
1880 1876
         }));
1881 1877
 
1882 1878
     try {
1883
-        jingleSession.initialize(this.room, this.rtc, this.options.config);
1879
+        jingleSession.initialize(this.room, this.rtc, {
1880
+            ...this.options.config,
1881
+            enableInsertableStreams: Boolean(this._e2eEncryption)
1882
+        });
1884 1883
     } catch (error) {
1885 1884
         GlobalOnErrorHandler.callErrorHandler(error);
1886 1885
     }
@@ -2639,7 +2638,12 @@ JitsiConference.prototype._acceptP2PIncomingCall = function(
2639 2638
     this.p2pJingleSession = jingleSession;
2640 2639
     this._sendConferenceJoinAnalyticsEvent();
2641 2640
 
2642
-    this.p2pJingleSession.initialize(this.room, this.rtc, this.options.config);
2641
+    this.p2pJingleSession.initialize(
2642
+        this.room,
2643
+        this.rtc, {
2644
+            ...this.options.config,
2645
+            enableInsertableStreams: Boolean(this._e2eEncryption)
2646
+        });
2643 2647
 
2644 2648
     logger.info('Starting CallStats for P2P connection...');
2645 2649
 
@@ -2995,7 +2999,12 @@ JitsiConference.prototype._startP2PSession = function(remoteJid) {
2995 2999
         'Created new P2P JingleSession', this.room.myroomjid, remoteJid);
2996 3000
     this._sendConferenceJoinAnalyticsEvent();
2997 3001
 
2998
-    this.p2pJingleSession.initialize(this.room, this.rtc, this.options.config);
3002
+    this.p2pJingleSession.initialize(
3003
+        this.room,
3004
+        this.rtc, {
3005
+            ...this.options.config,
3006
+            enableInsertableStreams: Boolean(this._e2eEncryption)
3007
+        });
2999 3008
 
3000 3009
     logger.info('Starting CallStats for P2P connection...');
3001 3010
 
@@ -3345,6 +3354,35 @@ JitsiConference.prototype.isE2EESupported = function() {
3345 3354
     return browser.supportsInsertableStreams() && !(config.testing && config.testing.disableE2EE);
3346 3355
 };
3347 3356
 
3357
+/**
3358
+ * Initializes the E2E encryption module. Currently any active media session muste be restarted due to
3359
+ * the limitation that the insertable streams constraint can only be set when a new PeerConnection instance is created.
3360
+ *
3361
+ * @private
3362
+ * @returns {void}
3363
+ */
3364
+JitsiConference.prototype._initializeE2EEncryption = function() {
3365
+    this._e2eEncryption = new E2EEncryption(this, { salt: this.options.name });
3366
+
3367
+    // Need to re-create the peerconnections in order to apply the insertable streams constraint
3368
+    this.p2pJingleSession && this.stopP2PSession();
3369
+
3370
+    const jvbJingleSession = this.jvbJingleSession;
3371
+
3372
+    jvbJingleSession && jvbJingleSession.terminate(
3373
+        null /* success callback => we don't care */,
3374
+        error => {
3375
+            logger.warn(`An error occurred while trying to terminate ${jvbJingleSession}`, error);
3376
+        }, {
3377
+            reason: 'success',
3378
+            reasonDescription: 'restart required',
3379
+            requestRestart: true,
3380
+            sendSessionTerminate: true
3381
+        });
3382
+
3383
+    this._maybeStartOrStopP2P(false);
3384
+};
3385
+
3348 3386
 /**
3349 3387
  * Sets the key to be used for End-To-End encryption.
3350 3388
  *
@@ -3352,12 +3390,16 @@ JitsiConference.prototype.isE2EESupported = function() {
3352 3390
  * @returns {void}
3353 3391
  */
3354 3392
 JitsiConference.prototype.setE2EEKey = function(key) {
3355
-    if (!this._e2eEncryption) {
3356
-        logger.warn('Cannot set E2EE key: there is no defined context, platform is likely unsupported.');
3393
+    if (!this.isE2EESupported()) {
3394
+        logger.warn('Cannot set E2EE key: platform is not supported.');
3357 3395
 
3358 3396
         return;
3359 3397
     }
3360 3398
 
3399
+    if (!this._e2eEncryption) {
3400
+        this._initializeE2EEncryption();
3401
+    }
3402
+
3361 3403
     this._e2eEncryption.setKey(key);
3362 3404
 };
3363 3405
 

+ 3
- 1
modules/RTC/RTC.js 查看文件

@@ -499,6 +499,8 @@ export default class RTC extends Listenable {
499 499
      * @param {boolean} isP2P Indicates whether or not the new TPC will be used
500 500
      *      in a peer to peer type of session.
501 501
      * @param {object} options The config options.
502
+     * @param {boolean} options.enableInsertableStreams - Set to true when the insertable streams constraints is to be
503
+     * enabled on the PeerConnection.
502 504
      * @param {boolean} options.disableSimulcast If set to 'true' will disable
503 505
      *      the simulcast.
504 506
      * @param {boolean} options.disableRtx If set to 'true' will disable the
@@ -522,7 +524,7 @@ export default class RTC extends Listenable {
522 524
 
523 525
         // FIXME: We should rename iceConfig to pcConfig.
524 526
 
525
-        if (browser.supportsInsertableStreams() && !(this.options.testing && this.options.testing.disableE2EE)) {
527
+        if (options.enableInsertableStreams) {
526 528
             logger.debug('E2EE - setting insertable streams constraints');
527 529
             iceConfig.encodedInsertableStreams = true;
528 530
             iceConfig.forceEncodedAudioInsertableStreams = true; // legacy, to be removed in M85.

+ 2
- 0
modules/xmpp/JingleSession.js 查看文件

@@ -175,6 +175,8 @@ export default class JingleSession extends Listenable {
175 175
      * @param {Object} options
176 176
      * @param {string} [options.reason] XMPP Jingle error condition
177 177
      * @param {string} [options.reasonDescription] some meaningful error message
178
+     * @param {boolean} [options.requestRestart=false] set to true to ask Jicofo to start a new session one this once is
179
+     * terminated.
178 180
      * @param {boolean} [options.sendSessionTerminate=true] set to false to skip
179 181
      * sending session-terminate. It may not make sense to send it if the XMPP
180 182
      * connection has been closed already or if the remote peer has disconnected

+ 6
- 1
modules/xmpp/JingleSessionPC.js 查看文件

@@ -47,6 +47,8 @@ const DEFAULT_MAX_STATS = 300;
47 47
  * @property {boolean} disableH264 - Described in the config.js[1].
48 48
  * @property {boolean} disableRtx - Described in the config.js[1].
49 49
  * @property {boolean} disableSimulcast - Described in the config.js[1].
50
+ * @property {boolean} enableInsertableStreams - Set to true when the insertable streams constraints is to be enabled
51
+ * on the PeerConnection.
50 52
  * @property {boolean} enableLayerSuspension - Described in the config.js[1].
51 53
  * @property {boolean} failICE - it's an option used in the tests. Set to
52 54
  * <tt>true</tt> to block any real candidates and make the ICE fail.
@@ -326,6 +328,8 @@ export default class JingleSessionPC extends JingleSession {
326 328
             pcOptions.maxstats = DEFAULT_MAX_STATS;
327 329
         }
328 330
         pcOptions.capScreenshareBitrate = false;
331
+        pcOptions.enableInsertableStreams = options.enableInsertableStreams;
332
+
329 333
         if (this.isP2P) {
330 334
             // simulcast needs to be disabled for P2P (121) calls
331 335
             pcOptions.disableSimulcast = true;
@@ -1455,7 +1459,8 @@ export default class JingleSessionPC extends JingleSession {
1455 1459
                 && sessionTerminate.c(
1456 1460
                     'bridge-session', {
1457 1461
                         xmlns: 'http://jitsi.org/protocol/focus',
1458
-                        id: this._bridgeSessionId
1462
+                        id: this._bridgeSessionId,
1463
+                        restart: options && options.requestRestart === true
1459 1464
                     }).up();
1460 1465
 
1461 1466
             // Calling tree() to print something useful

Loading…
取消
儲存