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.


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)

    Recieved a text message

  • Bits(BitArray)

    Recieved a BitArray message

  • Event(event)

    Recieved a custom event


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.

pub fn send_text(
  conn: WebsocketConn(a),
  text: String,
) -> Result(Nil, String)

Send text to the websocket client.

Search Document