feat: live SSE stage, phone view and presenter control

- proxy Go /api/stream through Nitro; drive /stage, /live, /plan and /forecast from scenario events
- fall back to 5 s polling after SSE failures or heartbeat silence; show Live/Polling/Offline
- authenticate /control and POST /api/scenario in Nitro with server-side control credentials
- add big-screen stage with local QR and a no-login phone recommendation view
- add SSE unit tests and a live smoke test; refresh README/Makefile
This commit is contained in:
Noel Sabia committed 2026-11-14 06:59:07 +01:00
1 parent 7181562e0f
commit 233fdbf66c
24 files changed
+2757 -49

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import QRCode from 'qrcode'
/**
* Generate the /stage QR code locally. No third-party QR image service is
* called at runtime, so the big screen keeps working without internet access.
*/
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const text = typeof query.text === 'string' ? query.text.trim() : ''
if (!text) {
throw createError({ statusCode: 400, statusMessage: 'text is required' })
}
if (text.length > 1024) {
throw createError({ statusCode: 400, statusMessage: 'text is too long for a QR code' })
}
let svg: string
try {
svg = await QRCode.toString(text, {
type: 'svg',
margin: 1,
width: 320,
errorCorrectionLevel: 'M',
color: { dark: '#0f172a', light: '#ffffff' },
})
} catch {
throw createError({ statusCode: 400, statusMessage: 'could not encode text as a QR code' })
}
setResponseHeaders(event, {
'content-type': 'image/svg+xml; charset=utf-8',
'cache-control': 'public, max-age=300',
})
return svg
})
+2 -2
View File
@@ -1,8 +1,8 @@
import type { ScenarioState } from '../../shared/types'
import { apiRequest, isMockMode } from '../utils/api'
import { mockScenario } from '../utils/mock-data'
import { getMockScenario } from '../utils/mock-scenario'
export default defineEventHandler(async () => {
if (isMockMode()) return mockScenario
if (isMockMode()) return getMockScenario()
return apiRequest<ScenarioState>('/api/scenario')
})
+2 -9
View File
@@ -1,9 +1,7 @@
import { SCENARIOS } from '../../shared/types'
import type { Scenario, ScenarioDefinition, ScenarioState } from '../../shared/types'
import { apiRequest, isMockMode } from '../utils/api'
import { mockScenario } from '../utils/mock-data'
let version = mockScenario.version
import { setMockScenario } from '../utils/mock-scenario'
export default defineEventHandler(async (event) => {
const body = await readBody<ScenarioDefinition>(event)
@@ -16,12 +14,7 @@ export default defineEventHandler(async (event) => {
}
if (isMockMode()) {
version += 1
return {
version,
scenario: body,
at: new Date().toISOString(),
}
return setMockScenario(body)
}
// Control credentials are attached in the server process, never in the
+24
View File
@@ -0,0 +1,24 @@
import { apiBaseUrl, isMockMode } from '../utils/api'
/**
* Same-origin SSE proxy. The browser never talks to Go directly, so the
* Cloudflare/K8s CORS surface stays closed and the stream can be cached or
* authenticated at one edge only.
*
* h3's proxyRequest pipes response chunks as they arrive (it does not await
* the full body), which preserves the 15 s heartbeat and `retry: 3000`.
*/
export default defineEventHandler(async (event) => {
if (isMockMode() || process.env.NUXT_DISABLE_SSE === '1') {
// Failure drill: make the client prove the 5 s polling fallback. Mock mode
// has no upstream stream either, so both paths fail fast and visibly.
throw createError({
statusCode: 503,
statusMessage: 'SSE is disabled; the scenario polling fallback is active.',
})
}
return proxyRequest(event, `${apiBaseUrl()}/api/stream`, {
headers: { accept: 'text/event-stream' },
})
})