WebSocketLifecycleEventReceiver¶
WebSocket lifecycle callbacks delivered to the connection actor.
All callbacks have default no-op implementations. Override only the
callbacks your actor needs. For most servers, on_text_message() or
on_binary_message() is the main callback — it delivers complete,
reassembled messages after all fragments are received and validated.
Override on_upgrade_request() to inspect the HTTP upgrade request
before accepting the connection (e.g., checking the URI path or
Origin header). Return false to reject with 403 Forbidden.
Callbacks are invoked synchronously inside the actor that owns the
WebSocketServer. The protocol class handles framing, masking,
fragmentation, and the close handshake internally, delivering only
application-level events through this interface.
Public Functions¶
on_upgrade_request¶
Called when a valid upgrade request is received, before the connection is accepted.
Return true to accept (sends 101 Switching Protocols) or false
to reject (sends 403 Forbidden and closes TCP). The default
implementation accepts all connections.
Parameters¶
- request: UpgradeRequest val
Returns¶
- Bool val
on_open¶
Called after the WebSocket handshake completes successfully.
Parameters¶
- request: UpgradeRequest val
Returns¶
- None val
on_text_message¶
Called when a complete text message is received.
Parameters¶
- data: String val
Returns¶
- None val
on_binary_message¶
Called when a complete binary message is received.
Parameters¶
Returns¶
- None val
on_closed¶
Called when the WebSocket connection closes.
close_status indicates why the connection closed — a named primitive
for standard codes (e.g., CloseNormal), CloseNoStatusReceived when
the close frame had no payload, CloseAbnormalClosure when TCP dropped
without a close handshake, or OtherCloseCode for application-defined
or IANA-registered codes without named primitives.
close_reason is the UTF-8 reason string from the close frame, or
empty when no reason was provided or the close was abnormal.
fun ref on_closed(
close_status: (CloseNormal val | CloseGoingAway val | CloseProtocolError val |
CloseUnsupportedData val | CloseInvalidPayload val | ClosePolicyViolation val |
CloseMessageTooBig val | CloseInternalError val | CloseNoStatusReceived val |
CloseAbnormalClosure val | OtherCloseCode val),
close_reason: String val)
: None val
Parameters¶
- close_status: (CloseNormal val | CloseGoingAway val | CloseProtocolError val | CloseUnsupportedData val | CloseInvalidPayload val | ClosePolicyViolation val | CloseMessageTooBig val | CloseInternalError val | CloseNoStatusReceived val | CloseAbnormalClosure val | OtherCloseCode val)
- close_reason: String val
Returns¶
- None val
on_throttled¶
Called when backpressure is applied on the connection.
Returns¶
- None val
on_unthrottled¶
Called when backpressure is released on the connection.
Returns¶
- None val