thibauts / node-castv2-client

A Chromecast client based on the new (CASTV2) protocol
MIT License
649 stars 95 forks source link

Detecting ChromeCast Connect and Disconnect Events #25

Closed joelongstreet closed 8 years ago

joelongstreet commented 9 years ago

Not sure if this is the right place to post this question, but I'm having issues detecting when ChromeCasts join and leave the network.

I originally thought this was a problem with the mdns lib and the way it polled, so I filed an issue. The author of node_mdns helped me out and it looks like the ChromeCast device is the culprit:

Not sure if this is related, but after I start and stop my app a few times, I'll have to turn my wifi off and then on again to pick up serviceUps.

Sample App:

var mdns = require('mdns');
var browser = mdns.createBrowser(mdns.tcp('googlecast'));

browser.on('serviceUp', function(service){
  console.log('chromecast detected -', service.name);
});

browser.on('serviceDown', function(service){
  console.log('chromecast lost -', service.name);
});

browser.start();

Thanks for any help you can provide

thibauts commented 9 years ago

This is a reccurring issue documented here #22 and here (castnow repo).

I've had no time to investigate but it seems that since the last update the Chromecast doesn't advertise consistently over the mDNS protocol.

Usual Chromecast clients (Google Chrome, the Android Chromecast SDK) still use the old protocols for backward compatibility with some apps (SSDP for discovery and DIAL for launch / control) and the best guess currently is Chrome detects the dongles thanks to SSDP.

chromecast-scanner used to implement both methods for discovery but I see @xat changed that just a few minutes ago !

@xat how is it going ? Any news on this front ?

xat commented 9 years ago

The SSDP module brought in too much node-gyp trouble, thats why I got rid of it. There was also an MDNS Problem related to node v0.12.x. You can read about it here: https://github.com/kmpm/node-mdns-js/issues/31

I've temporary worked around the MDNS problem so chromecast-scanner now finds chromecast in the network ( at least for me :-D )

rknell commented 9 years ago

Hi xat,

probably not the right place, but I'm here now!

The new version you pushed up (0.4.1) almost immediately returns device not found for me. I'm going to try and roll my own solution using SSDP, besides the node-gyp, was there anything else that was of concern?

xat commented 9 years ago

@rknell which node version are you using?

node-gyp was the only problem with SSDP I know of.

rknell commented 9 years ago

Hi, Its v0.10.35

Just used the code you posted over here (below): https://github.com/thibauts/node-castv2-client/issues/22

And it worked immediately. Also tried rolling my own mDNS implementation and had no luck there either.

var Client = require('node-ssdp').Client
var client = new Client();

client.on('response', function (headers, statusCode, rinfo) {
  console.log('chromecast running on address', rinfo.address);
  client._stop();
});

client.search('urn:dial-multiscreen-org:service:dial:1');
xat commented 9 years ago

works fine for me with v0.10.35 (there is a known issue on v0.11.13 and bigger, see https://github.com/mafintosh/multicast-dns/issues/2). What Chromecast firmware version are you on?