gleam/http/cowboy_websockets

Types

pub external type CowboyRequest
pub type Frame {
  Text(String)
  Binary(BitString)
  Close(close_code: Int, reason: String)
  Ping
  Pong
}

Constructors

  • Text(String)
  • Binary(BitString)
  • Close(close_code: Int, reason: String)
  • Ping
  • Pong
pub type FrameResponse(state) {
  Ignore(state)
  Respond(Frame, state)
  MultiRespond(List(Frame), state)
}

Constructors

  • Ignore(state)
  • Respond(Frame, state)
  • MultiRespond(List(Frame), state)

Response returned from a websocket service. The response can either be a normal HTTP response OR it can be a directive to upgrade to a persistant websocket connection with the initial state for the socket

pub type WSResponse(out, state) {
  Upgrade(state)
  Normal(Response(out))
}

Constructors

  • Upgrade(state)
  • Normal(Response(out))
pub type WSService(in, out, state) =
  fn(Request(in)) -> WSResponse(out, state)

Functions

pub fn start(service: fn(Request(BitString)) ->
    WSResponse(BitBuilder, a), on_ws_init init: fn(a) ->
    FrameResponse(a), on_ws_frame frame: fn(a, Frame) ->
    FrameResponse(a), on_info info: fn(a, Dynamic) ->
    FrameResponse(a), on_port number: Int) -> Result(
  Sender(b),
  StartError,
)
pub fn ws_service_to_handler(service: fn(Request(BitString)) ->
    WSResponse(BitBuilder, a)) -> fn(CowboyRequest) -> Dynamic