mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-29 04:39:53 +00:00
ui: rely on different value in stats when checking calls media (#5007)
* ui: rely on different value in stats when checking calls media * int64
This commit is contained in:
parent
b01efd9d0a
commit
fabbe0285d
3 changed files with 14 additions and 17 deletions
|
@ -306,8 +306,7 @@ final class WebRTCClient: NSObject, RTCVideoViewDelegate, RTCFrameEncryptorDeleg
|
||||||
func setupMuteUnmuteListener(_ transceiver: RTCRtpTransceiver, _ track: RTCMediaStreamTrack) {
|
func setupMuteUnmuteListener(_ transceiver: RTCRtpTransceiver, _ track: RTCMediaStreamTrack) {
|
||||||
// logger.log("Setting up mute/unmute listener in the call without encryption for mid = \(transceiver.mid)")
|
// logger.log("Setting up mute/unmute listener in the call without encryption for mid = \(transceiver.mid)")
|
||||||
Task {
|
Task {
|
||||||
// for some reason even for disabled tracks one packet arrives (seeing this on screenVideo track)
|
var lastBytesReceived: Int64 = 0
|
||||||
var lastPacketsReceived = 1
|
|
||||||
// muted initially
|
// muted initially
|
||||||
var mutedSeconds = 4
|
var mutedSeconds = 4
|
||||||
while let call = self.activeCall, transceiver.receiver.track?.readyState == .live {
|
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"})
|
let stat = stats.statistics.values.first(where: { stat in stat.type == "inbound-rtp"})
|
||||||
if let stat {
|
if let stat {
|
||||||
//logger.debug("Stat \(stat.debugDescription)")
|
//logger.debug("Stat \(stat.debugDescription)")
|
||||||
let packets = stat.values["packetsReceived"] as! Int
|
let bytes = stat.values["bytesReceived"] as! Int64
|
||||||
if packets <= lastPacketsReceived {
|
if bytes <= lastBytesReceived {
|
||||||
mutedSeconds += 1
|
mutedSeconds += 1
|
||||||
if mutedSeconds == 3 {
|
if mutedSeconds == 3 {
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
|
@ -329,7 +328,7 @@ final class WebRTCClient: NSObject, RTCVideoViewDelegate, RTCFrameEncryptorDeleg
|
||||||
self.onMediaMuteUnmute(transceiver.mid, false)
|
self.onMediaMuteUnmute(transceiver.mid, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastPacketsReceived = packets
|
lastBytesReceived = bytes
|
||||||
mutedSeconds = 0
|
mutedSeconds = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -955,8 +955,7 @@ const processCommand = (function () {
|
||||||
function setupMuteUnmuteListener(transceiver, track) {
|
function setupMuteUnmuteListener(transceiver, track) {
|
||||||
// console.log("Setting up mute/unmute listener in the call without encryption for mid = ", transceiver.mid)
|
// console.log("Setting up mute/unmute listener in the call without encryption for mid = ", transceiver.mid)
|
||||||
let inboundStatsId = "";
|
let inboundStatsId = "";
|
||||||
// for some reason even for disabled tracks one packet arrives (seeing this on screenVideo track)
|
let lastBytesReceived = 0;
|
||||||
let lastPacketsReceived = 1;
|
|
||||||
// muted initially
|
// muted initially
|
||||||
let mutedSeconds = 4;
|
let mutedSeconds = 4;
|
||||||
let statsInterval = setInterval(async () => {
|
let statsInterval = setInterval(async () => {
|
||||||
|
@ -970,9 +969,9 @@ const processCommand = (function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (inboundStatsId) {
|
if (inboundStatsId) {
|
||||||
// even though MSDN site says `packetsReceived` is available in WebView 80+, in reality it's available even in 69
|
// even though MSDN site says `bytesReceived` 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;
|
const bytes = (_a = stats.get(inboundStatsId)) === null || _a === void 0 ? void 0 : _a.bytesReceived;
|
||||||
if (packets <= lastPacketsReceived) {
|
if (bytes <= lastBytesReceived) {
|
||||||
mutedSeconds++;
|
mutedSeconds++;
|
||||||
if (mutedSeconds == 3) {
|
if (mutedSeconds == 3) {
|
||||||
onMediaMuteUnmute(transceiver.mid, true);
|
onMediaMuteUnmute(transceiver.mid, true);
|
||||||
|
@ -982,7 +981,7 @@ const processCommand = (function () {
|
||||||
if (mutedSeconds >= 3) {
|
if (mutedSeconds >= 3) {
|
||||||
onMediaMuteUnmute(transceiver.mid, false);
|
onMediaMuteUnmute(transceiver.mid, false);
|
||||||
}
|
}
|
||||||
lastPacketsReceived = packets;
|
lastBytesReceived = bytes;
|
||||||
mutedSeconds = 0;
|
mutedSeconds = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1272,8 +1272,7 @@ const processCommand = (function () {
|
||||||
function setupMuteUnmuteListener(transceiver: RTCRtpTransceiver, track: MediaStreamTrack) {
|
function setupMuteUnmuteListener(transceiver: RTCRtpTransceiver, track: MediaStreamTrack) {
|
||||||
// console.log("Setting up mute/unmute listener in the call without encryption for mid = ", transceiver.mid)
|
// console.log("Setting up mute/unmute listener in the call without encryption for mid = ", transceiver.mid)
|
||||||
let inboundStatsId = ""
|
let inboundStatsId = ""
|
||||||
// for some reason even for disabled tracks one packet arrives (seeing this on screenVideo track)
|
let lastBytesReceived = 0
|
||||||
let lastPacketsReceived = 1
|
|
||||||
// muted initially
|
// muted initially
|
||||||
let mutedSeconds = 4
|
let mutedSeconds = 4
|
||||||
let statsInterval = setInterval(async () => {
|
let statsInterval = setInterval(async () => {
|
||||||
|
@ -1286,9 +1285,9 @@ const processCommand = (function () {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (inboundStatsId) {
|
if (inboundStatsId) {
|
||||||
// even though MSDN site says `packetsReceived` is available in WebView 80+, in reality it's available even in 69
|
// even though MSDN site says `bytesReceived` is available in WebView 80+, in reality it's available even in 69
|
||||||
const packets = (stats as any).get(inboundStatsId)?.packetsReceived
|
const bytes = (stats as any).get(inboundStatsId)?.bytesReceived
|
||||||
if (packets <= lastPacketsReceived) {
|
if (bytes <= lastBytesReceived) {
|
||||||
mutedSeconds++
|
mutedSeconds++
|
||||||
if (mutedSeconds == 3) {
|
if (mutedSeconds == 3) {
|
||||||
onMediaMuteUnmute(transceiver.mid, true)
|
onMediaMuteUnmute(transceiver.mid, true)
|
||||||
|
@ -1297,7 +1296,7 @@ const processCommand = (function () {
|
||||||
if (mutedSeconds >= 3) {
|
if (mutedSeconds >= 3) {
|
||||||
onMediaMuteUnmute(transceiver.mid, false)
|
onMediaMuteUnmute(transceiver.mid, false)
|
||||||
}
|
}
|
||||||
lastPacketsReceived = packets
|
lastBytesReceived = bytes
|
||||||
mutedSeconds = 0
|
mutedSeconds = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue