|
@@ -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) {
|