问题
I'm trying to get a basic chromecast app setup where I can send a simple custom message from Desktop Chrome to the Chromecast receiver. The devices is whitelisted, and the app sources are sitting at the url specified during the whitelisting process. Additionally the correct API_ID is being used and the NAMESPACE is the same for the receiver and sender apps.
The receiver app loads, but just after that I get:
[ 0.230s] [goog.net.WebSocket] The WebSocket disconnected unexpectedly: undefined
This seems to be preventing me from being able to send custom messages to the Chromecast.
From the sender app I am able to locate the device, connect, and launch the receiver app. I am also able to properly disconnect with the stopActivity() call on the sender.
The setup for the receiver is:
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();
The full log from the Chromecast device is (actual appId removed):
[ 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
Any help in the matter would be greatly appreciated! Thanks!
回答1:
The type for NAMESPACE
in the Receiver
constructor needs to be a an array. I'm guessing that in your code sample it is a string. That could cause the strange problems you are seeing.
来源:https://stackoverflow.com/questions/19191114/chromecast-receiver-app-error-the-websocket-disconnected-unexpectedly-undefine