From 714ad566d7878460ff3c0230567e53b4b1b0675e Mon Sep 17 00:00:00 2001 From: Kevin Hanna Date: Wed, 4 Dec 2024 14:04:25 +0000 Subject: [PATCH] media: catch Type errors when adding Transceiver in Safari17Handler We're seeing this error when running this handler in the Webkit build used by Playwright in the e2e test suite in Github Actions I can't reproduce it locally, and 'normal' builds of safari work just fine, so this is a compromise to get the tests working --- packages/media/package.json | 2 +- packages/media/src/utils/Safari17Handler.ts | 29 +++++++++++++++------ yarn.lock | 5 ++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/packages/media/package.json b/packages/media/package.json index 9fa8d4f9b..305a0fb48 100644 --- a/packages/media/package.json +++ b/packages/media/package.json @@ -49,7 +49,6 @@ "dist/**/*.d.cts" ], "dependencies": { - "@types/ua-parser-js": "^0.7.39", "check-ip": "^1.1.1", "events": "^3.3.0", "ip-address": "^9.0.5", @@ -67,6 +66,7 @@ "devDependencies": { "@babel/core": "^7.23.2", "@babel/preset-env": "^7.23.2", + "@types/ua-parser-js": "^0.7.39", "jest-websocket-mock": "^2.5.0", "process": "^0.11.10" }, diff --git a/packages/media/src/utils/Safari17Handler.ts b/packages/media/src/utils/Safari17Handler.ts index a4fff2151..e4f0c4228 100644 --- a/packages/media/src/utils/Safari17Handler.ts +++ b/packages/media/src/utils/Safari17Handler.ts @@ -185,7 +185,7 @@ export class Safari17 extends HandlerInterface { rtcpMuxPolicy: "require", ...additionalSettings, }, - proprietaryConstraints + proprietaryConstraints, ); this._pc.addEventListener("icegatheringstatechange", () => { @@ -329,18 +329,31 @@ export class Safari17 extends HandlerInterface { } const sendingRemoteRtpParameters = utils.clone( - this._sendingRemoteRtpParametersByKind![track.kind] + this._sendingRemoteRtpParametersByKind![track.kind], ); // This may throw. sendingRemoteRtpParameters.codecs = ortc.reduceCodecs(sendingRemoteRtpParameters.codecs, codec); const mediaSectionIdx = this._remoteSdp!.getNextMediaSectionIdx(); - const transceiver = this._pc.addTransceiver(track, { - direction: "sendonly", - streams: [this._sendStream], - sendEncodings: encodings, - }); + let transceiver: RTCRtpTransceiver; + try { + transceiver = this._pc.addTransceiver(track, { + direction: "sendonly", + streams: [this._sendStream], + sendEncodings: encodings, + }); + } catch (e) { + if ((e as Error).message === "Type error") { + console.warn("Failed to add transceiver with encodings, retrying without"); + transceiver = this._pc.addTransceiver(track, { + direction: "sendonly", + streams: [this._sendStream], + }); + } else { + throw e; + } + } if (onRtpSender) { onRtpSender(transceiver.sender); @@ -363,7 +376,7 @@ export class Safari17 extends HandlerInterface { await this._pc.setLocalDescription(offer); // We can now get the transceiver.mid. - const localId = transceiver.mid; + const localId = transceiver.mid!; // Set MID. sendingRtpParameters.mid = localId; diff --git a/yarn.lock b/yarn.lock index 588831fdf..bd86b9d5d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17282,6 +17282,11 @@ ua-parser-js@^1.0.35: resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.38.tgz#66bb0c4c0e322fe48edfe6d446df6042e62f25e2" integrity sha512-Aq5ppTOfvrCMgAPneW1HfWj66Xi7XL+/mIy996R1/CLS/rcyJQm6QZdsKrUeivDFQ+Oc9Wyuwor8Ze8peEoUoQ== +ua-parser-js@^1.0.38: + version "1.0.39" + resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.39.tgz#bfc07f361549bf249bd8f4589a4cccec18fd2018" + integrity sha512-k24RCVWlEcjkdOxYmVJgeD/0a1TiSpqLg+ZalVGV9lsnr4yqu0w7tX/x2xX6G4zpkgQnRf89lxuZ1wsbjXM8lw== + ua-parser-js@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-2.0.0.tgz#fae88e352510198bd29a6dd41624c7cd0d2c7ade"