How to use the mdns.createBrowser 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 gebhardm / energyhacks / Gauge / serve_mqtt.js View on Github external
var url = require("url");

var path = require("path");

var io = require("socket.io")(http);

// multicast DNS service discovery
var mdns = require("mdns");

// resolution requence added due to mdns issue - see https://github.com/agnat/node_mdns/issues/130
var sequence = [ mdns.rst.DNSServiceResolve(), "DNSServiceGetAddrInfo" in mdns.dns_sd ? mdns.rst.DNSServiceGetAddrInfo() : mdns.rst.getaddrinfo({
    families: [ 4 ]
}), mdns.rst.makeAddressesUnique() ];

// detect mqtt publishers and create corresponding servers
var mdnsbrowser = mdns.createBrowser(mdns.tcp("mqtt"), {
    resolverSequence: sequence
});

mdnsbrowser.on("serviceUp", function(service) {
    console.log("Detected MQTT service on: " + service.addresses[0] + ":" + service.port);
    mqttconnect(service.addresses[0], service.port);
});

mdnsbrowser.on("serviceDown", function(service) {
    console.log("MQTT service down: ", service);
});

mdnsbrowser.on("error", function(exception) {
    console.log("An error occured: ", exception);
});
github citelab / JAMScript / lib / jdiscovery / mdnsregistry.js View on Github external
MDNSRegistry.prototype._browse = function(self, attr, machType, event) {
    var browser = mdns.createBrowser(mdns.tcp(self.app + '-' + machType[0] + '-' + attr));

    self.browsers[machType][attr] = browser;

    browser.on('serviceUp', function(service) {
        // ignore our own services
        if (service.name == self.id) {
            return;
        }

        // emit a discovery event!
        self.emit('discovery', attr, event, service.name, JSON.parse(service.txtRecord.msg).payload);
    });

    browser.on('error', function(err) {
        browser.stop();
        self.emit('browser-error', self, attr, machType, event);
github citelab / JAMScript / lib / jdiscovery / mdnsregistry.js View on Github external
MDNSRegistry.prototype._browseForStatus = function(self, machType, events) {
    var browser = mdns.createBrowser(mdns.tcp(self.app + '-' + machType[0] + '-status'));

    self.browsers[machType].status = browser;

    browser.on('serviceUp', function(service) {
        // ignore our own services
        if (service.name == self.id) {
            return;
        }

        // emit a node online event!
        self.emit('discovery', 'status', events.online, service.name, JSON.parse(service.txtRecord.msg).payload);
    });

    browser.on('serviceDown', function(service) {
        self.emit('discovery', 'status', events.offline, service.name, 'offline');
    });
github Adeptive / SoundTouch-NodeJS / discovery.js View on Github external
SoundTouchDiscovery.prototype.search = function(callbackUp, callbackDown) {
    console.log("Started Searching...");
    var discovery = this;
    var sequence = [
        mdns.rst.DNSServiceResolve(),
        mdns.rst.getaddrinfo({families: [4] })
    ];

    // watch all http servers
    this.browser = mdns.createBrowser(mdns.tcp('soundtouch'), {resolverSequence: sequence});
    this.browser.on('serviceUp', function(service) {
        service.ip = service.addresses[0];
        service.mac_address = service.txtRecord.MAC;
        var deviceAPI = new SoundTouchAPI(service);
        discovery.addDevice(deviceAPI);
        if (callbackUp != undefined) {
            callbackUp(deviceAPI);
        }

    });
    this.browser.on('serviceDown', function(service) {
        discovery.deleteDevice(service);
        if (callbackDown != undefined) {
            callbackDown(service);
        }
    });
github emilisto / hook.io-mdns / lib / mdns.js View on Github external
mDNSHook.prototype.connect = function(options, callback) {
  var self = this;
  var browser = mdns.createBrowser(defaults['mdns-regtype']);

  var timer = setTimeout(function() {
    // Stop listening for services, important for app
    // to not enter an infinite loop
    browser.stop();

    if(callback) callback(new Error('Unable to connect'));
  }, defaults['mdns-listen-timeout']);


  var _connect = function(host, port) {
    browser.stop();

    options = options || {};
    options['hook-host'] = host;
    options['hook-port'] = port;
github hongkongkiwi / node-apple-tv-remote / lib / server / RemoteServer.js View on Github external
this.mdns_options = {
    name: 'Node Server',
    txtRecord: {
      DvTy: 'Node-Server',
      txtvers: '1',
    }};

  this.ads = [
    mdns.createAdvertisement(mdns.tcp(this.options.bonjourTouchableServerService), this.options.listenPort, this.mdns_options),
    mdns.createAdvertisement(mdns.tcp(this.options.bonjourDACPServerService), this.options.listenPort, this.mdns_options)
  ];

  this.app = express();

  this.browser = mdns.createBrowser(mdns.tcp(this.options.bonjourClientService));

  this.guids = {}; // Lets save/load this to disk
  this.sessionIds = {};
  this.lastSessionId = 0;

  // Add Command Routes
  require('./RemoteServerCommands')(this);
};
github dkundel / spotify-chromecast-api / index.js View on Github external
const bodyParser = require('body-parser');
const mdns = require('mdns');
const Client = require('castv2-client').Client;
const DefaultMediaReceiver = require('castv2-client').DefaultMediaReceiver;
const request = require('request');
const os = require('os');
const fs = require('fs');
const path = require('path');
const querystring = require('querystring');

const PORT = process.env.PORT || 3000;
const app = express();
const devices = new Map();
let playlist = [];

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

function deviceRegister(name, address, port) {
  let id = devices.size;
  let client = new Client();

  return new Promise((resolve, reject) => {
    client.connect(address, () => {
      client.launch(DefaultMediaReceiver, (err, player) => {
        if (err) {
          reject(err);
          return;
        }

        devices.set(id, { name, address, port, client, player });
        resolve(player);
      });
github paolotremadio / homebridge-automation-chromecast / index.js View on Github external
detectChromecast() {
    const browser = mdns.createBrowser(mdns.tcp('googlecast'), { resolverSequence: mdnsSequence });

    browser.on('serviceUp', (device) => {
      const txt = device.txtRecord;
      const name = txt.fn;

      if (name.toLowerCase() === this.chromecastDeviceName.toLowerCase()) {
        this.setDefaultProperties(true, true);

        const ipAddress = device.addresses[0];
        const { port } = device;

        this.chromecastIp = ipAddress;
        this.chromecastPort = port;

        this.deviceType = txt.md || '';
        this.deviceIp = `${ipAddress}:${port}`;
github noelportugal / google-home-notifier / google-home-notifier.js View on Github external
var Client = require('castv2-client').Client;
var DefaultMediaReceiver = require('castv2-client').DefaultMediaReceiver;
var mdns = require('mdns');
var browser = mdns.createBrowser(mdns.tcp('googlecast'));
var deviceAddress;
var language;

var device = function(name, lang = 'en') {
    device = name;
    language = lang;
    return this;
};

var ip = function(ip, lang = 'en') {
  deviceAddress = ip;
  language = lang;
  return this;
}

var googletts = require('google-tts-api');
github taeukme / google-home-push / index.js View on Github external
"use strict";

const GoogleCastClient = require("castv2-client").Client;
const DefaultMediaReceiver = require("castv2-client").DefaultMediaReceiver;
const mdns = require("mdns");
const browser = mdns.createBrowser(mdns.tcp("googlecast"));
const googleTTS = require("google-tts-api");
const isIp = require("is-ip");

class GoogleHome {
  constructor(deviceIdentifier, options = {}) {
    this.device = {};

    if (isIp(deviceIdentifier)) {
      this.device.ip = deviceIdentifier;
    } else {
      this.device.name = deviceIdentifier;
    }
    this.device.identifier = deviceIdentifier;

    this.options = options;