Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
MDNSRegistrar.prototype.browse = function() {
// the serice a node browses for depends on the type of the node
/* create the browser */
var browser;
var self = this;
if (this.machType === constants.globals.NodeType.DEVICE) {
// devices browse for fogs
browser = mdns.createBrowser(mdns.tcp(this.app + '-' + constants.globals.NodeType.FOG));
browser.on('serviceUp', function(service) {
/* emit the id, port, and IP address of the fog to the rest of the application */
// possible that _getIp returns null
var fogIp = self._getIp(service.addresses);
if (fogIp === null) {
// ignore the fog
// TODO might want to modify this behavior
return;
}
var retVal = {
port: service.port, // int
ip: fogIp, // string
id: service.name // string
};
self.emit('fog-up', retVal);
});
if (IS_HEX_STRING.test(settings.uuid) === false) {
throw new TypeError('service uuid must be a hex string');
}
// helps handling fast close
this._closed = false;
// Collection of online sockets
this.connections = [];
// Add connection handler if given
if (connectionHandler) this.on('connection', connectionHandler);
// Contains unique ID and a service key (given by service name)
this._uuid = settings.uuid;
this._key = mdns.tcp(settings.name);
// Collection of services
this._services = [];
this._serviceBuffer = [];
// Keeps addresses and port
this._address = {
addresses: null,
port: null
};
// do the service listen on localhost
this._internalAllowed = false;
this._relayError = function (err) {
self.emit('error', err);
bonjourClientService: 'touch-remote',
bonjourTouchableServerService: 'touch-able',
bonjourDACPServerService: 'dacp',
guidLength: 16,
persistGuids: true
}, options);
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);
};
wsConnections.forEach(wsConnection => wsConnection.close());
}
bonjour.unpublishAll(() => {
//bonjour.destroy()
});
if (mdnsAd) {
mdnsAd.stop();
}
})
try {
var mdns = require('mdns');
mdnsAd = mdns.createAdvertisement(mdns.tcp('http'), port, {
name: 'Barcode to PC server - ' + getNumber()
});
mdnsAd.start();
} catch (ex) {
dialog.showMessageBox(mainWindow, {
type: 'warning',
title: 'Error',
message: 'Apple Bonjour is missing.\nThe app may fail to detect automatically the server.\n\nTo remove this alert try to install Barcode to PC server again an reboot your system.',
});
var bonjourService = bonjour.publish({ name: 'Barcode to PC server - ' + getNumber(), type: 'http', port: port })
bonjourService.on('error', err => { // err is never set?
dialog.showMessageBox(mainWindow, {
type: 'error',
title: 'Error',
}).listen(function () {
var ad = mdns.createAdvertisement(mdns.tcp('tomatotomato'), server.address().port)
, msg = 'server running on ' + networkAddress() + ':' + server.address().port
console.log(chalk.blue(msg))
ad.start()
})
function _initBroadcast (config) {
var ad = mdns.createAdvertisement(mdns.tcp(config.server.serviceName), config.server.port)
ad.start()
}