Google Cast游戏管理器接收器

时间:2015-06-15 18:16:19

标签: javascript google-cast

我遇到了一个错误,我不确定在尝试启动和运行Cast游戏管理器时如何修复。我已经能够连接游戏管理器,并获得状态更新。在此之后,我尝试发送PlayerAvailableRequest。接收器更新游戏调试ui,指示请求成功,但在尝试将其响应消息发送给发送者时崩溃。下面我附上了相关的控制台日志,以及GameDebug UI的图片。如果我有什么遗漏,请告诉我。

 [ 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

编辑:我已经将其缩小为通过addGameManagerListener使用GameManagerListener。我让我的听众像示例一样简单,但它仍然崩溃。

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 个答案:

答案 0 :(得分:3)

抱歉 - 这是因为documentation guide

中的错误
  • GameManagerListener示例缺少其他方法 覆盖。
  • 有一个")"在结束分号之前 实现GameManager属性的示例。

对于addGameManagerListener,实现https://developers.google.com/cast/docs/reference/receiver/cast.receiver.games.GameManagerListener

中列出的GameManagerListener的所有方法

例如,您需要添加:

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

至于实现定义的GameManager属性的回调,请确保没有语法错误,例如

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

而不是

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

再次道歉 - 我们将修复文档。 :)

答案 1 :(得分:0)

好的,我正在为实施此问题的其他任何人发布我的解决方案,但问题相同。

在文件中说明, "有三种方法可以使用GameManager设置请求事件回调。

  • 为特定请求调用addEventListener方法。
  • 为定义的GameManager属性实现回调。
  • 调用addGameManagerListener方法以提供一个对象(实现GameManagerListener)来处理所有请求。 "

事实证明,只有addEventListener方法似乎有效。当我创建一个类并将其添加为监听器时,我得到了我在原始问题中发布的错误。当我实现回调时,没有一个被击中。我不确定这是否是由于我在我的结果上所做的事情,但是,再次,只有addEventListener似乎有效。