feat: SSE live fight spectating with spectator count

Enable real-time fight spectating for all live fights (not just human
fights). Multiple spectators can watch simultaneously via SSE. Spectator
count is tracked per-fight and broadcast with every SSE event.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-08 19:46:39 +00:00
co-authored by Claude Opus 4.6
parent a540320901
commit 610e799605
18 changed files with 1555 additions and 397 deletions
+51
View File
@@ -0,0 +1,51 @@
// Web Worker for Kokoro TTS — runs ONNX neural network inference off the main thread.
// This prevents the 1-5 second freezes that occur when generate() runs on the UI thread.
let tts: any = null
self.addEventListener('message', async (e: MessageEvent) => {
const msg = e.data
switch (msg.type) {
case 'init': {
try {
const { KokoroTTS } = await import('kokoro-js')
tts = await KokoroTTS.from_pretrained('onnx-community/Kokoro-82M-ONNX', {
dtype: 'q8',
device: null,
progress_callback: (p: any) => {
if (p.progress !== undefined) {
self.postMessage({ type: 'progress', progress: p.progress })
}
},
})
self.postMessage({ type: 'init-done' })
} catch (err) {
self.postMessage({ type: 'init-failed', error: String(err) })
}
break
}
case 'generate': {
if (!tts) {
self.postMessage({ type: 'generate-failed', id: msg.id, error: 'not initialized' })
break
}
try {
const result = await tts.generate(msg.text, {
voice: msg.voice,
speed: msg.speed,
})
// Copy to a standalone ArrayBuffer so we can transfer ownership (zero-copy to main thread)
const audio = new Float32Array(result.audio)
self.postMessage(
{ type: 'generate-done', id: msg.id, audio, sampleRate: result.sampling_rate },
{ transfer: [audio.buffer] },
)
} catch (err) {
self.postMessage({ type: 'generate-failed', id: msg.id, error: String(err) })
}
break
}
}
})