internal/transports/websocket

Types

pub type WebSocket
pub type WebSocketCloseReason {
  Normal(code: Int, reason: String)
  GoingAway(code: Int, reason: String)
  ProtocolError(code: Int, reason: String)
  UnexpectedTypeOfData(code: Int, reason: String)
  NoCodeFromServer(code: Int, reason: String)
  AbnormalClose(code: Int, reason: String)
  IncomprehensibleFrame(code: Int, reason: String)
  PolicyViolated(code: Int, reason: String)
  MessageTooBig(code: Int, reason: String)
  FailedExtensionNegotation(code: Int, reason: String)
  UnexpectedFailure(code: Int, reason: String)
  ServiceRestart(code: Int, reason: String)
  TryAgainLater(code: Int, reason: String)
  BadGateway(code: Int, reason: String)
  FailedTLSHandshake(code: Int, reason: String)
  OtherCloseReason(code: Int, reason: String)
}

Constructors

  • Normal(code: Int, reason: String)
  • GoingAway(code: Int, reason: String)
  • ProtocolError(code: Int, reason: String)
  • UnexpectedTypeOfData(code: Int, reason: String)
  • NoCodeFromServer(code: Int, reason: String)
  • AbnormalClose(code: Int, reason: String)
  • IncomprehensibleFrame(code: Int, reason: String)
  • PolicyViolated(code: Int, reason: String)
  • MessageTooBig(code: Int, reason: String)
  • FailedExtensionNegotation(code: Int, reason: String)
  • UnexpectedFailure(code: Int, reason: String)
  • ServiceRestart(code: Int, reason: String)
  • TryAgainLater(code: Int, reason: String)
  • BadGateway(code: Int, reason: String)
  • FailedTLSHandshake(code: Int, reason: String)
  • OtherCloseReason(code: Int, reason: String)
pub type WebSocketError {
  InvalidUrl(message: String)
  UnsupportedEnvironment(message: String)
}

Constructors

  • InvalidUrl(message: String)
  • UnsupportedEnvironment(message: String)
pub type WebSocketEvent {
  OnOpen(WebSocket)
  OnTextMessage(String)
  OnBinaryMessage(BitArray)
  OnClose(WebSocketCloseReason)
}

Constructors

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

Functions

pub fn close(ws ws: WebSocket) -> Nil
pub fn init(path: String) -> Result(WebSocket, WebSocketError)

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 listen(
  ws: WebSocket,
  on_open on_open: fn(WebSocket) -> Nil,
  on_text_message on_text_message: fn(String) -> Nil,
  on_close on_close: fn(WebSocketCloseReason) -> Nil,
) -> Nil
pub fn send(ws ws: WebSocket, msg msg: String) -> Nil
Search Document