Constructor

GameManager

new GameManager(config)

Used to determine who is connected to the receiver, who is ready to play, and who is playing the game on the receiver.

Parameter

config

cast.receiver.games.GameManagerConfig

Value must not be null.

Implements
cast.receiver.games.GameManagerListener

Properties

onGameDataChanged

Fired when the game manager receives a request that changes game data (e.g. cast.receiver.games.GameManagerReceiverClient.sendGameDataRequest). Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onGameDataChanged

onGameLoading

Fired when the game manager receives a request that changes gameplay state to cast.receiver.games.GameplayState.LOADING. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onGameLoading

onGameMessageReceived

Fired when the game manager receives a game message (e.g. from cast.receiver.games.GameManagerReceiverClient.sendGameMessage). Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onGameMessageReceived

onGamePaused

Fired when the game manager receives a request that changes gameplay state to cast.receiver.games.GameplayState.PAUSED. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onGamePaused

onGameRunning

Fired when the game manager receives a request that changes gameplay state to cast.receiver.games.GameplayState.RUNNING. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onGameRunning

onGameShowingInfoScreen

Fired when the game manager receives a request that changes gameplay state to cast.receiver.games.GameplayState.SHOWING_INFO_SCREEN. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onGameShowingInfoScreen

onGameStatusTextChanged

Fired when the game manager receives a request that changes game status text. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onGameStatusTextChanged

onLobbyClosed

Fired when the game manager receives a request that changes lobby state to cast.receiver.games.LobbyState.CLOSED. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onLobbyClosed

onLobbyOpen

Fired when the game manager receives a request that changes lobby state to cast.receiver.games.LobbyState.OPEN. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onLobbyOpen

onPlayerAvailable

Fired when the game manager receives a request that changes player state to cast.receiver.games.PlayerState.AVAILABLE. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onPlayerAvailable

onPlayerDataChanged

Fired when the game manager receives a request that changes player data (e.g. cast.receiver.games.GameManagerReceiverClient.sendPlayerDataRequest). Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onPlayerDataChanged

onPlayerDropped

Fired when the game manager receives a request that changes player state to cast.receiver.games.PlayerState.DROPPED. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onPlayerDropped

onPlayerIdle

Fired when the game manager receives a request that changes player state to cast.receiver.games.PlayerState.IDLE. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onPlayerIdle

onPlayerPlaying

Fired when the game manager receives a request that changes player state to cast.receiver.games.PlayerState.PLAYING. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onPlayerPlaying

onPlayerQuit

Fired when the game manager receives a request that changes player state to cast.receiver.games.PlayerState.QUIT. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onPlayerQuit

onPlayerReady

Fired when the game manager receives a request that changes player state to cast.receiver.games.PlayerState.READY. Replacing this callback can provide application-specific behavior.

Parameter

event

Value must not be null.

Implements
cast.receiver.games.GameManagerListener#onPlayerReady

Methods

addEventListener

addEventListener(type, listener)

Adds an event listener.

Parameter

type

cast.receiver.games.EventType

The type of event to listen for.

listener

function(non-null cast.receiver.games.Event)

The event listener.

addGameManagerListener

addGameManagerListener(listener)

Adds a listener for all of the game manager events. The listener object will be used as the scope of any triggered callback methods.

Parameter

listener

cast.receiver.games.GameManagerListener

Value must not be null.

broadcastGameManagerStatus

broadcastGameManagerStatus(exceptSenderId)

Sends the current game manager status to all connected senders.

Parameter

exceptSenderId

string

If not null, skip this sender ID when sending the response.

Value may be null.

getApplicationName

getApplicationName() returns string

Returns

string The application name as defined in the cast.receiver.games.GameManagerConfig passed in via the constructor.

getConnectedPlayers

getConnectedPlayers(opt_result) returns Array of non-null cast.receiver.games.PlayerInfo

