hensm / fx_cast

Chromecast Web Sender SDK implementation for Firefox
https://hensm.github.io/fx_cast/
MIT License
1.87k stars 63 forks source link

Chromecast IP is not detected correctly #210

Closed F43nd1r closed 2 years ago

F43nd1r commented 2 years ago

OS version: Arch Linux Browser version: Firefox 99.0.1 Extension version: 0.2.0 Bridge version: 0.2.0

Description fx_cast seems to fail to detect the IP address of my chromecast correctly, it just shows up as 0.0.0.0:8009, and casting fails (neither chromecast nor browser do anything on button click). Screenshot_20220419_223410

Steps to reproduce

  1. Install new version 0.2.0 for bridge and extension
  2. Observe behaviour

Expected behaviour Connection to chromecast works from arch linux.

Logs Browser logs:

stderr output from native app fx_cast_bridge: *** WARNING *** The program 'fx_cast_bridge' uses the Apple Bonjour compatibility layer of Avahi.
stderr output from native app fx_cast_bridge: *** WARNING *** Please fix your application to use the native API of Avahi!
stderr output from native app fx_cast_bridge: *** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html>
stderr output from native app fx_cast_bridge: *** WARNING *** The program 'fx_cast_bridge' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
stderr output from native app fx_cast_bridge: *** WARNING *** Please fix your application to use the native API of Avahi!
stderr output from native app fx_cast_bridge: *** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html>
stderr output from native app fx_cast_bridge: node:internal/process/promises:246
stderr output from native app fx_cast_bridge:           triggerUncaughtException(err, true /* fromPromise */);
stderr output from native app fx_cast_bridge:           ^
stderr output from native app fx_cast_bridge: 
stderr output from native app fx_cast_bridge: Error: connect ECONNREFUSED 0.0.0.0:8009
stderr output from native app fx_cast_bridge:     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
stderr output from native app fx_cast_bridge:   errno: -111,
stderr output from native app fx_cast_bridge:   code: 'ECONNREFUSED',
stderr output from native app fx_cast_bridge:   syscall: 'connect',
stderr output from native app fx_cast_bridge:   address: '0.0.0.0',
stderr output from native app fx_cast_bridge:   port: 8009
stderr output from native app fx_cast_bridge: }
Error: fx_cast (Error): Bridge connection failed and backup not enabled. [background.js:1:1964](moz-extension://cffa0107-aca1-40d0-8346-4d8488585ecd/background/background.js)

Avahi seems to see the correct IP:

$ avahi-browse --all --ignore-local --resolve --terminate
+ enp8s0 IPv4 Chromecast-***   _googlecast._tcp     local
= enp8s0 IPv4 Chromecast-***   _googlecast._tcp     local
   hostname = [***.local]
   address = [192.168.0.118]
   port = [8009]
   txt = ["rs=" "nf=1" "bs=***" "st=0" "ca=201221" "fn=Dwalin TV" "ic=/setup/icon.png" "md=Chromecast" "ve=05" "rm=" "cd=***" "id=***"]
hensm commented 2 years ago

Well, that's an interesting one. I'll make a build with some additional logging later.

hensm commented 2 years ago

I don't know your packaging situation on Arch, so here's an unpackaged build: fx_cast_bridge.zip

Should be a drop-in replacement. Relevant logs in the browser console.

Also, a test script that might be more useful, but probably needs GCC and dev packages for avahi (though I think Arch bundles that stuff with the runtime package, maybe?): mdns_test.zip

F43nd1r commented 2 years ago

Browser console shows this

stderr output from native app fx_cast_bridge: *** WARNING *** The program 'fx_cast_bridge' uses the Apple Bonjour compatibility layer of Avahi.
stderr output from native app fx_cast_bridge: *** WARNING *** Please fix your application to use the native API of Avahi!
stderr output from native app fx_cast_bridge: *** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html>
stderr output from native app fx_cast_bridge: *** WARNING *** The program 'fx_cast_bridge' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
stderr output from native app fx_cast_bridge: *** WARNING *** Please fix your application to use the native API of Avahi!
stderr output from native app fx_cast_bridge: *** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html>
stderr output from native app fx_cast_bridge: Found service {
stderr output from native app fx_cast_bridge:   interfaceIndex: 2,
stderr output from native app fx_cast_bridge:   type: ServiceType {
stderr output from native app fx_cast_bridge:     name: 'googlecast',
stderr output from native app fx_cast_bridge:     protocol: 'tcp',
stderr output from native app fx_cast_bridge:     subtypes: [],
stderr output from native app fx_cast_bridge:     fullyQualified: true
stderr output from native app fx_cast_bridge:   },
stderr output from native app fx_cast_bridge:   replyDomain: 'local.',
stderr output from native app fx_cast_bridge:   flags: 2,
stderr output from native app fx_cast_bridge:   name: 'Chromecast-735fd7891ed61311ff3e7b0e40bdf395',
stderr output from native app fx_cast_bridge:   networkInterface: 'enp8s0',
stderr output from native app fx_cast_bridge:   fullname: 'Chromecast-735fd7891ed61311ff3e7b0e40bdf395._googlecast._tcp.local.',
stderr output from native app fx_cast_bridge:   host: '735fd789-1ed6-1311-ff3e-7b0e40bdf395.local.',
stderr output from native app fx_cast_bridge:   port: 8009,
stderr output from native app fx_cast_bridge:   rawTxtRecord: <Buffer 03 72 73 3d 04 6e 66 3d 31 0f 62 73 3d 46 41 38 46 43 41 39 35 34 33 41 34 04 73 74 3d 30 09 63 61 3d 32 30 31 32 32 31 0c 66 6e 3d 44 77 61 6c 69 6e ... 118 more bytes>,
stderr output from native app fx_cast_bridge:   txtRecord: {
stderr output from native app fx_cast_bridge:     rs: '',
stderr output from native app fx_cast_bridge:     nf: '1',
stderr output from native app fx_cast_bridge:     bs: 'FA8FCA9543A4',
stderr output from native app fx_cast_bridge:     st: '0',
stderr output from native app fx_cast_bridge:     ca: '201221',
stderr output from native app fx_cast_bridge:     fn: 'Dwalin TV',
stderr output from native app fx_cast_bridge:     ic: '/setup/icon.png',
stderr output from native app fx_cast_bridge:     md: 'Chromecast',
stderr output from native app fx_cast_bridge:     ve: '05',
stderr output from native app fx_cast_bridge:     rm: '',
stderr output from native app fx_cast_bridge:     cd: '3DDACD48AFAA056ACEAC1CC9A8A01940',
stderr output from native app fx_cast_bridge:     id: '735fd7891ed61311ff3e7b0e40bdf395'
stderr output from native app fx_cast_bridge:   },
stderr output from native app fx_cast_bridge:   addresses: [ '0.0.0.0' ]
stderr output from native app fx_cast_bridge: }
stderr output from native app fx_cast_bridge: node:internal/process/promises:246
stderr output from native app fx_cast_bridge:           triggerUncaughtException(err, true /* fromPromise */);
stderr output from native app fx_cast_bridge:           ^
stderr output from native app fx_cast_bridge: 
stderr output from native app fx_cast_bridge: Error: connect ECONNREFUSED 0.0.0.0:8009
stderr output from native app fx_cast_bridge:     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
stderr output from native app fx_cast_bridge:   errno: -111,
stderr output from native app fx_cast_bridge:   code: 'ECONNREFUSED',
stderr output from native app fx_cast_bridge:   syscall: 'connect',
stderr output from native app fx_cast_bridge:   address: '0.0.0.0',
stderr output from native app fx_cast_bridge:   port: 8009
stderr output from native app fx_cast_bridge: }
Error: fx_cast (Error): Bridge connection failed and backup not enabled.

