From 5f501f1cb9f638ebcf57939b758d647dfbf28e95 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Thu, 2 May 2024 22:47:52 +0700 Subject: [PATCH] android, desktop: fix android video calls (#4118) --- .../src/commonMain/resources/assets/www/call.js | 14 ++++++++++++-- packages/simplex-chat-webrtc/src/call.ts | 13 +++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js b/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js index 218fe0c660..571c494c7c 100644 --- a/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js +++ b/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js @@ -453,7 +453,11 @@ const processCommand = (function () { // For opus (where encodedFrame.type is not set) this is the TOC byte from // https://tools.ietf.org/html/rfc6716#section-3.1 var _a; - const capabilities = RTCRtpSender.getCapabilities("video"); + // Using RTCRtpReceiver instead of RTCRtpSender, see these lines: + // - if (!is_recv_codec && !is_send_codec) { + // + if (!is_recv_codec) { + // https://webrtc.googlesource.com/src.git/+/db2f52ba88cf9f98211df2dabb3f8aca9251c4a2%5E%21/ + const capabilities = RTCRtpReceiver.getCapabilities("video"); if (capabilities) { const { codecs } = capabilities; const selectedCodecIndex = codecs.findIndex((c) => c.mimeType === "video/VP8"); @@ -464,7 +468,13 @@ const processCommand = (function () { // Firefox doesn't have this function implemented: // https://bugzilla.mozilla.org/show_bug.cgi?id=1396922 if (((_a = t.sender.track) === null || _a === void 0 ? void 0 : _a.kind) === "video" && t.setCodecPreferences) { - t.setCodecPreferences(codecs); + try { + t.setCodecPreferences(codecs); + } + catch (error) { + // Shouldn't be here but in case something goes wrong, it will allow to make a call with auto-selected codecs + console.log("Failed to set codec preferences, trying without any preferences: " + error); + } } } } diff --git a/packages/simplex-chat-webrtc/src/call.ts b/packages/simplex-chat-webrtc/src/call.ts index e7788ac723..19682249e9 100644 --- a/packages/simplex-chat-webrtc/src/call.ts +++ b/packages/simplex-chat-webrtc/src/call.ts @@ -657,7 +657,11 @@ const processCommand = (function () { // For opus (where encodedFrame.type is not set) this is the TOC byte from // https://tools.ietf.org/html/rfc6716#section-3.1 - const capabilities = RTCRtpSender.getCapabilities("video") + // Using RTCRtpReceiver instead of RTCRtpSender, see these lines: + // - if (!is_recv_codec && !is_send_codec) { + // + if (!is_recv_codec) { + // https://webrtc.googlesource.com/src.git/+/db2f52ba88cf9f98211df2dabb3f8aca9251c4a2%5E%21/ + const capabilities = RTCRtpReceiver.getCapabilities("video") if (capabilities) { const {codecs} = capabilities const selectedCodecIndex = codecs.findIndex((c) => c.mimeType === "video/VP8") @@ -668,7 +672,12 @@ const processCommand = (function () { // Firefox doesn't have this function implemented: // https://bugzilla.mozilla.org/show_bug.cgi?id=1396922 if (t.sender.track?.kind === "video" && t.setCodecPreferences) { - t.setCodecPreferences(codecs) + try { + t.setCodecPreferences(codecs) + } catch (error) { + // Shouldn't be here but in case something goes wrong, it will allow to make a call with auto-selected codecs + console.log("Failed to set codec preferences, trying without any preferences: " + error) + } } } }