Documentation
¶
Overview ¶
Package websocket adapts realtime.Coordinator to an HTTP WebSocket upgrade, wrapping github.com/coder/websocket. No coder/websocket type appears in this package's own public API — see this milestone's ADR on wrapping third-party dependencies behind a translated contract.
Index ¶
Constants ¶
const DefaultMaxMessageSize = 32 * 1024
DefaultMaxMessageSize bounds one inbound WebSocket message. It matches coder/websocket's own default, so View's behavior is explicit rather than an unstated inherited default.
Variables ¶
This section is empty.
Functions ¶
func View ¶
func View(coordinator realtime.Coordinator, authenticate Authenticate, roomID func(*tango.Context) (string, error)) tango.View
View upgrades an authenticated request to a WebSocket connection and runs it against coordinator until the connection ends. Mount it as an ordinary route, e.g. tango.Path("GET", "/rooms/{id}/ws", View(hub, authenticate, roomIDFromPath)).
authenticate runs before the upgrade is attempted: a failure responds with a plain JSON 401 and never touches the WebSocket handshake. roomID is resolved the same way, before upgrading, so a bad room reference fails as an ordinary HTTP 400 rather than an upgraded connection that immediately closes.
Join is called, and must return successfully, before View starts reading any client message — a message sent immediately after the socket opens must never race ahead of the room loop's own membership-apply. This is exactly why realtime.Hub.Join is synchronous.
Types ¶
type Authenticate ¶
Authenticate resolves the requesting Principal from a plain HTTP request, before any WebSocket upgrade is attempted. It may use auth/jwt (see jwt.Service.Verify, called directly — not via jwt.Service.Middleware, since that targets ordinary HTTP routes), a cookie session, or anything else; this package never imports auth, auth/jwt, or accounts.