billstclair/elm-websocket-framework/8.1.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>"

Game and Player addition and removal

GameId
-> gamestate
-> ServerState gamestate player
-> ServerState gamestate player

Add a game to a ServerState.

Adds the game ID to the added games list in changes, so that the server code will update its tables.

PlayerId
-> PlayerInfo player
-> ServerState gamestate player
-> ServerState gamestate player

Add a player to a ServerState.

Adds the player ID to the added players list in changes, so that the server code will update its tables.

GameId
-> List PlayerId
-> ServerState gamestate player
-> ServerState gamestate player

Remove a game and its players from a ServerState.

Removes the game ID from the removed games list in changes, so that the server code will update its tables.

PlayerId
-> ServerState gamestate player
-> ServerState gamestate player

Remove a player from a ServerState.

Adds the player ID to the removed players list in changes, so that the server code will update its tables.

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.

Support for creating random game and player identifiers.

ServerState gamestate player
-> ( GameId, ServerState gamestate player )

Generate a random GameId string, ensuring that it is not already assigned to a game.

Will not be used by servers that have no concept of a game.

ServerState gamestate player
-> ( PlayerId, ServerState gamestate player )

Generate a random PlayerId string, ensuring that it is not already assigned to a player.

Will not be used by servers that have no concept of a player.

Utilities

getGame : GameId -> ServerState gamestate player -> Maybe gamestate

Look up the gamestate for a GameId

GameId
-> Maybe gamestate
-> ServerState gamestate player
-> ServerState gamestate player

Update the gamestate for a GameId.

Pass Nothing to remove the game's state.

PlayerId
-> ServerState gamestate player
-> Maybe (PlayerInfo player)

Look up the PlayerInfo for a PlayerId

PlayerId
-> Maybe (PlayerInfo player)
-> ServerState gamestate player
-> ServerState gamestate player

Update the PlyaerInfo for a PlayerId.

Pass Nothing to remove the player's info.

Errors

errorRsp : message -> String -> ErrorRsp message

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