Browse Source

hips: fix enabling E2EE for tracks added later to the conference

dev1
Saúl Ibarra Corretgé 5 years ago
parent
commit
5423a24f18
2 changed files with 65 additions and 24 deletions
  1. 50
    24
      JitsiConference.js
  2. 15
    0
      modules/e2ee/E2EEContext.js

+ 50
- 24
JitsiConference.js View File

1114
 
1114
 
1115
     this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, newTrack);
1115
     this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, newTrack);
1116
 
1116
 
1117
-    // Setup E2EE handling, if supported.
1118
-    if (!this.isP2PActive() && this._e2eeCtx) {
1119
-        const activeTPC = this.getActivePeerConnection();
1120
-        const sender = activeTPC ? activeTPC.findSenderForTrack(newTrack.track) : null;
1121
-
1122
-        if (sender) {
1123
-            this._e2eeCtx.handleSender(sender, newTrack.getType());
1124
-        } else {
1125
-            logger.warn(`Could not handle E2EE for local ${newTrack.getType()} track: sender not found`);
1126
-        }
1127
-    }
1117
+    this._setupSenderE2EEForTrack(newTrack);
1128
 };
1118
 };
1129
 
1119
 
1130
 /**
1120
 /**
1654
     }
1644
     }
1655
 
1645
 
1656
     // Setup E2EE handling, if supported.
1646
     // Setup E2EE handling, if supported.
1657
-    if (!this.isP2PActive() && this._e2eeCtx) {
1658
-        const activeTPC = this.getActivePeerConnection();
1659
-        const receiver = activeTPC ? activeTPC.findReceiverForTrack(track.track) : null;
1660
-
1661
-        if (receiver) {
1662
-            this._e2eeCtx.handleReceiver(receiver, track.getType());
1663
-        } else {
1664
-            logger.warn(`Could not handle E2EE for remote ${track.getType()} track: receiver not found`);
1665
-        }
1666
-    }
1647
+    this._setupReceiverE2EEForTrack(track);
1667
 
1648
 
1668
     const id = track.getParticipantId();
1649
     const id = track.getParticipantId();
1669
     const participant = this.getParticipantById(id);
1650
     const participant = this.getParticipantById(id);
1739
  * @param {JitsiRemoteTrack} removedTrack
1720
  * @param {JitsiRemoteTrack} removedTrack
1740
  */
1721
  */
