glen/ws
Types and functions for working with websockets. Use the glen.websocket
function to start a websocket connection from a request handler.
ℹ️ Websockets are currently only supported when using the
deno
runtime.
Types
pub type WebsocketBody
pub type WebsocketConn(event)
A websocket message represents an incoming message from the websocket client,
or a custom event sent from the server via dispatch_event
.
pub type WebsocketMessage(event) {
Text(String)
Bits(BitArray)
Event(event)
}
Constructors
-
Text(String)
Recieved a text message
-
Bits(BitArray)
Recieved a BitArray message
-
Event(event)
Recieved a custom event
Functions
pub fn dispatch_event(conn: WebsocketConn(a), event: a) -> Nil
Dispatch a custom event to the event handler. A custom event allows you to
call the websocket’s on_event
function from the server-side with a message
of ws.Event(a)
.
pub fn send_bits(
conn: WebsocketConn(a),
bits: BitArray,
) -> Result(Nil, String)
Send a BitArray to the websocket client.