Francis.Websocket (Francis v0.3.3)
View SourceHelper functions for WebSocket handlers generated by the Francis.ws/3 macro.
This module centralizes the WebSocket lifecycle logic (heartbeat, join/close events, response formatting) so that the generated per-route handler modules stay small. It is not intended for direct use by application code.
Summary
Functions
Safely calls a handler for the {:close, reason} event.
Safely calls a handler for the :join event.
Cancels the heartbeat timer during termination.
Formats a WebSocket response for the WebSock protocol.
Reschedules the heartbeat timer and returns a ping frame.
Sets up the heartbeat timer if configured.
Functions
Safely calls a handler for the {:close, reason} event.
Always returns :ok because terminate/2 ignores the return value.
If the handler doesn't pattern-match close events, silently succeeds.
Safely calls a handler for the :join event.
If the handler doesn't pattern-match :join (raises FunctionClauseError
or MatchError), silently returns {:ok, state} — join handling is optional.
Returns a WebSock-compatible response tuple so the join reply (if any) is sent.
Cancels the heartbeat timer during termination.
Formats a WebSocket response for the WebSock protocol.
Reschedules the heartbeat timer and returns a ping frame.
Sets up the heartbeat timer if configured.