new Client(config)
Backgammon client
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object | Configuration object
Properties
|
Members
_callbackList :Object
Map of callback functions to be executed after server replies to a message
Type:
- Object
_clientMsgSeq :number
Counter used to generate unique sequence number for messages in client's session
Type:
- number
_msgSubscriptions :Object
Dictionary of arrays, containing subscriptions for reception of messages by id/type.
The key of the dictionary is the message ID.
The value of the dictionary is an array with callback functions to execute when message is received.
Type:
- Object
_socket :Socket
Client's socket object
Type:
- Socket
config :Object
Default client configuration
Type:
- Object
match :Match
Current match
Type:
otherPlayer :Player
Other player object
Type:
player :Player
Client's player object
Type:
rule :Rule
Rule used in current match
Type:
Methods
_notify(msg, params)
Subscribe for notification on message reception
Parameters:
Name | Type | Description |
---|---|---|
msg |
number | The ID of the message received |
params |
Object | Message parameters |
_openSocket()
Prepare socket and attach message handlers
handleConnect()
Handle connection to server.
handleCreateGuest(params)
Handle reply - Guest player created
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
params |
Object | Message parameters
Properties
|
handleCreateMatch(params)
Handle reply - New match has been created
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Message parameters |
handleEventDiceRoll(params)
Handle event - Dice rolled
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Message parameters |
handleEventGameOver(params)
Handle event - Game over. Current game is over. Prepare for next game of match, if any.
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
params |
Object | Message parameters
Properties
|
handleEventGameRestart(params)
Handle event - Game restart. Current game in match is over. Match is not finished, so start next game.
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Message parameters |
handleEventMatchOver(params)
Handle event - Match is over. Offer rematch or starting a new game.
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
params |
Object | Message parameters
Properties
|
handleEventMatchStart(params)
Handle event - Piece moved
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
params |
Object | Message parameters
Properties
|
handleEventPieceMove(params)
Handle event - Piece moved
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object | Message parameters
Properties
|
handleEventPlayerJoined(params)
Handle event - Another player joined match
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Message parameters |
handleEventTurnStart(params)
Handle event - New turn started
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Message parameters |
handleEventUndoMoves(params)
Handle event - Undo moves
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Message parameters |
handleGetMatchList(params)
Handle reply - List of matfches returned
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Message parameters |
handleJoinMatch(params)
Handle reply - Joined new match
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Message parameters |
handleMessage(msg, params)
Handle reply/event message.
Parameters:
Name | Type | Description |
---|---|---|
msg |
string | Message ID |
params |
Object | Message parameters |
handleMovePiece(params)
Handle reply - Piece moved
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Message parameters |
handlePlayRandom(params)
Handle reply - Start random match
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Message parameters |
handleRollDice(params)
Handle reply - Dice rolled
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Message parameters |
init(config)
Initialize client
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object | Configuration object
Properties
|
loadRule(ruleName) → {Rule}
Load rule module
Parameters:
Name | Type | Description |
---|---|---|
ruleName |
string | Rule's name, equal to rule's class name (eg. RuleBgCasual) |
Returns:
- Corresponding rule object
- Type
- Rule
reqConfirmMoves(callbackopt)
Confirm moves made
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
messageCallback |
<optional> |
Callback function to be called when server sends a reply |
reqCreateMatch(ruleName, callbackopt)
Request creating a new match.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ruleName |
string | Name of rule to use (eg. RuleBgCasual) | |
callback |
messageCallback |
<optional> |
Callback function to be called when server sends a reply |
reqJoinMatch(matchID, callbackopt)
Request joining a specific match.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
matchID |
number | ID of match to join | |
callback |
messageCallback |
<optional> |
Callback function to be called when server sends a reply |
reqMove(piece, steps, callbackopt)
Request moving a piece.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
piece |
Piece | Denormalized position from which a piece has to be moved | |
steps |
number | Number of steps to move forward to first home position | |
callback |
messageCallback |
<optional> |
Callback function to be called when server sends a reply |
reqPlayRandom(ruleName, paramsopt, callbackopt)
Request playing a match with random player - from waiting queue.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ruleName |
string | Name of rule to use (eg. RuleBgCasual) | |
params |
Object |
<optional> |
Object map with message parameters |
callback |
messageCallback |
<optional> |
Callback function to be called when server sends a reply |
reqRollDice(callbackopt)
Request rolling dice
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
messageCallback |
<optional> |
Callback function to be called when server sends a reply |
reqUndoMoves(callbackopt)
Undo moves made since last confirm
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
messageCallback |
<optional> |
Callback function to be called when server sends a reply |
resetBoard(match, rule)
Init game
Parameters:
Name | Type | Description |
---|---|---|
match |
Match | Game |
rule |
Rule | Rule object to use |
resizeUI()
Notify UI that DOM was rezised and UI may have to be updated
sendMessage(msg, paramsopt, callbackopt)
Send message to server.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
msg |
string | Message ID | |
params |
Object |
<optional> |
Object map with message parameters |
callback |
messageCallback |
<optional> |
Callback function to be called when server sends a reply to this message |
subscribe(msgID, callbackopt)
Subscribe for notification on message reception
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
msgID |
number | The type of message to subscribe for | |
callback |
messageCallback |
<optional> |
Callback function to be called on reception of this message |
updateMatch(match)
Update match object.
After an object has been updated, an update to UI should also be triggered.
Parameters:
Name | Type | Description |
---|---|---|
match |
Match | Updated match object to use |
updateOtherPlayer(player)
Update other player.
After an object has been updated, an update to UI should also be triggered.
Parameters:
Name | Type | Description |
---|---|---|
player |
Player | Updated other player's object to use |
updatePlayer(player)
Update player.
After an object has been updated, an update to UI should also be triggered.
Parameters:
Name | Type | Description |
---|---|---|
player |
Player | Updated player's object to use |
updateRule(rule)
Update rule object.
After an object has been updated, an update to UI should also be triggered.
Parameters:
Name | Type | Description |
---|---|---|
rule |
Rule | Updated rule object to use |
updateUI()
Trigger update of board's UI.