Checking the state again to avoid any eventual race condition
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
const waitForIceGatheringComplete = async (pc, timeoutMs = 2000) => {
|
const waitForIceGatheringComplete = async (pc, timeoutMs = 2000) => {
|
||||||
if (pc.iceGatheringState === 'complete') return;
|
if (pc.iceGatheringState === 'complete') return;
|
||||||
console.log("Waiting for ICE gathering to complete...");
|
console.log("Waiting for ICE gathering to complete. Current state:", pc.iceGatheringState);
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
let timeoutId;
|
let timeoutId;
|
||||||
const checkState = () => {
|
const checkState = () => {
|
||||||
@@ -47,6 +47,8 @@
|
|||||||
};
|
};
|
||||||
pc.addEventListener('icegatheringstatechange', checkState);
|
pc.addEventListener('icegatheringstatechange', checkState);
|
||||||
timeoutId = setTimeout(onTimeout, timeoutMs);
|
timeoutId = setTimeout(onTimeout, timeoutMs);
|
||||||
|
// Checking the state again to avoid any eventual race condition
|
||||||
|
checkState();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user