kageurufu/elm-websockets/1.0.1

Websockets

Simple interfaces for getting started with Websockets in Elm

Other modules are exposed for advanced usage.

Defining your Ports

{ command : CommandPort msg
, event : EventPort msg
}
-> Methods msg

Helper to wrap your Ports

type alias CommandPort msg =
Value -> Cmd msg

Port to send Commands to the Websocket

type alias EventPort msg =
(Value -> msg) -> Sub msg

Port for subscribing to income events

type alias Methods msg =
{ open : String -> String -> List ( String, Maybe String ) -> Cmd msg
, close : String -> Cmd msg
, send : String -> Value -> Cmd msg
, onEvent : EventHandlers msg -> Sub msg
}

Methods for using your sockets

Event data received from your Sockets

type alias EventHandlers msg =
{ onOpened : WebsocketOpened -> msg
, onClosed : WebsocketClosed -> msg
, onError : WebsocketError -> msg
, onMessage : WebsocketMessage -> msg
, onDecodeError : String -> msg
}

Event handlers for subscriptions

type alias WebsocketOpened =
{ name : Name
, meta : Meta
}

Record data when a socket is Opened

type alias WebsocketMessage =
{ name : Name
, meta : Meta
, data : String
}

Record data when a socket is Message

type alias WebsocketClosed =
{ name : Name
, meta : Meta
, reason : String
}

Record data when a socket is Closed

type alias WebsocketError =
{ name : Name
, meta : Meta
, error : Maybe String
}

Record data when a socket is Error