Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
var mdns = require('mdns'),
browser = mdns.createBrowser(mdns.tcp('ipp'));
mdns.Browser.defaultResolverSequence[1] = 'DNSServiceGetAddrInfo' in mdns.dns_sd ? mdns.rst.DNSServiceGetAddrInfo() : mdns.rst.getaddrinfo({families:[4]});
browser.on('serviceUp', function (rec) {
console.log(rec.name, 'http://'+rec.host+':'+rec.port+'/'+rec.txtRecord.rp);
});
browser.start();
//example output...
//HP LaserJet 400 M401dn (972E51) http://CP01.local:631/ipp/printer
//HP LaserJet Professional P1102w http://P1102W.local:631/printers/Laserjet
//Officejet Pro 8500 A910 [611B21] http://HPPRINTER.local:631/ipp/printer
var Client = require('castv2-client').Client;
var DefaultMediaReceiver = require('castv2-client').DefaultMediaReceiver;
var dotenv = require('dotenv');
var mdns = require('mdns');
var ngrok = require('ngrok');
var util = require('util');
var activeDevice = null;
dotenv.load();
mdns.Browser.defaultResolverSequence[1] = 'DNSServiceGetAddrInfo' in mdns.dns_sd
? mdns.rst.DNSServiceGetAddrInfo()
: mdns.rst.getaddrinfo({families:[4]});
function onDeviceUp(host, item, port) {
var media = {};
var client = new Client();
client.connect(host, function() {
client.launch(DefaultMediaReceiver, function(err, player) {
ngrok.connect({
proto: 'http',
addr: port,
host_header: 'rewrite ' + port,
bind_tls: true
}, function (err, url) {
media = {