3
votes

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
I'm not ready to propose this as a full-blown answer because I don't know what type NAMESPACE is in your Receiver constructor, but it's supposed to be an array. If it's not, maybe strange things happen?dowski
Ahh Bingo! That seems to have made the error go away. Do you want to post that as an answer instead of a comment so that I can give you credit for it?Jake Callery
Moved it to an answer. Thanks!dowski

1 Answers

1
votes

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.