Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env node
// var wemore = require('./');
// wemore.Discover()
// .on('device', function(device) {
// if (device.friendlyName == 'television'
// || device.friendlyName == 'playstation') {
// console.log(device);
// }
// });
var SsdpClient = require('node-ssdp').Client
// , BELKIN_CONTROLLEE = "urn:Belkin:device:controllee:1"
, BELKIN_CONTROLLEE = "urn:Belkin:device:**"
;
var client = new SsdpClient({logLevel: 'TRACE'});
client.on('response', function(resp) {
console.log(resp);
});
client.search(BELKIN_CONTROLLEE);
var Client = require('node-ssdp').Client;
let client = new Client();
let getRenderers = () => {
let servers = [];
let findRenderers = () => {
var parent = document.getElementById('divMain');
client.on('response', function (headers, statusCode, rinfo) {
console.log('Got a response to an m-search.');
var newDiv = document.createElement('div');
var newContent = document.createTextNode(headers['LOCATION']);
newDiv.appendChild(newContent); //add the text node to the newly created div.
// add the newly created element and its content into the DOM
//var currentDiv = document.getElementById('divMain');
parent.appendChild(newDiv);
servers.push(headers);
dlna.bestMatches.push(el[0]);
// if (ij == 3) return true;
}
});
if (dlna.bestMatches.length) {
dlna.checkedPorts = [];
dlna.tryKnown();
} else player.setOpeningText("Error: Nothing Found");
}
},10000);
$(".wcp-dlna-buttons").show(0);
var Client = require('node-ssdp').Client
, client = new Client();
client.on('response', function (headers, statusCode, rinfo) {
// console.log(headers);
if (headers["LOCATION"]) {
dlna.instance.clients.push(headers["LOCATION"]);
}
if (dlna.instance.clients.length == 1){
if (headers["SERVER"]) dlna.instance.serverName = headers["SERVER"]; // remember the server name
// console.log(headers["SERVER"]);
dlna.findMyIp(); // remove this line for select device menu
}
});
// uncomment this line for select device menu
// setTimeout(function() { checkClients(); },1000);
var search = function (SSDPSearchString, options) {
options = options || {};
options.SSDPTimeout = options.SSDPTimeout || 2*1000;
var deferred = Q.defer();
var SSDPClient = require('node-ssdp').Client,
client = new SSDPClient(),
responses = [];
client.on('response', function (headers, statusCode, rinfo) {
// Split on line breaks ("/r/n"):
var headersFormatted = headers.split( String.fromCharCode(13, 10) );
// Extract the headers:
var headersParsed = {};
for (var i = 0, nbHeaders = headersFormatted.length; i < nbHeaders; i++) {
var item = headersFormatted[i];
var firstColonIndex = item.indexOf(':');
if (firstColonIndex > -1) {
var key = item.substring(0, firstColonIndex);
var value = item.substring(firstColonIndex + 1, item.length).trim();
var details = function (req, res) {
var SSDPClient = require('node-ssdp').Client,
client = new SSDPClient(),
SSDPResponses = [];
client.on('response', function (headers, statusCode, rinfo) {
// Split on line breaks ("/r/n"):
var headersFormatted = headers.split( String.fromCharCode(13, 10) );
// Extract the headers:
var headersParsed = {};
for (var i = 0, nbHeaders = headersFormatted.length; i < nbHeaders; i++) {
var item = headersFormatted[i];
var firstColonIndex = item.indexOf(':');
if (firstColonIndex > -1) {
var key = item.substring(0, firstColonIndex);
var value = item.substring(firstColonIndex + 1, item.length).trim();
Sonos.prototype.scanforComponents = function() {
if (!ssdp) return;
var client = new ssdp.Client();
var timeout;
client.on('response', function (headers, statusCode, rinfo) {
var host = rinfo.address;
if (this.discoveredIps.indexOf(host) == -1) {
this.discoveredIps.push(host);
if (headers["ST"] != Sonos.PLAYER_UPNP_URN) return;
if (!headers["LOCATION"]) return;
this.createComponent(host);
}
}.bind(this));
// search periodcally
function scanDevices() {
if (this.debug) console.log("Scanning for sonos");
client.search(Sonos.PLAYER_UPNP_URN);
clearTimeout(timeout);
console.log("smartserver:G_DeviceProperties: exception reading " + fName + " error=" + err);
return null;
}
}
try {
return JSON.parse(data);
} catch (exc) {
console.log("smartserver:G_DeviceProperties: exception parsing json " + fName + " data=" + data + " exception=" + exc);
return null;
}
})();
console.log("smartserver:G_DeviceProperties=" + JSON.stringify(G_deviceProperties));
if (gTEST){
console.log("Trying to get ssdps")
var SSDPClient = require('node-ssdp').Client;
var client = new SSDPClient({ allowWildcards:false});
var searchString = 'urn:schemas-upnp-org:device*';
client.on('response', function (response) {
if (response.ST == searchString)
console.log("response st=" + response.ST + " location=" + response.LOCATION +"\t usn=" + response.USN )
});
client.on('notify', function () {
console.log('Got a notification.')
})
// search for a service type
//client.search('urn:schemas-upnp-org:device:SmartBridge*');
//"urn:schemas-upnp-org:device:SmartBridge:1"
//client.search("schemas-upnp-org:device:SmartBridge:1");
//client.search('schemas-upnp-org:device:Smart*');
//client.search('urn:schemas-upnp-org:device:RFXDevice:1')
//urn:schemas-upnp-org:device
client.search(searchString);
return new Promise((resolve, reject) => {
const timerRef = setTimeout(() => {
if (typeof callback === 'function') callback(devices)
resolve(devices)
}, opts.duration || 2500)
const client = new Client()
client.search('ssdp:all')
client.on('response', (headers, statusCode, rinfo) => {
const searchTarget = headers.ST
if (!(searchTarget.match(/^bigfoot:/) || {}).input) {
return // Do nothing
}
// Enable to hunt only one device
if (opts.id === headers.USN) {
clearTimeout(timerRef)
return resolve(parseResponse(headers, statusCode, rinfo))
}
devices = {
...devices,
Discovery.prototype.close = function() {
// hax?
if (this.client) {
this.client._stop();
}
// create a new one (apparently they're one-use only)
this.client = new SsdpClient();
this.client.on('response', this._onResponse.bind(this));
};
return new Promise((resolve, reject) => {
const client = new nodeSSDPClient();
// Open the flood gates
const intervalId = setInterval(() => {
client.search('ssdp:all');
}, 1000);
// Discovery timeout for roku device; default 10000ms
const timeoutId = setTimeout(() => {
clearInterval(intervalId);
clearTimeout(timeoutId);
return reject(new Error(`Could not find any Roku devices. Time spent: ${timeout / 1000} seconds`));
}, timeout);
client.on('response', headers => {
if (self.debug) {