From 5e71d00acee466f7d9e5758f402336b600bf2409 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:38:46 +0700 Subject: [PATCH] android, desktop: workaround of missing stuns support in calls (#4033) * android, desktop: workaround of missing stuns support in calls * const --- .../src/commonMain/resources/assets/www/call.js | 12 +++++++++++- packages/simplex-chat-webrtc/src/call.ts | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 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 9d9782e90c..9e7d29189f 100644 --- a/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js +++ b/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js @@ -111,7 +111,17 @@ const processCommand = (function () { }); } async function initializeCall(config, mediaType, aesKey) { - const pc = new RTCPeerConnection(config.peerConnectionConfig); + var _a; + let pc; + try { + pc = new RTCPeerConnection(config.peerConnectionConfig); + } + catch (e) { + console.log("Error while constructing RTCPeerConnection, will try without 'stuns' specified: " + e); + const withoutStuns = (_a = config.peerConnectionConfig.iceServers) === null || _a === void 0 ? void 0 : _a.filter((elem) => typeof elem.urls === "string" ? !elem.urls.startsWith("stuns:") : !elem.urls.some((url) => url.startsWith("stuns:"))); + config.peerConnectionConfig.iceServers = withoutStuns; + pc = new RTCPeerConnection(config.peerConnectionConfig); + } const remoteStream = new MediaStream(); const localCamera = VideoCamera.User; const localStream = await getLocalMediaStream(mediaType, localCamera); diff --git a/packages/simplex-chat-webrtc/src/call.ts b/packages/simplex-chat-webrtc/src/call.ts index 1d68b83f73..41241e22c2 100644 --- a/packages/simplex-chat-webrtc/src/call.ts +++ b/packages/simplex-chat-webrtc/src/call.ts @@ -321,7 +321,17 @@ const processCommand = (function () { } async function initializeCall(config: CallConfig, mediaType: CallMediaType, aesKey?: string): Promise { - const pc = new RTCPeerConnection(config.peerConnectionConfig) + let pc: RTCPeerConnection + try { + pc = new RTCPeerConnection(config.peerConnectionConfig) + } catch (e) { + console.log("Error while constructing RTCPeerConnection, will try without 'stuns' specified: " + e) + const withoutStuns = config.peerConnectionConfig.iceServers?.filter((elem) => + typeof elem.urls === "string" ? !elem.urls.startsWith("stuns:") : !elem.urls.some((url) => url.startsWith("stuns:")) + ) + config.peerConnectionConfig.iceServers = withoutStuns + pc = new RTCPeerConnection(config.peerConnectionConfig) + } const remoteStream = new MediaStream() const localCamera = VideoCamera.User const localStream = await getLocalMediaStream(mediaType, localCamera)