This commit is contained in:
legop3
2026-03-20 02:03:25 -04:00
parent cc6e1fde56
commit ab9d388392
+45 -22
View File
@@ -351,6 +351,10 @@ function cleanupUploadFile(worker) {
function stopContentWriter(worker) { function stopContentWriter(worker) {
if (!worker) return; if (!worker) return;
if (worker.micWhipRestartTimer) {
clearTimeout(worker.micWhipRestartTimer);
worker.micWhipRestartTimer = null;
}
if (worker.micIdleTimer) { if (worker.micIdleTimer) {
clearTimeout(worker.micIdleTimer); clearTimeout(worker.micIdleTimer);
worker.micIdleTimer = null; worker.micIdleTimer = null;
@@ -516,37 +520,55 @@ function startMicWhipRelay(roverId, ownerSocketId = null) {
return; return;
} }
stopContentWriter(worker);
cleanupUploadFile(worker);
const inputUrl = resolveMicReadUrl(roverId);
const proc = spawnProcess(roverId, 'mic-whip-reader', buildWhipRelayReaderArgs(inputUrl), {
captureStdout: true,
});
worker.contentProc = proc;
worker.contentKind = 'mic_whip'; worker.contentKind = 'mic_whip';
worker.activeOwnerSocketId = ownerSocketId; worker.activeOwnerSocketId = ownerSocketId;
worker.micWhipPathId = resolveMicPathId(roverId); worker.micWhipPathId = resolveMicPathId(roverId);
const seq = ++worker.writerSeq; if (worker.micWhipRestartTimer) {
attachWriterPipe(worker, proc); clearTimeout(worker.micWhipRestartTimer);
setState(roverId, { state: 'playing', source: 'mic-whip', error: null, startedAt: Date.now() }); worker.micWhipRestartTimer = null;
}
stopContentWriter(worker);
worker.contentKind = 'mic_whip';
worker.activeOwnerSocketId = ownerSocketId;
worker.micWhipPathId = resolveMicPathId(roverId);
setState(roverId, { state: 'starting', source: 'mic-whip', error: null, startedAt: Date.now() });
proc.on('exit', (code, signal) => { const launch = () => {
const current = workers.get(roverId); const current = workers.get(roverId);
if (!current || current.stopping) return; if (!current || current.stopping) return;
if (current.writerSeq !== seq || current.contentProc !== proc) return; if (current.contentKind !== 'mic_whip' || current.activeOwnerSocketId !== ownerSocketId) return;
current.contentProc = null;
current.contentKind = null; const inputUrl = resolveMicReadUrl(roverId);
current.activeOwnerSocketId = null; const proc = spawnProcess(roverId, 'mic-whip-reader', buildWhipRelayReaderArgs(inputUrl), {
current.micWhipPathId = null; captureStdout: true,
if (code != null && code !== 0 && signal !== 'SIGTERM') { });
current.contentProc = proc;
const seq = ++current.writerSeq;
attachWriterPipe(current, proc);
setState(roverId, { state: 'playing', source: 'mic-whip', error: null, startedAt: Date.now() });
proc.on('exit', (code, signal) => {
const next = workers.get(roverId);
if (!next || next.stopping) return;
if (next.writerSeq !== seq || next.contentProc !== proc) return;
next.contentProc = null;
if (next.contentKind !== 'mic_whip' || next.activeOwnerSocketId !== ownerSocketId) return;
if (signal === 'SIGTERM') return;
setState(roverId, { setState(roverId, {
state: 'error', state: 'starting',
source: 'mic-whip', source: 'mic-whip',
error: `mic whip reader exited code=${code} signal=${signal || 'none'}`, error: code != null && code !== 0 ? `relay reconnecting (last code=${code})` : null,
startedAt: Date.now(),
}); });
} next.micWhipRestartTimer = setTimeout(() => {
startSilenceWriter(roverId); next.micWhipRestartTimer = null;
}); launch();
}, 300);
});
};
launch();
} }
function decodeMicChunk(payload = {}) { function decodeMicChunk(payload = {}) {
@@ -636,6 +658,7 @@ function ensureWorker(roverId) {
activeUploadPath: null, activeUploadPath: null,
micWriter: null, micWriter: null,
micWhipPathId: null, micWhipPathId: null,
micWhipRestartTimer: null,
micLastChunkAt: 0, micLastChunkAt: 0,
micIdleTimer: null, micIdleTimer: null,
micBackpressured: false, micBackpressured: false,