diff --git a/apps/ios/Shared/Views/Call/WebRTCClient.swift b/apps/ios/Shared/Views/Call/WebRTCClient.swift index 389e5d0503..db7910836e 100644 --- a/apps/ios/Shared/Views/Call/WebRTCClient.swift +++ b/apps/ios/Shared/Views/Call/WebRTCClient.swift @@ -306,8 +306,7 @@ final class WebRTCClient: NSObject, RTCVideoViewDelegate, RTCFrameEncryptorDeleg func setupMuteUnmuteListener(_ transceiver: RTCRtpTransceiver, _ track: RTCMediaStreamTrack) { // logger.log("Setting up mute/unmute listener in the call without encryption for mid = \(transceiver.mid)") Task { - // for some reason even for disabled tracks one packet arrives (seeing this on screenVideo track) - var lastPacketsReceived = 1 + var lastBytesReceived: Int64 = 0 // muted initially var mutedSeconds = 4 while let call = self.activeCall, transceiver.receiver.track?.readyState == .live { @@ -315,8 +314,8 @@ final class WebRTCClient: NSObject, RTCVideoViewDelegate, RTCFrameEncryptorDeleg let stat = stats.statistics.values.first(where: { stat in stat.type == "inbound-rtp"}) if let stat { //logger.debug("Stat \(stat.debugDescription)") - let packets = stat.values["packetsReceived"] as! Int - if packets <= lastPacketsReceived { + let bytes = stat.values["bytesReceived"] as! Int64 + if bytes <= lastBytesReceived { mutedSeconds += 1 if mutedSeconds == 3 { await MainActor.run { @@ -329,7 +328,7 @@ final class WebRTCClient: NSObject, RTCVideoViewDelegate, RTCFrameEncryptorDeleg self.onMediaMuteUnmute(transceiver.mid, false) } } - lastPacketsReceived = packets + lastBytesReceived = bytes mutedSeconds = 0 } } 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 0e58050fcf..32f014e622 100644 --- a/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js +++ b/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js @@ -955,8 +955,7 @@ const processCommand = (function () { function setupMuteUnmuteListener(transceiver, track) { // console.log("Setting up mute/unmute listener in the call without encryption for mid = ", transceiver.mid) let inboundStatsId = ""; - // for some reason even for disabled tracks one packet arrives (seeing this on screenVideo track) - let lastPacketsReceived = 1; + let lastBytesReceived = 0; // muted initially let mutedSeconds = 4; let statsInterval = setInterval(async () => { @@ -970,9 +969,9 @@ const processCommand = (function () { }); } if (inboundStatsId) { - // even though MSDN site says `packetsReceived` is available in WebView 80+, in reality it's available even in 69 - const packets = (_a = stats.get(inboundStatsId)) === null || _a === void 0 ? void 0 : _a.packetsReceived; - if (packets <= lastPacketsReceived) { + // even though MSDN site says `bytesReceived` is available in WebView 80+, in reality it's available even in 69 + const bytes = (_a = stats.get(inboundStatsId)) === null || _a === void 0 ? void 0 : _a.bytesReceived; + if (bytes <= lastBytesReceived) { mutedSeconds++; if (mutedSeconds == 3) { onMediaMuteUnmute(transceiver.mid, true); @@ -982,7 +981,7 @@ const processCommand = (function () { if (mutedSeconds >= 3) { onMediaMuteUnmute(transceiver.mid, false); } - lastPacketsReceived = packets; + lastBytesReceived = bytes; mutedSeconds = 0; } } diff --git a/packages/simplex-chat-webrtc/src/call.ts b/packages/simplex-chat-webrtc/src/call.ts index a961dbe442..eda535cfa7 100644 --- a/packages/simplex-chat-webrtc/src/call.ts +++ b/packages/simplex-chat-webrtc/src/call.ts @@ -1272,8 +1272,7 @@ const processCommand = (function () { function setupMuteUnmuteListener(transceiver: RTCRtpTransceiver, track: MediaStreamTrack) { // console.log("Setting up mute/unmute listener in the call without encryption for mid = ", transceiver.mid) let inboundStatsId = "" - // for some reason even for disabled tracks one packet arrives (seeing this on screenVideo track) - let lastPacketsReceived = 1 + let lastBytesReceived = 0 // muted initially let mutedSeconds = 4 let statsInterval = setInterval(async () => { @@ -1286,9 +1285,9 @@ const processCommand = (function () { }) } if (inboundStatsId) { - // even though MSDN site says `packetsReceived` is available in WebView 80+, in reality it's available even in 69 - const packets = (stats as any).get(inboundStatsId)?.packetsReceived - if (packets <= lastPacketsReceived) { + // even though MSDN site says `bytesReceived` is available in WebView 80+, in reality it's available even in 69 + const bytes = (stats as any).get(inboundStatsId)?.bytesReceived + if (bytes <= lastBytesReceived) { mutedSeconds++ if (mutedSeconds == 3) { onMediaMuteUnmute(transceiver.mid, true) @@ -1297,7 +1296,7 @@ const processCommand = (function () { if (mutedSeconds >= 3) { onMediaMuteUnmute(transceiver.mid, false) } - lastPacketsReceived = packets + lastBytesReceived = bytes mutedSeconds = 0 } }