Francis.Websocket (Francis v0.3.2)

View Source

Helper 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

call_close(handler, event, state)

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.

call_join(handler, state)

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.

cancel_heartbeat(state)

Cancels the heartbeat timer during termination.

format_response(arg1, state)

Formats a WebSocket response for the WebSock protocol.

handle_heartbeat(state)

Reschedules the heartbeat timer and returns a ping frame.

setup_heartbeat(state)

Sets up the heartbeat timer if configured.