From 8ebeb3a01f6764adc3c7a373c069c3a26ba5fe5b Mon Sep 17 00:00:00 2001 From: Jan-Ivar Bruaroey Date: Fri, 15 Dec 2023 20:31:23 -0500 Subject: [PATCH 1/2] Shim RTCRtpScriptTransform. --- src/js/adapter_factory.js | 1 + src/js/chrome/chrome_shim.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/js/adapter_factory.js b/src/js/adapter_factory.js index 54bdda28..7ac2a71c 100644 --- a/src/js/adapter_factory.js +++ b/src/js/adapter_factory.js @@ -63,6 +63,7 @@ export function adapterFactory({window} = {}, options = { chromeShim.shimGetStats(window, browserDetails); chromeShim.shimSenderReceiverGetStats(window, browserDetails); chromeShim.fixNegotiationNeeded(window, browserDetails); + chromeShim.shimRTCRtpScriptTransform(window, browserDetails); commonShim.shimRTCIceCandidate(window, browserDetails); commonShim.shimRTCIceCandidateRelayProtocol(window, browserDetails); diff --git a/src/js/chrome/chrome_shim.js b/src/js/chrome/chrome_shim.js index 46aee7e2..9f0793c3 100644 --- a/src/js/chrome/chrome_shim.js +++ b/src/js/chrome/chrome_shim.js @@ -700,3 +700,37 @@ export function fixNegotiationNeeded(window, browserDetails) { return e; }); } + +export function shimRTCRtpScriptTransform(window) { + if (!window.RTCRtpScriptTransform && + !('transform' in window.RTCRtpSender.prototype) && + !('transform' in window.RTCRtpReceiver.prototype)) { + window.RTCRtpScriptTransform = class RTCRtpScriptTransform { + constructor(worker, options, transfer) { + this._worker = worker; + this._options = options; + this._transfer = transfer; + } + }; + const property = { + get() { + return this._transform || null; + }, + set(transform) { + if (transform && !(transform instanceof window.RTCRtpScriptTransform)) { + throw new TypeError("expected window.RTCRtpScriptTransform"); + } + this._transform = transform || null; + if (!transform) return; + const {readable, writable} = this.createEncodedStreams(); + transform._worker.postMessage({ + rtctransform: { + readable, writable, options: transform._options + } + }, [readable, writable, ...(transform._transfer || [])]); + } + }; + Object.defineProperty(window.RTCRtpSender.prototype, 'transform', property); + Object.defineProperty(window.RTCRtpReceiver.prototype, 'transform', property); + } +} From 9f65fa61cb12672920c3a2eb417bdb43a19044a2 Mon Sep 17 00:00:00 2001 From: Jan-Ivar Bruaroey Date: Fri, 15 Dec 2023 20:37:09 -0500 Subject: [PATCH 2/2] Fix lint errors --- src/js/chrome/chrome_shim.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/js/chrome/chrome_shim.js b/src/js/chrome/chrome_shim.js index 9f0793c3..ceae7f0c 100644 --- a/src/js/chrome/chrome_shim.js +++ b/src/js/chrome/chrome_shim.js @@ -712,16 +712,18 @@ export function shimRTCRtpScriptTransform(window) { this._transfer = transfer; } }; - const property = { + const prop = { get() { return this._transform || null; }, set(transform) { if (transform && !(transform instanceof window.RTCRtpScriptTransform)) { - throw new TypeError("expected window.RTCRtpScriptTransform"); + throw new TypeError('expected window.RTCRtpScriptTransform'); } this._transform = transform || null; - if (!transform) return; + if (!transform) { + return; + } const {readable, writable} = this.createEncodedStreams(); transform._worker.postMessage({ rtctransform: { @@ -730,7 +732,7 @@ export function shimRTCRtpScriptTransform(window) { }, [readable, writable, ...(transform._transfer || [])]); } }; - Object.defineProperty(window.RTCRtpSender.prototype, 'transform', property); - Object.defineProperty(window.RTCRtpReceiver.prototype, 'transform', property); + Object.defineProperty(window.RTCRtpSender.prototype, 'transform', prop); + Object.defineProperty(window.RTCRtpReceiver.prototype, 'transform', prop); } }