Returns a list of all players in a connected state. A player is considered to be in a connected state if the associated cast.receiver.games.PlayerInfo#playerState is one of cast.receiver.games.PlayerState.IDLE, cast.receiver.games.PlayerState.AVAILABLE, cast.receiver.games.PlayerState.PLAYING or cast.receiver.games.PlayerState.READY.

Parameter

opt_result

Optional

Array of non-null cast.receiver.games.PlayerInfo

An optional re-usable array object to hold players. If not provided, a new array object will be allocated and returned.

Value must not be null.

Returns

non-null Array of non-null cast.receiver.games.PlayerInfo The list of players.

getGameData

getGameData() returns Object

Returns

Object The game specific JSON serializable data that is automatically returned with every response message.

getGameplayState

getGameplayState() returns cast.receiver.games.GameplayState

Returns

cast.receiver.games.GameplayState The current gameplay state.

getGameStatusText

getGameStatusText() returns string

Returns

string Human readable string representing the current game status.

getLobbyState

getLobbyState() returns cast.receiver.games.LobbyState

Returns

cast.receiver.games.LobbyState The current lobby state.

getMaxPlayers

getMaxPlayers() returns number

Returns

number The maximum number of players as defined in the cast.receiver.games.GameManagerConfig passed in via the constructor.

getPlayer

getPlayer(playerId) returns cast.receiver.games.PlayerInfo

Gets a specific player with a given player ID.

Parameter

playerId

string

The player ID of the player.

Returns

cast.receiver.games.PlayerInfo The player or null if the player ID was not found.

getPlayerIdsWithSenderId

getPlayerIdsWithSenderId(senderId, opt_result) returns Array of string

Gets player IDs associated with a given sender ID.

Parameter

senderId

string

The sender ID of the player.

opt_result

Optional

Array of string

An optional re-usable array object to hold the player IDs. If not provided, a new array object will be allocated and returned.

Value must not be null.

Returns

non-null Array of string The player IDs or an empty array if sender ID is not found.

getPlayers

getPlayers(opt_result) returns Array of non-null cast.receiver.games.PlayerInfo

Returns a list of all players. This list includes players in non-connected states like cast.receiver.games.PlayerState.DROPPED, cast.receiver.games.PlayerState.QUIT and cast.receiver.games.PlayerState.UNKNOWN.

Also see cast.receiver.games.GameManager#getConnectedPlayers

Parameter

opt_result

Optional

Array of non-null cast.receiver.games.PlayerInfo

An optional re-usable array object to hold players. If not provided, a new array object will be allocated and returned.

Value must not be null.

Returns

non-null Array of non-null cast.receiver.games.PlayerInfo The list of players.

getPlayersInState

getPlayersInState(state, opt_array) returns Array of non-null cast.receiver.games.PlayerInfo

Returns a list of players in the provided state.

Parameter

state

cast.receiver.games.PlayerState

The state to find players in.

Value must not be null.

opt_array

Optional

Array of non-null cast.receiver.games.PlayerInfo

An optional array object to be reused. If not provided a new array object will be allocated and returned.

Value must not be null.

Returns

non-null Array of non-null cast.receiver.games.PlayerInfo The list of players in that state.

getSenderIdWithPlayerId

getSenderIdWithPlayerId(playerId) returns string

Gets the sender ID with a given player ID.

Parameter

playerId

string

The player ID of the player.

Returns

nullable string The sender ID or null if player ID is not found.

isPlayerConnected

isPlayerConnected(playerId) returns boolean

Returns whether a player is in a connected state. A player is considered to be in a connected state if the associated cast.receiver.games.PlayerInfo#playerState is one of cast.receiver.games.PlayerState.IDLE, cast.receiver.games.PlayerState.AVAILABLE, cast.receiver.games.PlayerState.PLAYING or cast.receiver.games.PlayerState.READY.

Parameter

playerId

string

The playerId to check.

Returns

boolean Whether the player is connected or not.

removeEventListener

removeEventListener(type, listener)

Removes an event listener.

Parameter

type

cast.receiver.games.EventType

The type of event to listen for.

listener

function(non-null cast.receiver.games.Event)

