billstclair/elm-websocket-framework/3.1.0

NOTE: this package is not compatible with Elm 0.19.1

WebSocketFramework.Types

Types used by the rest of the WebSocketFramework modules.

State

type alias ServerState gamestate player =
{ gameDict : Dict GameId gamestate
, playerDict : Dict PlayerId (PlayerInfo player)
, publicGames : PublicGames
, state : Maybe gamestate
}

The part of the server state that is independent from its socket connections.

You might think that the names are per game, and you'd be right to think that. They're not in the GameState, because they don't need to go over the wire, except in the JoinRsp.

They're stored in a Dict in the Server model.

type ServerInterface gamestate player message msg
= ServerInterface
{ server : ServerUrl
, wrapper :
ServerInterface gamestate player message msg -> message -> msg
, state : Maybe (ServerState gamestate player)
, sender :
ServerInterface gamestate player message msg -> message -> Cmd msg
}

Everything necessary to communicate with a server, be it real or proxy.

type alias PlayerInfo player =
{ gameid : GameId
, player : player
}

Information about a player in a game

type alias PublicGame =
{ gameid : GameId
, playerName : String
}

If your server supports public games, this represents the game id and name of the creator of the game.

type alias PublicGames =
List PublicGame

A list of pubic games.

Empty states

emptyServerState : Maybe gamestate -> ServerState gamestate player

Create a mostly empty ServerState.

emptyPublicGames : PublicGames

An empty list of public games.

Messages

type alias RawMessage =
{ reqrsp : String
, msg : String
, plist : Plist
}

A raw request, ready to be encoded to go over the wire.

reqrsp is "req" or "rsp" for request or response.

msg is the name of the message.

plist is the parameters of the message.

type ReqRsp
= Req String
| Rsp String

A type safe representation of the reqrsp and msg fields of a RawMessage.

type alias Plist =
List ( String, Value )

A list of key/value pairs.

type alias ErrorRsp message =
{ request : message
, text : String
}

An error response that encapsulates a request message and an error string.

Function Signatures

type alias ServerMessageProcessor gamestate player message =
ServerState gamestate player
-> message
-> ( ServerState gamestate player, Maybe message )

Type signature of a function which turns a server state and a request message into a ServerState and maybe a response message.

type alias MessageToGameid message =
message -> Maybe GameId

Type signature of a function that extracts the game id from a message, if it has one.

type alias ModeChecker gamestate message =
gamestate -> message -> Result String Never

Type signature of a function that checks if a message is a legal request for a gamestate.

An Err result has a message string. An Ok result maps an unusable value.

Message Encoding/Decoding

type alias MessageDecoder message =
( ReqRsp, Plist ) -> Result String message

Type signature for a function that turns a request or response and a key/value list into a message.

type alias MessageEncoder message =
message -> ( ReqRsp, Plist )

Type signature for a function that turns a message into request or response and a key/value list.

type alias EncodeDecode message =
{ encoder : MessageEncoder message
, decoder : MessageDecoder message
, errorWrapper : Maybe (String -> message)
}

Wrapping of encoder, decoder, and error message creator.

type alias DecoderPlist msg =
List ( String, Decoder msg )

Map a list of request or response names to decoders for their messages.

Utility

printifyString : String -> String

Convert ASCII double-quote characters to curly end quotes.

Server Ports

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

The input port from the Node.js code to the WebSocket server.

type alias OutputPort msg =
Value -> Cmd msg

The output port from the WebSocket server to the Node.js code.

Aliases

type alias GameId =
String

An alias for String.

type alias PlayerId =
String

An alias for String.

type alias ServerUrl =
String

An alias for String.