billstclair/elm-websocket-framework/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

WebSocketFramework.ServerInterface

Functions that connect the client code to the server.

Server Constructors

MessageEncoder message
-> ServerUrl
-> msg
-> ServerInterface gamestate player message msg

Make a client connection to a real WebSocket server.

The msg will usually be a no-operation message. It is only used to fill a slot in the returned ServerInterface. That slot is only used by the proxy server.

ServerMessageProcessor gamestate player message
-> (ServerInterface gamestate player message msg -> message -> msg)
-> ServerInterface gamestate player message msg

Make a client connection to a proxy server.

No WebSocket connection will be used to send messages.

EncodeDecode message
-> ServerMessageProcessor gamestate player message
-> ServerMessageProcessor gamestate player message

Simulate a round-trip through the message encoder, decoder, and message processor.

Returns a function that takes a request message, encodes it, decodes it, processes it into a response, encodes and decodes that, then returns the result.

Usually passed as the first arg to makeProxyServer.

Sending a Message

send : ServerInterface gamestate player message msg -> message -> Cmd msg

Return a Cmd to send a message through a server interface.

State Access

getServer : ServerInterface gamestate player message msg -> ServerUrl

Return the server URL from inside a ServerInterface.

GameId and PlayerId validity checking

ServerState gamestate player
-> message
-> GameId
-> Result (ErrorRsp message) gamestate

Check that the passed GameId is in the ServerState's game dict.

If it is, return the gamestate. Otherwise wrap the message in an ErrorRsp.

ModeChecker gamestate message
-> ServerState gamestate player
-> message
-> GameId
-> Result (ErrorRsp message) gamestate

Check that the passed GameId is in the ServerState's game dict and that it satisifed the ModeChecker.

If it does, return the gamestate. Otherwise wrap the message in an ErrorRsp.

ServerState gamestate player
-> message
-> PlayerId
-> Result (ErrorRsp message) (PlayerInfo player)

Check that the passed PlayerId is in the ServerState's player dict.

If it is, return the PlayerInfo record for the player.

Otherwise wrap the message in an ErrorRsp.

dummyGameid : GameId

"<gameid>"

Public Games

appendPublicGames : PublicGame -> PublicGames -> PublicGames

Push a PublicGame onto a list of them.

removePublicGame : GameId -> PublicGames -> PublicGames

Remove the PublicGame with the given GameId from a list of games.

Errors

errorRsp : message -> String -> ErrorRsp message

Create the ErrorRsp record returned in the errors from CheckOnlyGameid, checkGameid, and checkPlayerid.