arizona_roadrunner_ws (arizona_roadrunner v0.1.0)
View SourceRoadrunner WebSocket handler that bridges to arizona_socket.
Translates roadrunner's split handler model (upgrade-time
roadrunner_handler + post-upgrade roadrunner_ws_handler) into the
transport-agnostic arizona_socket API:
handle/1-- theroadrunner_handlercallback. Delegates the upgrade-time handshake toarizona_ws:upgrade/3(parse_az_path/_az_reconnect, resolve the route viaarizona_roadrunner_req, run middlewares) and returns either a plain HTTP halt reply or a{websocket, ?MODULE, State}upgrade tuple.init/1-- runs once in the session process after the upgrade. Constructs the Arizona socket and starts the live process; the reconnect path can immediately reply with the rendered page.handle_frame/2-- forwards inbound text frames toarizona_socket:handle_in/2; ignores binary, ping, and pong frames.handle_info/2-- forwards mailbox messages (typically{arizona_push, ...}from the live process) toarizona_socket:handle_info/2.handle_drain/2-- fires when the listener broadcasts a drain signal (roadrunner_listener:drain/2ornotify_drain/2). Emits the drain acknowledgement and notifies the live process via{arizona_drain, Deadline}so the view can wind down gracefully (close the WS, push a reconnect indicator, etc.).
Summary
Functions
Roadrunner handle/1 callback. Resolves the route, applies
middlewares, and returns the websocket upgrade tuple.
Roadrunner handle_drain/2 callback. Emits the drain acknowledgement and
forwards an adapter-agnostic {arizona_drain, Deadline} to the live
process so the view's optional handle_drain/2 callback can run and
choose to push a "reconnecting" indicator, close the WS, or stay
alive past drain.
Roadrunner handle_frame/2 callback. Forwards text frames to the
socket; ignores binary, ping, and pong frames.
Roadrunner handle_info/2 callback. Forwards mailbox messages
(typically {arizona_push, ViewId, Ops, Effects, Observed} from the live process) to
arizona_socket:handle_info/2.
roadrunner_ws_handler init/1 callback. Builds the Arizona socket
and starts the live process. On reconnect, returns the page snapshot
as the first outbound text frame -- unless the client flagged
_az_fps_follow, in which case the socket defers the snapshot until
the client's cached_fps frame arrives so the payload dedups against
the announced fingerprints.
Functions
-spec handle(Req) -> {Response, Req} when Req :: roadrunner_req:request(), Response :: roadrunner_handler:response().
Roadrunner handle/1 callback. Resolves the route, applies
middlewares, and returns the websocket upgrade tuple.
-spec handle_drain(Deadline, State) -> Result when Deadline :: integer(), State :: map(), Result :: roadrunner_ws_handler:result().
Roadrunner handle_drain/2 callback. Emits the drain acknowledgement and
forwards an adapter-agnostic {arizona_drain, Deadline} to the live
process so the view's optional handle_drain/2 callback can run and
choose to push a "reconnecting" indicator, close the WS, or stay
alive past drain.
-spec handle_frame(Frame, State) -> Result when Frame :: roadrunner_ws:frame(), State :: map(), Result :: roadrunner_ws_handler:result().
Roadrunner handle_frame/2 callback. Forwards text frames to the
socket; ignores binary, ping, and pong frames.
-spec handle_info(Msg, State) -> Result when Msg :: term(), State :: map(), Result :: roadrunner_ws_handler:result().
Roadrunner handle_info/2 callback. Forwards mailbox messages
(typically {arizona_push, ViewId, Ops, Effects, Observed} from the live process) to
arizona_socket:handle_info/2.
-spec init(State) -> Result when State :: map(), Result :: roadrunner_ws_handler:result().
roadrunner_ws_handler init/1 callback. Builds the Arizona socket
and starts the live process. On reconnect, returns the page snapshot
as the first outbound text frame -- unless the client flagged
_az_fps_follow, in which case the socket defers the snapshot until
the client's cached_fps frame arrives so the payload dedups against
the announced fingerprints.