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 {
  InvalidUrl
  OnOpen(WebSocket)
  OnTextMessage(String)
  OnBinaryMessage(BitArray)
  OnClose(WebSocketCloseReason)
}

Constructors

  • InvalidUrl
  • OnOpen(WebSocket)
  • OnTextMessage(String)
  • OnBinaryMessage(BitArray)
  • OnClose(WebSocketCloseReason)

Functions

pub fn close(ws ws: WebSocket) -> Effect(a)
pub fn do_get_page_url() -> String
pub fn do_get_websocket_path(
  path: String,
  page_uri: Uri,
) -> Result(String, Nil)
pub fn get_websocket_path(path: String) -> Result(String, 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. If the path given is a URL, that is used. If the path is an absolute path, host and port are taken from document.URL, and scheme will become ws for http and wss for https. If the path is a relative path, ditto, but the the path will be relative to the path from document.URL

pub fn page_uri() -> Result(Uri, Nil)
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