Constructor

GameManagerClient

new GameManagerClient(session)

Used to allow a sender to interact with the cast game manager running on the receiver. Keeps track of player, game, and lobby state information and can send requests to the game manager on the receiver.

Do not instantiate this class directly. Instead, use chrome.cast.games.GameManagerClient.getInstanceFor to get an instance.

Parameter

session

chrome.cast.Session

An existing cast session.

Value must not be null.

See also
chrome.cast.games.GameManagerClient#getInstanceFor

Methods

getInstanceFor

static

getInstanceFor(session, successCallback, errorCallback)

Asynchronously obtains a GameManagerClient instance for the given cast session. The successCallback will be called with a result object that contains the GameManagerClient after initialization is completed successfully.

Parameter

session

chrome.cast.Session

An existing cast session.

Value must not be null.

successCallback

function(non-null chrome.cast.games.GameManagerInstanceResult)

Value must not be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Value may be null.

addEventListener

addEventListener(type, listener)

Adds a listener for a game manager event type. When the event is triggered, the listener will be called with an implementation of chrome.cast.games.GameManagerEvent that corresponds to the event type. For example, chrome.cast.games.GameManagerPlayerInfoEvent corresponds to the chrome.cast.games.GameManagerEventType.PLAYER_INFO_CHANGED event type.

Parameter

type

chrome.cast.games.GameManagerEventType

listener

function(non-null chrome.cast.games.GameManagerEvent)

See also
chrome.cast.games.GameManagerEventType

dispose

dispose()

Disposes this object, releasing all used resources.

See also
chrome.cast.games.GameManagerClient#isDisposed

getCurrentState

getCurrentState() returns chrome.cast.games.GameManagerState

Returns the current state of the game manager.

This method will throw an error if this GameManagerClient has been disposed.

Returns

non-null chrome.cast.games.GameManagerState 

See also
chrome.cast.games.GameManagerClient#isDisposed

getLastUsedPlayerId

getLastUsedPlayerId() returns string

Returns the last controllable player ID used by this sender or null if there is no known last controllable player ID. Useful for the common case when there is only one player per sender.

This method will throw an error if this GameManagerClient has been disposed.

Returns

nullable string 

See also
chrome.cast.games.GameManagerClient#isDisposed

isDisposed

isDisposed() returns boolean

Returns whether this client has already been disposed.

Returns

boolean Whether this client has been disposed.

See also
chrome.cast.games.GameManagerClient#dispose

removeEventListener

removeEventListener(type, listener)

Removes a previously added listener for a game manager event type.

Parameter

type

chrome.cast.games.GameManagerEventType

listener

function(non-null chrome.cast.games.GameManagerEvent)

sendGameMessage

sendGameMessage(extraMessageData)

Sends a game specific message to the receiver, its contents entirely up to the application. The message will originate from the last used controllable player. This is a fire and forget method where there is no guarantee the message is sent and the receiver will not send a response back to the sender.

This method will throw an error if this GameManagerClient has been disposed.

Parameter

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

See also
chrome.cast.games.GameManagerClient#isDisposed

sendGameMessageWithPlayerId

sendGameMessageWithPlayerId(playerId, extraMessageData)

Sends a game specific message to the receiver, its contents entirely up to the application. This is a fire and forget method where there is no guarantee the message is sent and the receiver will not send a response back to the sender.

This method will throw an error if this GameManagerClient has been disposed.

Parameter

playerId

string

The player ID of the controllable player sending this message.

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

See also
chrome.cast.games.GameManagerClient#isDisposed

sendGameRequest

sendGameRequest(extraMessageData, successCallback, errorCallback)

Sends a game specific message to the receiver, its contents entirely up to the application. The message will originate from the last used controllable player. The receiver will send a response back to this sender.

This method will throw an error if this GameManagerClient has been disposed.

Parameter

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#isDisposed

sendGameRequestWithPlayerId

sendGameRequestWithPlayerId(playerId, extraMessageData, successCallback, errorCallback)

Sends a game specific message to the receiver, its contents entirely up to the application. The receiver will send a response back to this sender.

This method will throw an error if this GameManagerClient has been disposed.

Parameter

playerId

string

The player ID of the controllable player sending this message.

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#isDisposed

sendPlayerAvailableRequest

sendPlayerAvailableRequest(extraMessageData, successCallback, errorCallback)

Sends a request to the receiver to transition the last used player by this sender into chrome.cast.games.PlayerState.AVAILABLE. If the player's transition is not valid an error will be returned in the error callback. If the last used player is unknown a new player will be registered its player ID will be set as the last used player when the receiver responds to this request.

This method will throw an error if this GameManagerClient has been disposed.

Parameter

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#isDisposed
chrome.cast.games.GameManagerClient#dispose

sendPlayerAvailableRequestWithPlayerId

