This commit is contained in:
legop3
2026-03-20 01:56:15 -04:00
parent dbfab6aa26
commit e2d9a1759b
3 changed files with 41 additions and 3 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-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" /> <meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
<title>Multi Roomba Rover</title> <title>Multi Roomba Rover</title>
<script type="module" crossorigin src="/assets/index-BjEIiAR_.js"></script> <script type="module" crossorigin src="/assets/index-CR--WtYL.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-WqYsCIRI.css"> <link rel="stylesheet" crossorigin href="/assets/index-WqYsCIRI.css">
</head> </head>
<body> <body>
@@ -49,6 +49,43 @@ function waitForIceGatheringComplete(pc, timeoutMs = 1500) {
}); });
} }
function waitForPeerConnected(pc, timeoutMs = 4000) {
return new Promise((resolve, reject) => {
if (!pc) {
reject(new Error('Peer connection missing'));
return;
}
const state = pc.connectionState;
if (state === 'connected') {
resolve();
return;
}
if (state === 'failed' || state === 'closed') {
reject(new Error(`Peer connection ${state}`));
return;
}
const timer = setTimeout(() => {
cleanup();
reject(new Error('Peer connection timeout'));
}, timeoutMs);
const onState = () => {
const next = pc.connectionState;
if (next === 'connected') {
cleanup();
resolve();
} else if (next === 'failed' || next === 'closed') {
cleanup();
reject(new Error(`Peer connection ${next}`));
}
};
function cleanup() {
clearTimeout(timer);
pc.removeEventListener('connectionstatechange', onState);
}
pc.addEventListener('connectionstatechange', onState);
});
}
function resampleTo16k(input, sampleRate) { function resampleTo16k(input, sampleRate) {
if (!input || !input.length) return new Float32Array(0); if (!input || !input.length) return new Float32Array(0);
if (sampleRate === TARGET_SAMPLE_RATE) return input; if (sampleRate === TARGET_SAMPLE_RATE) return input;
@@ -368,6 +405,7 @@ export default function VipAudioForwardingCard({
} }
const answerSdp = await response.text(); const answerSdp = await response.text();
await pc.setRemoteDescription({ type: 'answer', sdp: answerSdp }); await pc.setRemoteDescription({ type: 'answer', sdp: answerSdp });
await waitForPeerConnected(pc, 4500);
await readyMicWhip?.(target); await readyMicWhip?.(target);
setMicState('live'); setMicState('live');
} catch (err) { } catch (err) {