← all modules

Sky.Core.WebSocket

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

Types
  type WebSocket
  type WebSocketMessage = Text String | Binary String
  type CloseCode = Normal | GoingAway | UnsupportedData | InternalError | Custom Int
  type alias WebSocketCfg = { url : String , headers : List ( String, String ) , timeout : Int , pingInterval : Int }

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
  forEachMessage : WebSocket -> (WebSocketMessage -> Task Error ()) -> Task Error ()
      `forEachMessage sock body` — run `body` on every frame, in order,
  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.
  receive : WebSocket -> Task Error (Maybe WebSocketMessage)
      `receive sock` — wait for the next frame, from a Task.
  receiveWithin : Int -> WebSocket -> Task Error (Maybe WebSocketMessage)
      `receiveWithin ms sock` — `receive`, but fail with `Err` (`Timeout`)
  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).