sendPlayerAvailableRequestWithPlayerId(playerId, extraMessageData, successCallback, errorCallback)

Sends a request to the receiver to transition a player into chrome.cast.games.PlayerState.AVAILABLE. If the player's transition is not valid an error will be returned in the error callback. If playerId is null a new player will be registered its player ID will be set as the last used player when the receiver responds to this request.

This method will throw an error if this GameManagerClient has been disposed.

Parameter

playerId

string

The id of the player to transition.

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#isDisposed
chrome.cast.games.GameManagerClient#dispose

sendPlayerIdleRequest

sendPlayerIdleRequest(extraMessageData, successCallback, errorCallback)

Sends a request to the receiver to transition the last used player by this sender into chrome.cast.games.PlayerState.IDLE state. If the player's transition is not valid an error will be returned in the error callback.

This method will throw an error if this GameManagerClient has been disposed, or if there is no last used player id.

Parameter

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#getLastUsedPlayerId
chrome.cast.games.GameManagerClient#isDisposed
chrome.cast.games.GameManagerClient#dispose

sendPlayerIdleRequestWithPlayerId

sendPlayerIdleRequestWithPlayerId(playerId, extraMessageData, successCallback, errorCallback)

Sends a request to the receiver transition the specified player into chrome.cast.games.PlayerState.IDLE. If this is not a valid transition for that player an error will be returned in the error callback.

This method will throw an error if this GameManagerClient has been disposed.

Parameter

playerId

string

The id of the player to transition.

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#isDisposed
chrome.cast.games.GameManagerClient#dispose

sendPlayerPlayingRequest

sendPlayerPlayingRequest(extraMessageData, successCallback, errorCallback)

Sends a request to the receiver to transition the last used player by this sender into chrome.cast.games.PlayerState.PLAYING state. If the player's transition is not valid an error will be returned in the error callback.

This method will throw an error if this GameManagerClient has been disposed, or if there is no last used player id.

Parameter

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#getLastUsedPlayerId
chrome.cast.games.GameManagerClient#isDisposed
chrome.cast.games.GameManagerClient#dispose

sendPlayerPlayingRequestWithPlayerId

sendPlayerPlayingRequestWithPlayerId(playerId, extraMessageData, successCallback, errorCallback)

Sends a request to the receiver transition the specified player into chrome.cast.games.PlayerState.PLAYING. If this is not a valid transition for that player an error will be returned in the error callback.

This method will throw an error if this GameManagerClient has been disposed.

Parameter

playerId

string

The id of the player to transition.

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#isDisposed
chrome.cast.games.GameManagerClient#dispose

sendPlayerQuitRequest

sendPlayerQuitRequest(extraMessageData, successCallback, errorCallback)

Sends a request to the receiver to transition the last used player by this sender into chrome.cast.games.PlayerState.QUIT state.

This method will throw an error if this GameManagerClient has been disposed, or if there is no last used player id.

Parameter

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#getLastUsedPlayerId
chrome.cast.games.GameManagerClient#isDisposed
chrome.cast.games.GameManagerClient#dispose

sendPlayerQuitRequestWithPlayerId

sendPlayerQuitRequestWithPlayerId(playerId, extraMessageData, successCallback, errorCallback)

Sends a request to the receiver transition the specified player into chrome.cast.games.PlayerState.QUIT.

This method will throw an error if this GameManagerClient has been disposed.

Parameter

playerId

string

The id of the player to transition.

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#isDisposed
chrome.cast.games.GameManagerClient#dispose

sendPlayerReadyRequest

sendPlayerReadyRequest(extraMessageData, successCallback, errorCallback)

Sends a request to the receiver to transition the last used player by this sender into chrome.cast.games.PlayerState.READY state. If the player's transition is not valid an error will be returned in the error callback.

This method will throw an error if this GameManagerClient has been disposed, or if the last used player ID is unknown.

Parameter

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#getLastUsedPlayerId
chrome.cast.games.GameManagerClient#isDisposed
chrome.cast.games.GameManagerClient#dispose

sendPlayerReadyRequestWithPlayerId

sendPlayerReadyRequestWithPlayerId(playerId, extraMessageData, successCallback, errorCallback)

Sends a request to the receiver transition the specified player into chrome.cast.games.PlayerState.READY. If this is not a valid transition for that player an error will be returned in the error callback.

This method will throw an error if this GameManagerClient has been disposed.

Parameter

playerId

string

The id of the player to transition.

extraMessageData

Object

Application-specific JSON serializable data to pass along with the request.

successCallback

function(non-null chrome.cast.games.GameManagerResult)

Callback triggered when the request is processed successfully or null.

Value may be null.

errorCallback

function(non-null chrome.cast.games.GameManagerError)

Callback triggered when the request fails or null.

Value may be null.

See also
chrome.cast.games.GameManagerClient#isDisposed
chrome.cast.games.GameManagerClient#dispose