lustre_websocket

Types

pub type WebSocket
pub type WebSocketCloseReason {
  Normal
  GoingAway
  ProtocolError
  UnexpectedTypeOfData
  NoCodeFromServer
  AbnormalClose
  IncomprehensibleFrame
  PolicyViolated
  MessageTooBig
  FailedExtensionNegotation
  UnexpectedFailure
  FailedTLSHandshake
  OtherCloseReason
}

Constructors

  • Normal
  • GoingAway
  • ProtocolError
  • UnexpectedTypeOfData
  • NoCodeFromServer
  • AbnormalClose
  • IncomprehensibleFrame
  • PolicyViolated
  • MessageTooBig
  • FailedExtensionNegotation
  • UnexpectedFailure
  • FailedTLSHandshake
  • OtherCloseReason
pub type WebSocketEvent {
  OnOpen(WebSocket)
  OnMessage(String)
  OnClose(WebSocketCloseReason)
}

Constructors

  • OnOpen(WebSocket)
  • OnMessage(String)
  • OnClose(WebSocketCloseReason)

Functions

pub fn close(ws ws: WebSocket) -> Nil
pub fn init(
  path: String,
  wrapper: fn(WebSocketEvent) -> a,
) -> Effect(a)

Initialize a websocket. These constructs are fully asynchronous, so you must provide a wrapper that takes a WebSocketEvent and turns it into a lustre message of your application.

pub fn send(ws: WebSocket, msg: String) -> Effect(a)

Send a text message over the web socket. This is asynchronous. There is no expectation of a reply. See init. Only works on an Non-Closed socket. Returns a Effect(a) that you must pass as second entry in the lustre update return.

Search Document