我正在尝试使用基本的Chromecast应用设置,我可以将桌面Chrome中的简单自定义消息发送到Chromecast接收器。这些设备已列入白名单,并且应用来源位于白名单过程中指定的网址。此外,正在使用正确的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设备的完整日志是(已删除实际应用):
[ 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
对此事的任何帮助将不胜感激!谢谢!
答案 0 :(得分:1)
NAMESPACE
构造函数中Receiver
的类型需要是一个数组。我猜你的代码示例中它是一个字符串。这可能会导致你看到的奇怪问题。