Class: Client

Client

new Client(config)

Backgammon client
Parameters:
Name Type Description
config Object Configuration object
Properties
Name Type Description
containerID string ID of HTML container tag (defaults to 'backgammon')
boardID string ID of board tag (defaults to 'board')
rulePath string path to rules directory, relative to lib directory (defaults to './rules/')
boardUI string board UI filename, relative to project root (defaults to '../app/browser/js/SimpleBoardUI.js')
Source:

Members

_callbackList :Object

Map of callback functions to be executed after server replies to a message
Type:
  • Object
Source:

_clientMsgSeq :number

Counter used to generate unique sequence number for messages in client's session
Type:
  • number
Source:

_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
Source:

_socket :Socket

Client's socket object
Type:
  • Socket
Source:

config :Object

Default client configuration
Type:
  • Object
Source:

match :Match

Current match
Type:
Source:

otherPlayer :Player

Other player object
Type:
Source:

player :Player

Client's player object
Type:
Source:

rule :Rule

Rule used in current match
Type:
Source:

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
Source:

_openSocket()

Prepare socket and attach message handlers
Source:

handleConnect()

Handle connection to server.
Source:

handleCreateGuest(params)

Handle reply - Guest player created
Parameters:
Name Type Description
params Object Message parameters
Properties
Name Type Description
player Player Player object created
Source:

handleCreateMatch(params)

Handle reply - New match has been created
Parameters:
Name Type Description
params Object Message parameters
Source:

handleEventDiceRoll(params)

Handle event - Dice rolled
Parameters:
Name Type Description
params Object Message parameters
Source:

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
Name Type Description
match number Match that has been started
Source:

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
Source:

handleEventMatchOver(params)

Handle event - Match is over. Offer rematch or starting a new game.
Parameters:
Name Type Description
params Object Message parameters
Properties
Name Type Description
match number Match that has been started
Source:

handleEventMatchStart(params)

Handle event - Piece moved
Parameters:
Name Type Description
params Object Message parameters
Properties
Name Type Description
match number Match that has been started
Source:

handleEventPieceMove(params)

Handle event - Piece moved
Parameters:
Name Type Description
params Object Message parameters
Properties
Name Type Description
position number Position of piece being moved
type PieceType Type of piece being moved
steps number Number steps the piece is moved with
moveActionList Array.<MoveAction> List of actions that have to be played in UI
Source:

handleEventPlayerJoined(params)

Handle event - Another player joined match
Parameters:
Name Type Description
params Object Message parameters
Source:

handleEventTurnStart(params)

Handle event - New turn started
Parameters:
Name Type Description
params Object Message parameters
Source:

handleEventUndoMoves(params)

Handle event - Undo moves
Parameters:
Name Type Description
params Object Message parameters
Source:

handleGetMatchList(params)

Handle reply - List of matfches returned
Parameters:
Name Type Description
params Object Message parameters
Source:

handleJoinMatch(params)

Handle reply - Joined new match
Parameters:
Name Type Description
params Object Message parameters
Source:

handleMessage(msg, params)

Handle reply/event message.
Parameters:
Name Type Description
msg string Message ID
params Object Message parameters
Source:

handleMovePiece(params)

Handle reply - Piece moved
Parameters:
Name Type Description
params Object Message parameters
Source:

handlePlayRandom(params)

Handle reply - Start random match
Parameters:
Name Type Description
params Object Message parameters
Source:

handleRollDice(params)

Handle reply - Dice rolled
Parameters:
Name Type Description
params Object Message parameters
Source:

init(config)

Initialize client
Parameters:
Name Type Description
config Object Configuration object
Properties
Name Type Description
containerID string ID of HTML container tag (defaults to 'backgammon')
boardID string ID of board tag (defaults to 'board')
rulePath string path to rules directory, relative to lib directory (defaults to './rules/')
boardUI string board UI filename, relative to project root (defaults to '../app/browser/js/SimpleBoardUI.js')
Source:

loadRule(ruleName) → {Rule}

Load rule module
Parameters:
Name Type Description
ruleName string Rule's name, equal to rule's class name (eg. RuleBgCasual)
Source:
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
Source:

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
Source:

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
Source:

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
Source:

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
Source:

reqRollDice(callbackopt)

Request rolling dice
Parameters:
Name Type Attributes Description
callback messageCallback <optional>
Callback function to be called when server sends a reply
Source:

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
Source:

resetBoard(match, rule)

Init game
Parameters:
Name Type Description
match Match Game
rule Rule Rule object to use
Source:

resizeUI()

Notify UI that DOM was rezised and UI may have to be updated
Source:

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
Source:

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
Source:

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
Source:

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
Source:

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
Source:

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
Source:

updateUI()

Trigger update of board's UI.
Source: