How to use the mdns.isAvahi function in mdns

To help you get started, we’ve selected a few mdns examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AndreasMadsen / tcpnet / test / simple / loopback-interface.js View on Github external
var tcpnet = require('../../tcpnet.js');
var test = require('tap').test;
var async = require('async');
var ifname = require('interface-name');
var mdns = require('mdns');

// Avahi system is expected to emit an error
if (mdns.isAvahi) {
  test('avahi system should emit error', function (t) {

    var serviceA = tcpnet('test-service');
        serviceA.listen(0, '127.0.0.1');

        serviceA.once('error', function (err) {
          t.equal(
            err.message,
            'loopback address is not supported on linux-avahi platform'
          );

          serviceA.close(function () {
            t.end();
          });
        });
  });
github AndreasMadsen / tcpnet / tcpnet.js View on Github external
Service.prototype._startService = function (address, callback) {
  var networkName = ifname(address);
  var network = networkName;
  var isAny = isme(address, 'any');

  // If it listen to loopback interface set flag
  if (isAny || networkName === LOOPBACK_NAME) {
    this._loopbackAllowed = true;
  }

  // Special case, where loopback interface is used
  if (networkName === LOOPBACK_NAME) {

    // There is a linux-avahi exception when dealling with a loopback interface
    if (mdns.isAvahi) {
      return callback(
        new Error('loopback address is not supported on linux-avahi platform')
      );
    }

    // Use specical key
    network = mdns.loopbackInterface();
  } else if (isAny) {
    network = undefined;
  }

  this._discover = mdns.createBrowser(this._key, {
    networkInterface: network
  });

  this._discover.on('error', this._relayError);