From 584509a53d03ac923d42fb45302bf013c6302356 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sat, 9 Dec 2023 11:09:08 +0700 Subject: [PATCH] Improve IPv6 server detection --- better-xcloud.user.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/better-xcloud.user.js b/better-xcloud.user.js index f4a3c12..d1f9c6a 100644 --- a/better-xcloud.user.js +++ b/better-xcloud.user.js @@ -3033,7 +3033,7 @@ class StreamBadges { let totalIn = 0; let totalOut = 0; stats.forEach(stat => { - if (stat.type === 'candidate-pair' && stat.state == 'succeeded') { + if (stat.type === 'candidate-pair' && stat.state === 'succeeded') { totalIn += stat.bytesReceived; totalOut += stat.bytesSent; } @@ -6793,6 +6793,9 @@ function onStreamStarted($video) { const allAudioCodecs = {}; let audioCodecId; + const allCandidates = {}; + let candidateId; + stats.forEach(stat => { if (stat.type == 'codec') { const mimeType = stat.mimeType.split('/'); @@ -6810,6 +6813,10 @@ function onStreamStarted($video) { } else if (stat.kind === 'audio') { audioCodecId = stat.codecId; } + } else if (stat.type === 'candidate-pair' && stat.state === 'succeeded') { + candidateId = stat.remoteCandidateId; + } else if (stat.type === 'remote-candidate') { + allCandidates[stat.id] = stat.address; } }); @@ -6837,6 +6844,12 @@ function onStreamStarted($video) { } } + // Get server type + if (candidateId) { + console.log(candidateId, allCandidates); + StreamBadges.ipv6 = allCandidates[candidateId].includes(':'); + } + if (PREFS.get(Preferences.STATS_SHOW_WHEN_PLAYING)) { StreamStats.start(); } @@ -6934,16 +6947,6 @@ if (PREFS.get(Preferences.AUDIO_ENABLE_VOLUME_CONTROL)) { } } -RTCPeerConnection.prototype.orgAddIceCandidate = RTCPeerConnection.prototype.addIceCandidate; -RTCPeerConnection.prototype.addIceCandidate = function(...args) { - const candidate = args[0].candidate; - if (candidate && candidate.startsWith('a=candidate:1 ')) { - StreamBadges.ipv6 = candidate.substring(20).includes(':'); - } - - return this.orgAddIceCandidate.apply(this, args); -} - if (PREFS.get(Preferences.STREAM_TOUCH_CONTROLLER) === 'all') { TouchController.setup(); }