becvert / cordova-plugin-zeroconf

Cordova ZeroConf Plugin
MIT License
81 stars 57 forks source link

Does not find service published with bonjour on windows #83

Closed Blackfaded closed 5 years ago

Blackfaded commented 5 years ago

When I register a service in my android cordova app with

zeroconf.register('_http._tcp.', 'local.', 'Spaghetti', port, {}, onDNSregister);

function onDNSregister(result) {
      const action = result.action; // 'registered'
      const service = result.service;
      console.log({ action, service });
    }

and try to find the service with my electron app with

    const browser = bonjour.find({ type: 'http' });
    browser.on('up', onClientFound);
    browser.on('down', onClientDisconnect);

everything works and I can see the cordova apps IP.

But when I start the server from my electron app with

bonjour.publish({ name: 'My Web Server', type: 'http', port: 3000 });

and try to find the service from my android cordova app with

 zeroconf.watch('_http._tcp.', 'local.', function(result) {
        var action = result.action;
        var service = result.service;
        if (action == 'added') {
          console.log('service added', service);
        } else if (action == 'resolved') {
          console.log('service resolved', service);
          /* service : {
        'domain' : 'local.',
        'type' : '_http._tcp.',
        'name': 'Becvert\'s iPad',
        'port' : 80,
        'hostname' : 'ipad-of-becvert.local',
        'ipv4Addresses' : [ '192.168.1.125' ], 
        'ipv6Addresses' : [ '2001:0:5ef5:79fb:10cb:1dbf:3f57:feb0' ],
        'txtRecord' : {
            'foo' : 'bar'
        } */
        } else {
          console.log('service removed', service);
        }

I cannot find the service.

If I use the bonjour lib in a test.js file with following i can find the service too:

const bonjour = require('bonjour')();

const browser = bonjour.find({ type: 'http' });
browser.on('up', onClientFound);
browser.on('down', onClientDisconnect);

function onClientFound(client) {
  console.log({ client });
}

function onClientDisconnect(client) {
  console.log({ client });
}
  client: {
    addresses: [
      '10.0.75.1',
      '192.168.56.1',
      '169.254.236.237',
      '192.168.178.55',
      '172.30.84.33',
      'fe80::537:eb94:6134:8127',
      'fe80::50f9:b8eb:a8e8:f86b',
      'fe80::ed84:14d9:2e29:eced',
      'fe80::3557:6c29:cbc9:b176',
      'fe80::75ed:48f0:a6d6:114'
    ],
    name: 'My Web Server',
    fqdn: 'My Web Server._http._tcp.local',
    host: 'DESKTOP-B9ONMN5',
    referer: { address: '10.0.75.1', family: 'IPv4', port: 5353, size: 550 },
    port: 3000,
    type: 'http',
    protocol: 'tcp',
    subtypes: [],
    rawTxt: <Buffer 00>,
    txt: {}
  }
}

Am I missing something?

Blackfaded commented 5 years ago

Looks like this is an issue with bonjour.js After a couple of hours I moved to another lib called mdns-js and it worked like a charm!