1741
 JitsiConference.prototype.onRemoteTrackRemoved = function(removedTrack) {
1722
 JitsiConference.prototype.onRemoteTrackRemoved = function(removedTrack) {
1742
-    // TODO: handle E2EE.
1743
-
1744
     this.getParticipants().forEach(participant => {
1723
     this.getParticipants().forEach(participant => {
1745
         const tracks = participant.getTracks();
1724
         const tracks = participant.getTracks();
1746
 
1725
 
1879
     this._setBridgeChannel(jingleOffer, jingleSession.peerconnection);
1858
     this._setBridgeChannel(jingleOffer, jingleSession.peerconnection);
1880
 
1859
 
1881
     // Add local tracks to the session
1860
     // Add local tracks to the session
1861
+    const localTracks = this.getLocalTracks();
1862
+
1882
     try {
1863
     try {
1883
         jingleSession.acceptOffer(
1864
         jingleSession.acceptOffer(
1884
             jingleOffer,
1865
             jingleOffer,
1889
                 if (this.isP2PActive() && this.jvbJingleSession) {
1870
                 if (this.isP2PActive() && this.jvbJingleSession) {
1890
                     this._suspendMediaTransferForJvbConnection();
1871
                     this._suspendMediaTransferForJvbConnection();
1891
                 }
1872
                 }
1873
+
1874
+                // Setup E2EE.
1875
+                for (const track of localTracks) {
1876
+                    this._setupSenderE2EEForTrack(track);
1877
+                }
1892
             },
1878
             },
1893
             error => {
1879
             error => {
1894
                 GlobalOnErrorHandler.callErrorHandler(error);
1880
                 GlobalOnErrorHandler.callErrorHandler(error);
1895
                 logger.error(
1881
                 logger.error(
1896
                     'Failed to accept incoming Jingle session', error);
1882
                     'Failed to accept incoming Jingle session', error);
1897
             },
1883
             },
1898
-            this.getLocalTracks()
1884
+            localTracks
1899
         );
1885
         );
1900
 
1886
 
1901
         // Start callstats as soon as peerconnection is initialized,
1887
         // Start callstats as soon as peerconnection is initialized,
3327
 
3313
 
3328
     this._e2eeCtx.setKey(key);
3314
     this._e2eeCtx.setKey(key);
3329
 };
3315
 };
3316
+
3317
+/**
3318
+ * Setup E2EE for the sending side, if supported.
3319
+ * Note that this is only done for the JVB Peer Connecction.
3320
+ *
3321
+ * @returns {void}
3322
+ */
3323
+JitsiConference.prototype._setupSenderE2EEForTrack = function(track) {
3324
+    const jvbPc = this.jvbJingleSession ? this.jvbJingleSession.peerconnection : null;
3325
+
3326
+    if (jvbPc && this._e2eeCtx) {
3327
+        const sender = jvbPc.findSenderForTrack(track.track);
3328
+
3329
+        if (sender) {
3330
+            this._e2eeCtx.handleSender(sender, track.getType());
3331
+        } else {
3332
+            logger.warn(`Could not handle E2EE for local ${track.getType()} track: sender not found`);
3333
+        }
3334
+    }
3335
+};
3336
+
3337
+/**
3338
+ * Setup E2EE for the receiving side, if supported.
3339
+ * Note that this is only done for the JVB Peer Connecction.
3340
+ *
3341
+ * @returns {void}
3342
+ */
3343
+JitsiConference.prototype._setupReceiverE2EEForTrack = function(track) {
3344
+    const jvbPc = this.jvbJingleSession ? this.jvbJingleSession.peerconnection : null;
3345
+
3346
+    if (jvbPc && this._e2eeCtx) {
3347
+        const receiver = jvbPc.findReceiverForTrack(track.track);
3348
+
3349
+        if (receiver) {
3350
+            this._e2eeCtx.handleReceiver(receiver, track.getType());
3351
+        } else {
3352
+            logger.warn(`Could not handle E2EE for remote ${track.getType()} track: receiver not found`);
3353
+        }
3354
+    }
3355
+};

+ 15
- 0
modules/e2ee/E2EEContext.js View File

31
     undefined: 1 // frame.type is not set on audio
31
     undefined: 1 // frame.type is not set on audio
32
 };
32
 };
33
 
33
 
34
+// Flag to set on senders / receivers to avoid setting up the encryption transform
35
+// more than once.
36
+const kJitsiE2EE = Symbol('kJitsiE2EE');
34
 
37
 
35
 /**
38
 /**
36
  * Context encapsulating the cryptography bits required for E2EE.
39
  * Context encapsulating the cryptography bits required for E2EE.
83
      * @param {string} kind - The kind of track this receiver belongs to.
86
      * @param {string} kind - The kind of track this receiver belongs to.
84
      */
87
      */
85
     handleReceiver(receiver, kind) {
88
     handleReceiver(receiver, kind) {
89
+        if (receiver[kJitsiE2EE]) {
90
+            return;
91
+        }
92
+
86
         const receiverStreams
93
         const receiverStreams
87
             = kind === 'video' ? receiver.createEncodedVideoStreams() : receiver.createEncodedAudioStreams();
94
             = kind === 'video' ? receiver.createEncodedVideoStreams() : receiver.createEncodedAudioStreams();
88
         const transform = new TransformStream({
95
         const transform = new TransformStream({
92
         receiverStreams.readableStream
99
         receiverStreams.readableStream
93
             .pipeThrough(transform)
100
             .pipeThrough(transform)
94
             .pipeTo(receiverStreams.writableStream);
101
             .pipeTo(receiverStreams.writableStream);
102
+
103
+        receiver[kJitsiE2EE] = true;
95
     }
104
     }
96
 
105
 
97
     /**
106
     /**
102
      * @param {string} kind - The kind of track this sender belongs to.
111
      * @param {string} kind - The kind of track this sender belongs to.
103
      */
112
      */
104
     handleSender(sender, kind) {
113
     handleSender(sender, kind) {
114
+        if (sender[kJitsiE2EE]) {
115
+            return;
116
+        }
117
+
105
         const senderStreams
118
         const senderStreams
106
             = kind === 'video' ? sender.createEncodedVideoStreams() : sender.createEncodedAudioStreams();
119
             = kind === 'video' ? sender.createEncodedVideoStreams() : sender.createEncodedAudioStreams();
107
         const transform = new TransformStream({
120
         const transform = new TransformStream({
111
         senderStreams.readableStream
124
         senderStreams.readableStream
112
             .pipeThrough(transform)
125
             .pipeThrough(transform)
113
             .pipeTo(senderStreams.writableStream);
126
             .pipeTo(senderStreams.writableStream);
127
+
128
+        sender[kJitsiE2EE] = true;
114
     }
129
     }
115
 
130
 
116
     /**
131
     /**

Loading…
Cancel
Save