瀏覽代碼

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,7 +267,8 @@ export default class BrowserCapabilities extends BrowserDetection {
267 267
      */
268 268
     supportsInsertableStreams() {
269 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,8 +66,14 @@ export default class E2EEcontext {
66 66
         }
67 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 78
         this._worker.postMessage({
73 79
             operation: 'decode',
@@ -91,8 +97,14 @@ export default class E2EEcontext {
91 97
         }
92 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 109
         this._worker.postMessage({
98 110
             operation: 'encode',

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

@@ -1,5 +1,21 @@
1 1
 // Worker for E2EE/Insertable streams. Currently served as an inline blob.
2 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 19
     // We use a ringbuffer of keys so we can change them and still decode packets that were
4 20
     // encrypted with an old key.
5 21
     // In the future when we dont rely on a globally shared key we will actually use it. For
@@ -183,7 +199,7 @@ const code = `
183 199
             const keyIndex = this._currentKeyIndex % this._cryptoKeyRing.length;
184 200
 
185 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 204
                 return crypto.subtle.encrypt({
189 205
                     name: 'AES-GCM',
@@ -316,6 +332,9 @@ const code = `
316 332
             });
317 333
 
318 334
             readableStream
335
+                .pipeThrough(new TransformStream({
336
+                  transform: polyFillEncodedFrameMetadata, // M83 polyfill.
337
+                }))
319 338
                 .pipeThrough(transformStream)
320 339
                 .pipeTo(writableStream);
321 340
             if (keyBytes) {
@@ -333,6 +352,9 @@ const code = `
333 352
             });
334 353
 
335 354
             readableStream
355
+                .pipeThrough(new TransformStream({
356
+                  transform: polyFillEncodedFrameMetadata, // M83 polyfill.
357
+                }))
336 358
                 .pipeThrough(transformStream)
337 359
                 .pipeTo(writableStream);
338 360
             if (keyBytes) {

Loading…
取消
儲存