This WebSocket Elm module lets you encode and decode messages to pass to javascript, where the actual websocket sending and receiving will take place. See the README for more.
WebSocketMsgs are responses from javascript to elm after websocket operations. The name should be the same string you used in Connect.
decode incoming messages from the websocket javascript.
encode websocket commands into json.
make a subscription function with receive and a port, like so:
port receiveSocketMsg : (JD.Value -> msg) -> Sub msg
wsreceive =
receiveSocketMsg <| WebSocket.receive WsMsgWhere WsMessage is defined in your app like this:
type Msg
= WsMsg (Result JD.Error WebSocket.WebSocketMsg)
| <other message types>then in your application subscriptions:
subscriptions =
\_ -> wsreceiveuse send to make a websocket convenience function, like so:
port sendSocketCommand : JE.Value -> Cmd msg
wssend =
WebSocket.send sendSocketCommandthen you can call (makes a Cmd):
wssend <|
WebSocket.Send
{ name = "touchpage"
, content = dta
}
WebSocketCmds go from from elm out to javascript to be processed.