And the test script:

$ node index.js 
*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html>
*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html>
Local addresses [
  '192.168.0.103',
  '192.168.122.1',
  'fe80::5054:ff:fea9:a6d3',
  'fe80::fc54:ff:fec8:89db'
]
b1 found {
  interfaceIndex: 2,
  type: ServiceType {
    name: 'googlecast',
    protocol: 'tcp',
    subtypes: [],
    fullyQualified: true
  },
  replyDomain: 'local.',
  flags: 2,
  name: 'Chromecast-735fd7891ed61311ff3e7b0e40bdf395',
  networkInterface: 'enp8s0',
  fullname: 'Chromecast-735fd7891ed61311ff3e7b0e40bdf395._googlecast._tcp.local.',
  host: '735fd789-1ed6-1311-ff3e-7b0e40bdf395.local.',
  port: 8009,
  rawTxtRecord: <Buffer 03 72 73 3d 04 6e 66 3d 31 0f 62 73 3d 46 41 38 46 43 41 39 35 34 33 41 34 04 73 74 3d 30 09 63 61 3d 32 30 31 32 32 31 0c 66 6e 3d 44 77 61 6c 69 6e ... 118 more bytes>,
  txtRecord: {
    rs: '',
    nf: '1',
    bs: 'FA8FCA9543A4',
    st: '0',
    ca: '201221',
    fn: 'Dwalin TV',
    ic: '/setup/icon.png',
    md: 'Chromecast',
    ve: '05',
    rm: '',
    cd: '3DDACD48AFAA056ACEAC1CC9A8A01940',
    id: '735fd7891ed61311ff3e7b0e40bdf395'
  },
  addresses: [ '0.0.0.0' ]
}
b2 found {
  interfaceIndex: 2,
  type: ServiceType {
    name: 'googlecast',
    protocol: 'tcp',
    subtypes: [],
    fullyQualified: true
  },
  replyDomain: 'local.',
  flags: 2,
  name: 'Chromecast-735fd7891ed61311ff3e7b0e40bdf395',
  networkInterface: 'enp8s0',
  fullname: 'Chromecast-735fd7891ed61311ff3e7b0e40bdf395._googlecast._tcp.local.',
  host: '735fd789-1ed6-1311-ff3e-7b0e40bdf395.local.',
  port: 8009,
  rawTxtRecord: <Buffer 03 72 73 3d 04 6e 66 3d 31 0f 62 73 3d 46 41 38 46 43 41 39 35 34 33 41 34 04 73 74 3d 30 09 63 61 3d 32 30 31 32 32 31 0c 66 6e 3d 44 77 61 6c 69 6e ... 118 more bytes>,
  txtRecord: {
    rs: '',
    nf: '1',
    bs: 'FA8FCA9543A4',
    st: '0',
    ca: '201221',
    fn: 'Dwalin TV',
    ic: '/setup/icon.png',
    md: 'Chromecast',
    ve: '05',
    rm: '',
    cd: '3DDACD48AFAA056ACEAC1CC9A8A01940',
    id: '735fd7891ed61311ff3e7b0e40bdf395'
  },
  addresses: [ '0.0.0.0', '::' ]
}
hensm commented 2 years ago

Looks like it's a bug in the dns_sd bindings, or Avahi's compat layer. Here's a new test script with some more logging in the resolver sequence: mdns_test.zip Edit: Actually, that definitely won't work

After a little more research, it's not a bug in the compat layer, since the address isn't resolved via the dns_sd method. Could be a bug in node's getaddrinfo binding or some problem with your config causing address lookup issues? Though Avahi seems to be able to manage it.

New version: mdns_test.zip

hensm commented 2 years ago

Oh yeah, just remembered, people had issues with Arch before because avahi wasn't resolving through nss. Try installing this: https://archlinux.org/packages/extra/x86_64/nss-mdns/ https://wiki.archlinux.org/title/avahi#Hostname_resolution

F43nd1r commented 2 years ago

Oh yeah, just remembered, people had issues with Arch before because avahi wasn't resolving through nss. Try installing this: https://archlinux.org/packages/extra/x86_64/nss-mdns/ https://wiki.archlinux.org/title/avahi#Hostname_resolution

this worked, thanks! Is this documented somewhere? If not, might help others to put it in there. Nvm, found it. Sorry for not reading closely.

hensm commented 2 years ago

No worries, I'd completely forgotten about it myself. I'll see if I can make it more obvious, anyway.