Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.info("Discovery request ignored, since other discovery is active");
return;
}
node.status({fill:"yellow",shape:"dot",text:"discovering"});
node.counter = 0;
node.discovering = true;
var options = {
timeout: node.timeout, // Discovery should end after the specified timeout
resolve: false // Return discovered devices as data objects, instead of Cam instances
};
// Start discovery of the ONVIF network devices.
// The callback function will be called only once, when the broadcast is finished (after the timeout).
onvif.Discovery.probe(options, function(err, result) {
if (err) {
console.error(err.message);
node.status({fill:"red",shape:"dot",text: "failed"});
}
else {
node.status({fill:"green",shape:"dot",text: "completed (" + node.counter + "x)"});
}
if (!node.separate) {
var devices = [];
// Convert the array to an easy format
for (var i = 0; i < result.length; i++) {
devices.push(simplifyResult(result[i]));
}
return probeMatch;
}
function handleResult(result) {
node.counter++;
if (node.separate) {
// Send a separate output message for every discovered OnVif-compliant IP device
node.send({payload: simplifyResult(result)});
}
}
// Register once a listener for device events.
// The callback function will be called immediately when a device responses.
onvif.Discovery.on('device', handleResult);
node.on("input", function(msg) {
if (node.discovering) {
console.info("Discovery request ignored, since other discovery is active");
return;
}
node.status({fill:"yellow",shape:"dot",text:"discovering"});
node.counter = 0;
node.discovering = true;
var options = {
timeout: node.timeout, // Discovery should end after the specified timeout
resolve: false // Return discovered devices as data objects, instead of Cam instances
};
OnvifManager.prototype.discoverDevices = function(callback) {
console.log("Hello OnvifManager!");
onvif.Discovery.probe(function(err, cams) {
if(err) { throw err; }
cams.forEach(function(cam) {
//FIXME: this user/pass info is just a test
cam.username = 'admin';
cam.password = 'xsVLX842';
cam.connect(function(err) {
if (err) {throw err;}
cam.getDeviceInformation(function(err, info, xml) {
if (err) {throw err;}
console.log("Camera Info: " + JSON.stringify(info));
fs.readFile('./onvif.json', 'utf8', function(err, data) {
if (err) { throw err; }
var devSpec = JSON.parse(data);
devSpec.device.friendlyName = info.manufacturer;
devSpec.device.manufacturer = info.manufacturer;
app.get('/search', function (req, res) {
onvif.Discovery.probe(function (err, cams) {
if (err) {
console.log(err);
res.send({ result: false });
return;
}
searchForNextTick(res, [], cams, 0);
});
});
app.use(express.static('html'));