Skip to main content

Connection lifecycle you need to handle

  • No watch state survives a disconnect. A dropped connection (network blip, gateway task restart, app backgrounded) implicitly unwatches every device that connection was watching — there's no server-side session to resume. On every reconnect, re-send watch for everything you care about. Don't assume a reconnect picks up where you left off.
  • Server pings every ~54s; if the server hasn't seen a pong within ~60s it closes the connection (ordinary messages from your client don't count — only pongs do). Both browser WebSocket and Flutter's web_socket_channel/dart:io WebSocket answer ping frames automatically at the protocol level — you don't need to do anything for this unless your library/platform doesn't (some restrictive mobile network proxies strip WebSocket control frames; if you see mysterious ~60s disconnects, that's the first thing to check).
  • Keep up with the stream. Each connection has a 32-message outbound buffer; a client that falls further behind than that has messages dropped (not queued), and a single frame your client can't accept within 10 seconds closes the connection.
  • Deploys close connections. On shutdown the gateway sends a normal close (code 1000, reason server shutting down) and exits a few seconds later; at the dev tier a redeploy then leaves the port unbound briefly while the new task starts. Treat this like any other disconnect.
  • No reconnection is done for you. Implement your own retry with backoff (examples below do this).