← all modules

Sky.Core.WebSocket

Sky.Core.WebSocket
  Sky.Core.WebSocket — outbound WebSocket client.

Types
  type WebSocket = WebSocket Int
  type WebSocketMessage = Text String | Binary String
  type CloseCode = Normal | GoingAway | UnsupportedData | InternalError | Custom Int
  type alias WebSocketCfg

Values
  close : WebSocket -> Task Error ()
      `close sock` — release the connection (sends a Normal close
  closeWithCode : CloseCode -> String -> WebSocket -> Task Error ()
      `closeWithCode code reason sock` — release the connection with
  connect : String -> Task Error WebSocket
      `connect url` — open a new WebSocket to `url` (typically
  connectWith : WebSocketCfg -> Task Error WebSocket
      `connectWith cfg` — connect with custom headers / timeout /
  defaultCfg : String -> WebSocketCfg
      Default WebSocketCfg.  All-defaults values.  Override fields
  onClose : WebSocket -> (CloseCode -> msg) -> Sub msg
      `onClose sock toMsg` — dispatch `toMsg closeCode` when the
  onError : WebSocket -> (Error -> msg) -> Sub msg
      `onError sock toMsg` — dispatch `toMsg err` on a network /
  onMessage : WebSocket -> (WebSocketMessage -> msg) -> Sub msg
      `onMessage sock toMsg` — dispatch `toMsg event` for every
  onOpen : WebSocket -> msg -> Sub msg
      `onOpen sock msg` — dispatch `msg` once the socket is connected.
  send : WebSocket -> String -> Task Error ()
      `send sock text` — write a text frame.  Blocks up to 30 s if
  sendBinary : WebSocket -> String -> Task Error ()
      `sendBinary sock bytes` — write a binary frame.  The String
  withHeaders : List ( String, String ) -> WebSocketCfg -> WebSocketCfg
      Override the HTTP headers (e.g. Authorization) sent on the
  withPingInterval : Int -> WebSocketCfg -> WebSocketCfg
      Override the ping interval in milliseconds (default 30000).
  withTimeout : Int -> WebSocketCfg -> WebSocketCfg
      Override the handshake timeout in milliseconds (default 30000).