diff --git a/webrtc/RTCPeerConnection-helper.js b/webrtc/RTCPeerConnection-helper.js index df277ff6d35585..9baf840df21321 100644 --- a/webrtc/RTCPeerConnection-helper.js +++ b/webrtc/RTCPeerConnection-helper.js @@ -251,6 +251,8 @@ function createDataChannelPair( // Wait for RTP and RTCP stats to arrive async function waitForRtpAndRtcpStats(pc) { + // If remote stats are never reported, return after 5 seconds. + const startTime = performance.now(); while (true) { const report = await pc.getStats(); const stats = [...report.values()].filter(({type}) => type.endsWith("bound-rtp")); @@ -259,6 +261,9 @@ async function waitForRtpAndRtcpStats(pc) { if (stats.length && stats.every(({localId, remoteId}) => localId || remoteId)) { break; } + if (performance.now() > startTime + 5000) { + break; + } } }