diff options
Diffstat (limited to 'live/server.js')
| -rw-r--r-- | live/server.js | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/live/server.js b/live/server.js index 0e04aca..2aaa355 100644 --- a/live/server.js +++ b/live/server.js @@ -19,6 +19,7 @@ // GET /live/<id>/index.m3u8 everything so far; the recording once ended // GET /live/<id>/<run>-<n>.ts a segment // GET /live/<id>/stats {state, viewers, started, seconds} +// GET /live/ping (WebSocket) says pong: sockets get through // // Who may send: a coinos name's owner (its nostr key or the wallet key that // manages it), checked with the names registrar. One stream per person, @@ -221,6 +222,8 @@ export async function handle(req, server) { const url = new URL(req.url); const path = url.pathname.replace(/^\/live/, ''); if (path === '/health') return json({ ok: true, live: live().length }); + // a WebSocket that says pong: is the way in (Cloudflare, the proxies) open to sockets? + if (path === '/ping') return server.upgrade(req, { data: { ping: true } }) ? undefined : json({ error: 'websocket expected' }, 426); if (path === '/ingest') { const a = checkAuth(url); if (a.error) return json({ error: a.error }, 401); @@ -255,6 +258,7 @@ export const websocket = { idleTimeout: 60, open(ws) { const d = ws.data; + if (d.ping) { ws.send('pong'); ws.close(1000, 'pong'); return; } let s = d.resume ? streams.get(d.resume) : null; if (!s) { const id = randomBytes(8).toString('hex'); |
