Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
const findDevices = () => {
/* Look for mDNS Cast devices on local network */
let browser = mdns.createBrowser(mdns.tcp('googlecast'))
/* Only scan IPv4 addresses */
mdns.Browser.defaultResolverSequence[1] =
'DNSServiceGetAddrInfo' in mdns.dns_sd
? mdns.rst.DNSServiceGetAddrInfo()
: mdns.rst.getaddrinfo({ families: [4] })
browser.on('serviceUp', service => {
// service.name: Chromecast-hexadecimalid
let _id = service.name.split('-'),
id = _id.pop()
// fix for groups with IDs that resemble Google-Cast-Group-{deviceId}-1
while (_id.length > 0 && id.length < 3) id = _id.pop()
/* If device is registered, append local statistics */
if (func.isRegistered(id)) {
func.update(id, {
name: service.txtRecord.fn,
address: service.addresses[0],
port: service.port
})
ControllerVolumioDiscovery.prototype.startMDNSBrowse=function()
{
var self=this;
try
{
var serviceName=config.get('service');
var servicePort=config.get('port');
var sequence = [
mdns.rst.DNSServiceResolve()
, mdns.rst.getaddrinfo({families: [4] })
];
self.browser = mdns.createBrowser(mdns.tcp(serviceName),{resolverSequence: sequence});
self.browser.on('error',function(error){
self.context.coreCommand.pushConsoleMessage('mDNS Browse raised the following error ' + error);
// Do not start mdns browser, since it will duplicate its instance
// Find a way to reinstantiate, if possible
//self.startMDNSBrowse();
});
self.browser.on('serviceUp', function(service) {
if (registeredUUIDs.indexOf(service.txtRecord.UUID) > -1) {
console.log("Discovery: this is already registered, " + service.txtRecord.UUID);
foundVolumioInstances.delete(service.txtRecord.UUID+'.name');
self.remoteConnections.remove(service.txtRecord.UUID+'.name');
function MdnsNode(n) {
var mdns = require('mdns');
if (process.platform === "linux") {
RED.log.info("You may ignore the warning about Bonjour compatability.");
}
RED.nodes.createNode(this, n);
this.topic = n.topic || "";
this.service = n.service;
var node = this;
// var sequence = [
// mdns.rst.DNSServiceResolve(),
// mdns.rst.getaddrinfo({families: [4] })
// ];
// var browser = mdns.createBrowser(this.service,{resolverSequence: sequence});
var sequence = [
mdns.rst.DNSServiceResolve(),
'DNSServiceGetAddrInfo' in mdns.dns_sd ? mdns.rst.DNSServiceGetAddrInfo() : mdns.rst.getaddrinfo({families:[4]}),
mdns.rst.makeAddressesUnique()
];
var browser = mdns.createBrowser((this.service), {resolverSequence:sequence});
browser.on('serviceUp', function(service) {
if (RED.settings.verbose) { node.log("here : " + service.name); }
service.state = true;
var msg = {topic:node.topic, payload:service};
node.send(msg);
});
browser.on('serviceDown', function(service) {
if (RED.settings.verbose) { node.log("away : " + service.name); }
service.state = false;
var msg = {topic:node.topic, payload:service};
node.send(msg);
function Scanner(options) {
var self = this,
family = (options || {}).family || 0, // UNSPEC, can also use 4 or 6.
sequence = [
mdns.rst.DNSServiceResolve(),
'DNSServiceGetAddrInfo' in mdns.dns_sd ? mdns.rst.DNSServiceGetAddrInfo() : mdns.rst.getaddrinfo({families:[family]}),
mdns.rst.makeAddressesUnique()
];
events.EventEmitter.call(this);
options = options || {};
this.logger = options.logger || logger.devnull;
this.timeout = options.timeout || 5000;
this.reconnect = options.reconnect || {};
this.browser = mdns.createBrowser(mdns.tcp('googlecast'),
{resolverSequence: sequence});
this.browser
.on('serviceUp', onServiceUp)
.on('serviceDown', onServiceDown);
this.devices = [];
function onServiceUp(device) {
.action(function () {
console.log("Searching for connected devices...");
var sequence = [
mdns.rst.DNSServiceResolve(),
'DNSServiceGetAddrInfo' in mdns.dns_sd ? mdns.rst.DNSServiceGetAddrInfo({families:[0]}) : mdns.rst.getaddrinfo({families:[0]}),
mdns.rst.makeAddressesUnique()
];
var browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence});
browser.on('serviceUp', function(service) {
if (service.port == statusDebugServerPort) {
console.log(chalk.green(chalk.bold(service.name) + " (" + service.addresses.join(", ") + ")"));
}
});
browser.start();
});
.action(function () {
console.log("Searching for connected devices...");
var sequence = [
mdns.rst.DNSServiceResolve(),
'DNSServiceGetAddrInfo' in mdns.dns_sd ? mdns.rst.DNSServiceGetAddrInfo({families:[0]}) : mdns.rst.getaddrinfo({families:[0]}),
mdns.rst.makeAddressesUnique()
];
var browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence});
browser.on('serviceUp', function(service) {
if (service.port == statusDebugServerPort) {
console.log(chalk.green(chalk.bold(service.name) + " (" + service.addresses.join(", ") + ")"));
}
});
browser.start();
});