2015-06-15 71 views
0

我遇到了一個錯誤,我不知道如何解決在試圖讓Cast Game Manager啓動並運行時如何解決這個問題。我已經能夠連接遊戲管理器,並獲得狀態更新。在此之後,我嘗試發送一個PlayerAvailableRequest。接收者更新遊戲調試ui,指示請求成功,但在嘗試將其響應消息發送給發件人時崩潰。下面我附上了相關的控制檯日誌,以及GameDebug UI的圖片。請讓我知道,如果有什麼我在我的最後失蹤。Google Cast Game Manager Receiver

[ 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); 

回答

0

好吧,我發佈我的解決方案,爲其他任何人執行此問題有相同的問題。

在它指出, 「有三種方式來設置請求事件回調與遊戲管理的文檔。

  • 徵集具體要求addEventListener方法。
  • 的定義實施回調遊戲管理財產。
  • 調用addGameManagerListener方法來提供一個對象(即實現GameManagerListener)來處理所有請求。「

事實證明,只有addEventListener方法似乎工作。當我創建一個類並將其添加爲偵聽器時,我收到了我在原始問題中發佈的錯誤。當我實現回調時,沒有人被擊中。我不確定這是否是由於我正在做的事情,但是,再次,只有addEventListener似乎工作。

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.onPlayerAvailable = function(event) { 
    console.log('Player ' + event.playerInfo.playerId + ' is available'); 
}; 

,而不是

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

再次道歉 - 我們將得到的文檔固定。 :)