The event listener.

removeGameManagerListener

removeGameManagerListener(listener)

Removes a listener for all of the game manager events.

Parameter

listener

cast.receiver.games.GameManagerListener

Value must not be null.

sendGameMessageToAllConnectedPlayers

sendGameMessageToAllConnectedPlayers(message)

Sends a game message to all connected players. A player is considered to be in a connected state if the associated cast.receiver.games.PlayerInfo#playerState is one of cast.receiver.games.PlayerState.IDLE, cast.receiver.games.PlayerState.AVAILABLE, cast.receiver.games.PlayerState.PLAYING or cast.receiver.games.PlayerState.READY.

Parameter

message

Object

A JSON serializable object that will be sent to the connected players.

sendGameMessageToPlayer

sendGameMessageToPlayer(playerId, message)

Sends a game message to a specific player.

Parameter

playerId

string

The ID of the player.

message

Object

A JSON serializable object that will be sent to the specified player.

sendGameMessageToPlayers

sendGameMessageToPlayers(playerIds, message)

Sends a game message to multiple players.

Parameter

playerIds

Array of string

The ID of the players.

Value must not be null.

message

Object

A JSON serializable object that will be sent to the specified players.

simulateGameMessageFromPlayer

simulateGameMessageFromPlayer(playerId, message, opt_noBroadcastUpdate) returns cast.receiver.games.GameManagerResult

Simulates how a player sends a game message to the game manager via a sender. Useful for testing. This can trigger events and callbacks related to game messages (for example, cast.receiver.games.EventType.GAME_MESSAGE_RECEIVED).

Parameter

playerId

string

The player ID of the player sending the message.

message

Object

A JSON serializable object. This will be passed to event handlers on this game manager as the cast.receiver.games.Event#requestExtraMessageData field of the cast.receiver.games.Event object.

opt_noBroadcastUpdate

Optional

boolean

If set to true, this disables broadcasting an update to all senders and the caller is responsible for calling cast.receiver.games.GameManager.broadcastGameManagerStatus. By default, an update is always broadcasted.

Returns

non-null cast.receiver.games.GameManagerResult The result of the operation. Do not maintain a reference to this object as it may be reused for the next operation performed on the game manager.

updateGameData

updateGameData(gameData, opt_noBroadcastUpdate) returns cast.receiver.games.GameManagerResult

Updates game specific data that is stored while the game is running. Every response from the game manager to senders will include this game data. This can trigger events and callbacks related to game data changes (e.g. cast.receiver.games.EventType.GAME_DATA_CHANGED).

Parameter

gameData

Object

The JSON serializable game data.

opt_noBroadcastUpdate

Optional

boolean

If set to true, this disables broadcasting an update to all senders and the caller is responsible for calling cast.receiver.games.GameManager.broadcastGameManagerStatus. By default, an update is always broadcasted.

Returns

non-null cast.receiver.games.GameManagerResult The result of the operation. Do not maintain a reference to this object as it may be reused for the next operation performed on the game manager.

updateGameplayState

updateGameplayState(gameplayState, extraMessageData, opt_noBroadcastUpdate) returns cast.receiver.games.GameManagerResult

Updates the gameplay state on the game manager. This can trigger events and callbacks related to gameplay state changes (for example, cast.receiver.games.EventType.GAME_LOADING).

Parameter

gameplayState

cast.receiver.games.GameplayState

The new gameplay state.

extraMessageData

Object

An optional JSON serializable object. This will be passed to event handlers on this game manager as the cast.receiver.games.Event#requestExtraMessageData field of the cast.receiver.games.Event object.

opt_noBroadcastUpdate

Optional

boolean

If set to true, this disables broadcasting an update to all senders and the caller is responsible for calling cast.receiver.games.GameManager.broadcastGameManagerStatus. By default, an update is always broadcasted.

Returns

non-null cast.receiver.games.GameManagerResult The result of the operation. Do not maintain a reference to this object as it may be reused for the next operation performed on the game manager.

