WebSocket.
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.
responses from javascript after websocket operations. The name is the one you have the socket 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
}
messages going out from Elm to be processed in javascript. name: You should give each websocket connection a unique name. address: is the websocket address, for instance "ws://127.0.0.1:9000". protocol: is an extra string to help the server know what kind of data to expect, like if your server handled json or binary data. Probably you can pass it "".