我正在尝试获取基本的 chromecast 应用程序设置,我可以在其中将简单的自定义消息从桌面 Chrome 发送到 Chromecast 接收器。设备已列入白名单,并且应用程序源位于白名单过程中指定的 url。此外,正在使用正确的 API_ID,并且接收方和发送方应用程序的 NAMESPACE 相同。
接收器应用程序加载,但之后我得到:
[ 0.230s] [goog.net.WebSocket] The WebSocket disconnected unexpectedly: undefined
这似乎使我无法向 Chromecast 发送自定义消息。
从发送方应用程序中,我能够找到设备、连接并启动接收方应用程序。我还能够正确断开与发送方的 stopActivity() 调用的连接。
接收器的设置是:
var receiver = new cast.receiver.Receiver(APP_ID, NAMESPACE);
var channelHandler = new cast.receiver.ChannelHandler(NAMESPACE);
channelHandler.addChannelFactory(receiver.createChannelFactory(NAMESPACE));
channelHandler.addEventListener('error', function($e){
console.log('JAC - Error!');
});
channelHandler.addEventListener('open', function($e){
console.log('JAC - OnOpen!');
});
channelHandler.addEventListener('message', function($e){
console.log('JAC - Message: ' + $e.type);
});
receiver.start();
Chromecast 设备的完整日志是(实际的 appId 已删除):
[ 0.027s] [cast.receiver.ChannelHandler] New channel factory added: MY-APP-ID to heartbeatChannelHandler
cast_receiver.js:66
[ 0.088s] [cast.receiver.ChannelHandler] New channel factory added: receiverTest1: MY-APP-ID to receiverTest1
cast_receiver.js:66
[ 0.094s] [cast.receiver.ConnectionService] Open connection service websocket: url=ws://localhost:8008/connection
cast_receiver.js:66
[ 0.098s] [goog.net.WebSocket] Opening the WebSocket on ws://localhost:8008/connection
cast_receiver.js:66
[ 0.104s] [cast.receiver.Receiver] Receiver started.
cast_receiver.js:66
[ 0.142s] [goog.net.WebSocket] WebSocket opened on ws://localhost:8008/system/control
cast_receiver.js:66
[ 0.153s] [cast.receiver.ChannelOverWebSocket] Dispatch OPEN event to ws://localhost:8008/system/control
cast_receiver.js:66
[ 0.159s] [cast.receiver.Channel] Dispatch OPEN event to ws://localhost:8008/system/control
cast_receiver.js:66
[ 0.164s] [cast.receiver.Platform] Platform channel is open: ws://localhost:8008/system/control
cast_receiver.js:66
[ 0.208s] [goog.net.WebSocket] WebSocket opened on ws://localhost:8008/connection
cast_receiver.js:66
[ 0.212s] [cast.receiver.ConnectionService] Got event: d
cast_receiver.js:66
[ 0.222s] [goog.net.WebSocket] The WebSocket on ws://localhost:8008/connection closed.
cast_receiver.js:66
[ 0.225s] [cast.receiver.ConnectionService] Got event: a
cast_receiver.js:66
[ 0.230s] [goog.net.WebSocket] The WebSocket disconnected unexpectedly: undefined
任何有关此事的帮助将不胜感激!谢谢!