Ver código fonte

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

dev1
Saúl Ibarra Corretgé 5 anos atrás
pai
commit
5423a24f18
2 arquivos alterados com 65 adições e 24 exclusões
  1. 50
    24
      JitsiConference.js
  2. 15
    0
      modules/e2ee/E2EEContext.js

+ 50
- 24
JitsiConference.js Ver arquivo

@@ -1114,17 +1114,7 @@ JitsiConference.prototype._setupNewTrack = function(newTrack) {
1114 1114
 
1115 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,16 +1644,7 @@ JitsiConference.prototype.onRemoteTrackAdded = function(track) {
1654 1644
     }
1655 1645
 
1656 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 1649
     const id = track.getParticipantId();
1669 1650
     const participant = this.getParticipantById(id);
@@ -1739,8 +1720,6 @@ JitsiConference.prototype.onTransportInfo = function(session, transportInfo) {
1739 1720
  * @param {JitsiRemoteTrack} removedTrack
1740 1721
  */
1741 1722
 JitsiConference.prototype.onRemoteTrackRemoved = function(removedTrack) {
1742
-    // TODO: handle E2EE.
1743
-
1744 1723
     this.getParticipants().forEach(participant => {
1745 1724
         const tracks = participant.getTracks();
1746 1725
 
@@ -1879,6 +1858,8 @@ JitsiConference.prototype._acceptJvbIncomingCall = function(
1879 1858
     this._setBridgeChannel(jingleOffer, jingleSession.peerconnection);
1880 1859
 
1881 1860
     // Add local tracks to the session
1861
+    const localTracks = this.getLocalTracks();
1862
+
1882 1863
     try {
1883 1864
         jingleSession.acceptOffer(
1884 1865
             jingleOffer,
@@ -1889,13 +1870,18 @@ JitsiConference.prototype._acceptJvbIncomingCall = function(
1889 1870
                 if (this.isP2PActive() && this.jvbJingleSession) {
1890 1871
                     this._suspendMediaTransferForJvbConnection();
1891 1872
                 }
1873
+
1874
+                // Setup E2EE.
1875
+                for (const track of localTracks) {
1876
+                    this._setupSenderE2EEForTrack(track);
1877
+                }
1892 1878
             },
1893 1879
             error => {
1894 1880
                 GlobalOnErrorHandler.callErrorHandler(error);
1895 1881
                 logger.error(
1896 1882
                     'Failed to accept incoming Jingle session', error);
1897 1883
             },
1898
-            this.getLocalTracks()
1884
+            localTracks
1899 1885
         );
1900 1886
 
1901 1887
         // Start callstats as soon as peerconnection is initialized,
@@ -3327,3 +3313,43 @@ JitsiConference.prototype.setE2EEKey = function(key) {
3327 3313
 
3328 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 Ver arquivo

@@ -31,6 +31,9 @@ const unencryptedBytes = {
31 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 39
  * Context encapsulating the cryptography bits required for E2EE.
@@ -83,6 +86,10 @@ export default class E2EEcontext {
83 86
      * @param {string} kind - The kind of track this receiver belongs to.
84 87
      */
85 88
     handleReceiver(receiver, kind) {
89
+        if (receiver[kJitsiE2EE]) {
90
+            return;
91
+        }
92
+
86 93
         const receiverStreams
87 94
             = kind === 'video' ? receiver.createEncodedVideoStreams() : receiver.createEncodedAudioStreams();
88 95
         const transform = new TransformStream({
@@ -92,6 +99,8 @@ export default class E2EEcontext {
92 99
         receiverStreams.readableStream
93 100
             .pipeThrough(transform)
94 101
             .pipeTo(receiverStreams.writableStream);
102
+
103
+        receiver[kJitsiE2EE] = true;
95 104
     }
96 105
 
97 106
     /**
@@ -102,6 +111,10 @@ export default class E2EEcontext {
102 111
      * @param {string} kind - The kind of track this sender belongs to.
103 112
      */
104 113
     handleSender(sender, kind) {
114
+        if (sender[kJitsiE2EE]) {
115
+            return;
116
+        }
117
+
105 118
         const senderStreams
106 119
             = kind === 'video' ? sender.createEncodedVideoStreams() : sender.createEncodedAudioStreams();
107 120
         const transform = new TransformStream({
@@ -111,6 +124,8 @@ export default class E2EEcontext {
111 124
         senderStreams.readableStream
112 125
             .pipeThrough(transform)
113 126
             .pipeTo(senderStreams.writableStream);
127
+
128
+        sender[kJitsiE2EE] = true;
114 129
     }
115 130
 
116 131
     /**

Carregando…
Cancelar
Salvar