thibauts / node-castv2-client

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

How to get Chromecast display name? #57

Closed ariporad closed 7 years ago

ariporad commented 7 years ago

Hi,

I'm trying to display the user friendly name of a chromecast, and I can't seem to figure out how to get it. Right now, I'm using MDNS to find the name, and I'm getting something like "Chromecast-Audio-9cd1691d91e3dd6a3b2edbe9b2f8aff4".

Any ideas on how to go about that? Thanks! (Sorry if I missed it!)

strabbit commented 7 years ago

I believe you can request http://xxx.xxx.xxx.xxx:8008/ssdp/device-desc.xml, where xxx.xxx.xxx.xxx is the Chromecast IP. Not sure if there's an easier / quicker way.

ariporad commented 7 years ago

@strabbit: Thanks so much... That seems to work for devices, but I can't figure out groups. So far, groups appear as a different device (same IP, different port), for example:

found device "Chromecast-Audio-be3e75f9990081c3d2e1e19dfde793f3" at 192.168.73.23:8009
found device "Google-Cast-Group-D953E9E64D954CEB959076DE7749EB39" at 192.168.73.23:42279

I tried going one port lower (ex. 42278), and that didn't work.

Thanks again for all your help, the internet seems pretty scarce about this!

strabbit commented 7 years ago

Okay -- I really don't understand mDNS... but I managed to get the names on my mac using dns-sd -Z _googlecast._tcp... how that translates to something that can be used in node, I don't know... but it appears what you're looking for is the TXT record.

strabbit commented 7 years ago

I take that back... this is what you want:

var mdns = require('mdns');

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

browser.on('serviceUp', function(service) {
  console.log('found device "%s" at %s:%d', service.txtRecord.fn, service.addresses[0], service.port);
});

browser.start();
ariporad commented 7 years ago

@strabbit: Thanks... I was just about to post that!

Would you consider adding that to the wiki, it could be really useful for newcomers.

thibauts commented 7 years ago

This is right at the start of the readme code. If you think this is not enough, please reopen and comment.

matangover commented 4 years ago

@thibauts the README code currently doesn't refer to service.txtRecord.fn, only to service.name. On my machine these give two different results, only service.txtRecord.fn gives the display name.

matangover commented 4 years ago

I changed the console.log line in the README like so and it worked for me:

console.log('found device "%s" at %s:%d, "%s"', service.txtRecord.fn, service.addresses[0], service.port, service.name);

Thanks!!