This commit is contained in:
legop3
2026-03-20 02:00:17 -04:00
parent e2d9a1759b
commit cc6e1fde56
3 changed files with 35 additions and 18 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -11,7 +11,7 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
<title>Multi Roomba Rover</title>
<script type="module" crossorigin src="/assets/index-CR--WtYL.js"></script>
<script type="module" crossorigin src="/assets/index-D2iMrx7r.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-WqYsCIRI.css">
</head>
<body>
@@ -49,19 +49,31 @@ function waitForIceGatheringComplete(pc, timeoutMs = 1500) {
});
}
function waitForPeerConnected(pc, timeoutMs = 4000) {
function isPeerTransportReady(pc) {
if (!pc) return false;
const conn = pc.connectionState;
const ice = pc.iceConnectionState;
if (conn === 'connected') return true;
if (ice === 'connected' || ice === 'completed') return true;
return false;
}
function waitForPeerConnected(pc, timeoutMs = 10000) {
return new Promise((resolve, reject) => {
if (!pc) {
reject(new Error('Peer connection missing'));
return;
}
const state = pc.connectionState;
if (state === 'connected') {
if (isPeerTransportReady(pc)) {
resolve();
return;
}
if (state === 'failed' || state === 'closed') {
reject(new Error(`Peer connection ${state}`));
if (
pc.connectionState === 'failed' ||
pc.connectionState === 'closed' ||
pc.iceConnectionState === 'failed'
) {
reject(new Error(`Peer connection ${pc.connectionState || pc.iceConnectionState}`));
return;
}
const timer = setTimeout(() => {
@@ -69,20 +81,25 @@ function waitForPeerConnected(pc, timeoutMs = 4000) {
reject(new Error('Peer connection timeout'));
}, timeoutMs);
const onState = () => {
const next = pc.connectionState;
if (next === 'connected') {
if (isPeerTransportReady(pc)) {
cleanup();
resolve();
} else if (next === 'failed' || next === 'closed') {
} else if (
pc.connectionState === 'failed' ||
pc.connectionState === 'closed' ||
pc.iceConnectionState === 'failed'
) {
cleanup();
reject(new Error(`Peer connection ${next}`));
reject(new Error(`Peer connection ${pc.connectionState || pc.iceConnectionState}`));
}
};
function cleanup() {
clearTimeout(timer);
pc.removeEventListener('connectionstatechange', onState);
pc.removeEventListener('iceconnectionstatechange', onState);
}
pc.addEventListener('connectionstatechange', onState);
pc.addEventListener('iceconnectionstatechange', onState);
});
}
@@ -405,7 +422,7 @@ export default function VipAudioForwardingCard({
}
const answerSdp = await response.text();
await pc.setRemoteDescription({ type: 'answer', sdp: answerSdp });
await waitForPeerConnected(pc, 4500);
await waitForPeerConnected(pc, 10000);
await readyMicWhip?.(target);
setMicState('live');
} catch (err) {