Skip to content

Display rules

Find your camera in the snapshot’s devices by ID, then check in this order:

  1. Your ID is not there → “Camera deleted”.
  2. program or preview is null → Unknown. Unknown is not Off; never show it as Off.
  3. program is true → Program (red; if both are true, show Program).
  4. preview is true → Preview (green).
  5. Both false → Off.
function tallyOf(snapshot, deviceId) {
const device = snapshot.devices.find((d) => d.id === deviceId)
if (!device) return 'deleted'
if (device.program === null || device.preview === null) return 'unknown'
if (device.program) return 'program'
if (device.preview) return 'preview'
return 'off'
}

While the switcher is not ready, the server sends null for every camera, so the client needs no extra check. To show the reason, read source.state (connecting, ready, disconnected) and source.error.

  • On a disconnect, timeout or error, show Unknown at once; never keep the last colour.
  • Each reconnect brings a full snapshot; replace the old state with it.
  • After a server restart the old rev no longer matches, so /poll/v1 returns a new snapshot at once.
  • Ignore unknown fields and unknown message types.
  • Within v1, fields are only added, never removed or changed in meaning. Removals or changes will come as a new version (/ws/v2, /poll/v2), and the old version stays until all clients have upgraded.