updateGameStatusText

updateGameStatusText(gameStatusText, opt_noBroadcastUpdate) returns cast.receiver.games.GameManagerResult

Updates the game status text that is stored while the game is running. Every response from the game manager to senders will include this game status text. This can trigger events and callbacks related to game status text changes (e.g. cast.receiver.games.EventType.GAME_STATUS_TEXT_CHANGED).

Parameter

gameStatusText

string

Human readable string representing the current game status.

opt_noBroadcastUpdate

Optional

boolean

If set to true, this disables broadcasting an update to all senders and the caller is responsible for calling cast.receiver.games.GameManager.broadcastGameManagerStatus. By default, an update is always broadcasted.

Returns

non-null cast.receiver.games.GameManagerResult The result of the operation. Do not maintain a reference to this object as it may be reused for the next operation performed on the game manager.

updateLobbyState

updateLobbyState(lobbyState, extraMessageData, opt_noBroadcastUpdate) returns cast.receiver.games.GameManagerResult

Updates the lobby state on the game manager. This can trigger events and callbacks related to lobby state changes (for example, cast.receiver.games.EventType.LOBBY_OPEN).

Parameter

lobbyState

cast.receiver.games.LobbyState

The new lobby state.

extraMessageData

Object

An optional JSON serializable object. This will be passed to event handlers on this game manager as the cast.receiver.games.Event#requestExtraMessageData field of the cast.receiver.games.Event object.

opt_noBroadcastUpdate

Optional

boolean

If set to true, this disables broadcasting an update to all senders and the caller is responsible for calling cast.receiver.games.GameManager.broadcastGameManagerStatus. By default, an update is always broadcasted.

Returns

non-null cast.receiver.games.GameManagerResult The result of the operation. Do not maintain a reference to this object as it may be reused for the next operation performed on the game manager.

updatePlayerData

updatePlayerData(playerId, playerData, opt_noBroadcastUpdate) returns cast.receiver.games.GameManagerResult

Updates game specific player data that is stored while the game is running. Every response from the game manager to senders will include this player data. This can trigger events and callbacks related to player data changes (for example, cast.receiver.games.EventType.PLAYER_DATA_CHANGED).

Parameter

playerId

string

The player ID

playerData

Object

The JSON serializable data for the player.

opt_noBroadcastUpdate

Optional

boolean

If set to true, this disables broadcasting an update to all senders and the caller is responsible for calling cast.receiver.games.GameManager.broadcastGameManagerStatus. By default, an update is always broadcasted.

Returns

non-null cast.receiver.games.GameManagerResult The result of the operation. Do not maintain a reference to this object as it may be reused for the next operation performed on the game manager.

updatePlayerState

updatePlayerState(playerId, playerState, extraMessageData, opt_noBroadcastUpdate) returns cast.receiver.games.GameManagerResult

Updates the player to the specified player state. If this is not a valid transition for that player an error will be returned in the result object. This can trigger events and callbacks related to player state changes (for example, cast.receiver.games.EventType.PLAYER_AVAILABLE).

Parameter

playerId

string

The player ID of the player to be affected by this state change. If the playerId parameter is null and the state is chrome.cast.games.PlayerState.AVAILABLE, a new player will be registered. Since this new player is not associated with a sender, it is the responsibility of the game running on the receiver to manage this new player.

Value may be null.

playerState

cast.receiver.games.PlayerState

The player state to transition to.

extraMessageData

Object

An optional JSON serializable object. This will be passed to event handlers on this game manager as the cast.receiver.games.Event#requestExtraMessageData field of the cast.receiver.games.Event object.

opt_noBroadcastUpdate

Optional

boolean

If set to true, this disables broadcasting an update to all senders and the caller is responsible for calling cast.receiver.games.GameManager.broadcastGameManagerStatus. By default, an update is always broadcasted.

Returns

non-null cast.receiver.games.GameManagerResult The result of the operation. Do not maintain a reference to this object as it may be reused for the next operation performed on the game manager.