瀏覽代碼

e2ee: update for latest spec changes in Chrome M84

which landed in
  https://bugs.chromium.org/p/chromium/issues/detail?id=1069295#c4
master
Philipp Hancke 5 年之前
父節點
當前提交
2a7d854169
共有 3 個文件被更改,包括 41 次插入6 次删除
  1. 2
    1
      modules/browser/BrowserCapabilities.js
  2. 16
    4
      modules/e2ee/E2EEContext.js
  3. 23
    1
      modules/e2ee/Worker.js

+ 2
- 1
modules/browser/BrowserCapabilities.js 查看文件

267
      */
267
      */
268
     supportsInsertableStreams() {
268
     supportsInsertableStreams() {
269
         return Boolean(typeof window.RTCRtpSender !== 'undefined'
269
         return Boolean(typeof window.RTCRtpSender !== 'undefined'
270
-            && window.RTCRtpSender.prototype.createEncodedVideoStreams);
270
+            && (window.RTCRtpSender.prototype.createEncodedStreams
271
+                || window.RTCRtpSender.prototype.createEncodedVideoStreams));
271
     }
272
     }
272
 
273
 
273
     /**
274
     /**

+ 16
- 4
modules/e2ee/E2EEContext.js 查看文件

66
         }
66
         }
67
         receiver[kJitsiE2EE] = true;
67
         receiver[kJitsiE2EE] = true;
68
 
68
 
69
-        const receiverStreams
70
-            = kind === 'video' ? receiver.createEncodedVideoStreams() : receiver.createEncodedAudioStreams();
69
+        let receiverStreams;
70
+
71
+        if (receiver.createEncodedStreams) {
72
+            receiverStreams = receiver.createEncodedStreams();
73
+        } else {
74
+            receiverStreams = kind === 'video' ? receiver.createEncodedVideoStreams()
75
+                : receiver.createEncodedAudioStreams();
76
+        }
71
 
77
 
72
         this._worker.postMessage({
78
         this._worker.postMessage({
73
             operation: 'decode',
79
             operation: 'decode',
91
         }
97
         }
92
         sender[kJitsiE2EE] = true;
98
         sender[kJitsiE2EE] = true;
93
 
99
 
94
-        const senderStreams
95
-            = kind === 'video' ? sender.createEncodedVideoStreams() : sender.createEncodedAudioStreams();
100
+        let senderStreams;
101
+
102
+        if (sender.createEncodedStreams) {
103
+            senderStreams = sender.createEncodedStreams();
104
+        } else {
105
+            senderStreams = kind === 'video' ? sender.createEncodedVideoStreams()
106
+                : sender.createEncodedAudioStreams();
107
+        }
96
 
108
 
97
         this._worker.postMessage({
109
         this._worker.postMessage({
98
             operation: 'encode',
110
             operation: 'encode',

+ 23
- 1
modules/e2ee/Worker.js 查看文件

1
 // Worker for E2EE/Insertable streams. Currently served as an inline blob.
1
 // Worker for E2EE/Insertable streams. Currently served as an inline blob.
2
 const code = `
2
 const code = `
3
+    // Polyfill RTCEncoded(Audio|Video)Frame.getMetadata() (not available in M83, available M84+).
4
+    // The polyfill can not be done on the prototype since its not exposed in workers. Instead,
5
+    // it is done as another transformation to keep it separate.
6
+    function polyFillEncodedFrameMetadata(encodedFrame, controller) {
7
+      if (!encodedFrame.getMetadata) {
8
+        encodedFrame.getMetadata = function() {
9
+          return {
10
+            // TODO: provide a more complete polyfill based on additionalData for video.
11
+            synchronizationSource: this.synchronizationSource,
12
+            contributingSources: this.contributingSources
13
+          };
14
+        };
15
+      }
16
+      controller.enqueue(encodedFrame);
17
+    }
18
+
3
     // We use a ringbuffer of keys so we can change them and still decode packets that were
19
     // We use a ringbuffer of keys so we can change them and still decode packets that were
4
     // encrypted with an old key.
20
     // encrypted with an old key.
5
     // In the future when we dont rely on a globally shared key we will actually use it. For
21
     // In the future when we dont rely on a globally shared key we will actually use it. For
183
             const keyIndex = this._currentKeyIndex % this._cryptoKeyRing.length;
199
             const keyIndex = this._currentKeyIndex % this._cryptoKeyRing.length;
184
 
200
 
185
             if (this._cryptoKeyRing[keyIndex]) {
201
             if (this._cryptoKeyRing[keyIndex]) {
186
-                const iv = this.makeIV(encodedFrame.synchronizationSource, encodedFrame.timestamp);
202
+                const iv = this.makeIV(encodedFrame.getMetadata().synchronizationSource, encodedFrame.timestamp);
187
 
203
 
188
                 return crypto.subtle.encrypt({
204
                 return crypto.subtle.encrypt({
189
                     name: 'AES-GCM',
205
                     name: 'AES-GCM',
316
             });
332
             });
317
 
333
 
318
             readableStream
334
             readableStream
335
+                .pipeThrough(new TransformStream({
336
+                  transform: polyFillEncodedFrameMetadata, // M83 polyfill.
337
+                }))
319
                 .pipeThrough(transformStream)
338
                 .pipeThrough(transformStream)
320
                 .pipeTo(writableStream);
339
                 .pipeTo(writableStream);
321
             if (keyBytes) {
340
             if (keyBytes) {
333
             });
352
             });
334
 
353
 
335
             readableStream
354
             readableStream
355
+                .pipeThrough(new TransformStream({
356
+                  transform: polyFillEncodedFrameMetadata, // M83 polyfill.
357
+                }))
336
                 .pipeThrough(transformStream)
358
                 .pipeThrough(transformStream)
337
                 .pipeTo(writableStream);
359
                 .pipeTo(writableStream);
338
             if (keyBytes) {
360
             if (keyBytes) {

Loading…
取消
儲存