Google Cast Game Manager Receiver

216 views Asked by At

I've encountered a bug that I'm not sure how to fix while trying to get the Cast Game Manager up and running. I've been able to connect the game manager, and get state updates. After this, I attempt to send a PlayerAvailableRequest. The receiver updates the game debug ui indicating that the request was successful, but then crashes while trying to send it's response message to the sender. Below I've attached the relevant console logs, as well as a picture of the GameDebug UI. Please let me know if there is something that I'm missing on my end.

 [ 59.643s] [cast.receiver.IpcChannel] Received message: {"data":"{\"type\":1100,\"requestId\":1}","namespace":"urn:x-cast:com.google.cast.games","senderId":"219:C97BEC14-B8AF-4BD1-855A-C55CEED51E43"}
cast_receiver.js:37  [ 59.650s] [cast.receiver.CastMessageBus] Dispatching CastMessageBus message
cast_receiver.js:37  [ 59.669s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:com.google.cast.games","senderId":"219:C97BEC14-B8AF-4BD1-855A-C55CEED51E43","data":"{\"type\":1,\"requestId\":1,\"playerToken\":null,\"statusCode\":0,\"errorDescription\":\"\",\"gameplayState\":1,\"lobbyState\":1,\"players\":[{\"playerId\":\":0\",\"playerState\":1,\"playerData\":null}],\"gameData\":null,\"gameStatusText\":\"\",\"gameManagerConfig\":{\"applicationName\":\"Code Cast\",\"maxPlayers\":2,\"version\":\"1.0.0\"},\"extraMessageData\":null}"}
cast_receiver.js:37  [ 59.689s] [cast.receiver.IpcChannel] Received message: {"data":"{\"type\":1,\"requestId\":2}","namespace":"urn:x-cast:com.google.cast.games","senderId":"219:C97BEC14-B8AF-4BD1-855A-C55CEED51E43"}
cast_receiver.js:37  [ 59.696s] [cast.receiver.CastMessageBus] Dispatching CastMessageBus message
cast_games_receiver.js:220 Uncaught TypeError: Cannot read property 'call' of undefined cast_games_receiver.js:220 b.Zbcast_games_receiver.js:221 l.f.EventTarget.dkcast_games_receiver.js:218 b.dispatchEventcast_games_receiver.js:261 Qcast_games_receiver.js:255 cast.receiver.games.j.Clcast_receiver.js:22 ybcast_receiver.js:21 g.dispatchEventcast_receiver.js:33 R.gbcast_receiver.js:22 ybcast_receiver.js:21 g.dispatchEventcast_receiver.js:31 g.hbcast_receiver.js:22 ybcast_receiver.js:21 g.dispatchEventcast_receiver.js:28 g.hb

enter image description here

EDIT: I've narrowed it down to using a GameManagerListener via addGameManagerListener. I've made my listener as simple as the example, but it still crashes.

Game Manager Listener Object:
MyGame = function () {
};

MyGame.prototype.onPlayerAvailable = function (event) {
    console.log('Player ' + event.playerInfo.playerId + ' is available');
};

MyGame.prototype.onPlayerReady = function () { };
MyGame.prototype.onPlayerIdle = function () { };
MyGame.prototype.onPlayerPlaying = function () { };
MyGame.prototype.onPlayerDropped = function () { };
MyGame.prototype.onPlayerQuit = function () { };
MyGame.prototype.onGetGameManagerStatus = function () { };
MyGame.prototype.onGameMessage = function () { };
MyGame.prototype.onGameLoading = function () { };
MyGame.prototype.onGameRunning = function () { };
MyGame.prototype.onGamePaused = function () { };
MyGame.prototype.onGameShowingInfoScreen = function () { };
MyGame.prototype.onLobbyOpen = function () { };
MyGame.prototype.onLobbyClosed = function () { };

line adding it:
this.mMyGame = new MyGame();
this.mCastGameManager.addGameManagerListener(this.mMyGame);
2

There are 2 answers

1
Li-Te Cheng On

Sorry - this is because of errors in the documentation guide:

  • The GameManagerListener sample is missing additional methods to override.
  • There is a ")" before the ending semicolon at the end of the sample that implements the GameManager property.

For addGameManagerListener, implement all of the methods of GameManagerListener listed in https://developers.google.com/cast/docs/reference/receiver/cast.receiver.games.GameManagerListener

For example, you need to add:

MyGame.prototype.onGameMessageReceived = function() {};
MyGame.prototype.onGameDataChanged = function() {};
MyGame.prototype.onPlayerDataChanged = function() {};
MyGame.prototype.onGameDataChanged = function() {};
MyGame.prototype.onGameStatusTextChanged = function() {};

As for implementing the callback for the defined GameManager property, make sure there are no syntax errors, e.g.

gameManager.onPlayerAvailable = function(event) {
    console.log('Player ' + event.playerInfo.playerId + ' is available');
};

and not

gameManager.onPlayerAvailable = function(event) {
    console.log('Player ' + event.playerInfo.playerId + ' is available');
});

Apologies again - we'll get the docs fixed. :)

1
Jeff Schmitz On

Ok, I'm posting my solution for anyone else implementing this that's having the same issues.

In the documentation it states that, "There are three ways to set up request event callbacks with GameManager.

  • Call the addEventListener method for a specific request.
  • Implement a callback for the defined GameManager property.
  • Call the addGameManagerListener method to provide one object (that implements GameManagerListener) to handle all requests. "

As it turns out, only the addEventListener method seems to work. When I created a class and added it as a listener, I got the errors that I had posted in my original question. When I implemented callbacks, none were hit. I'm not sure if this is due to something that I'm doing on my end, but, again, only addEventListener seems to work.