sprocket

Types

pub type SprocketOptions {
  SprocketOptions(cassette_opts: Option(CassetteOpts))
}

Constructors

  • SprocketOptions(cassette_opts: Option(CassetteOpts))

Functions

pub fn cleanup(ca: Subject(Message), id: String) -> Nil

Cleanup a sprocket. This function is called when a websocket is closed. It will find the sprocket that is associated with the websocket and stop it.

Its important to call this function when the websocket connection is terminated.

pub fn handle_client(
  id: String,
  ca: Subject(Message),
  view: Element,
  msg: String,
  ws_send: fn(String) -> Result(Nil, Nil),
) -> Result(Nil, Nil)

Handle a message from the websocket. This function is called when a message is received from the websocket. It will find the sprocket that is associated with the websocket and pass the message to the sprocket. The sprocket will then handle the message and send a response back to the websocket.

pub fn start(
  validate_csrf: fn(String) -> Result(Nil, Nil),
  opts: Option(SprocketOptions),
) -> Subject(Message)

Start the cassette. This function is typically called when the server starts. It will start the cassette and setup the websocket handler.

pub fn stop(ca: Subject(Message)) -> Nil

Stop the cassette. This function is typically called when the server stops. It will stop and cleanup all sprockets that are currently running.

Search Document