Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 6 Examples of "onvif in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'onvif' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

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
            };
// TODO checken of er altijd een this.credentials bestaat, indien username en paswoord niet ingevuld is.
            
            // The client credentials will only contain the data (i.e. user name or password) which has changed.
            // The other data is not changed, so we will need use the original data stored on the server.
            clientConfig.username = clientConfig.user || this.credentials.user;
            clientConfig.password = clientConfig.password || this.credentials.password;
                    
            // When the user appends some new text to the existing password, then the original password is passed via the client as __PWRD__
            // So replace __PWRD__ again by the original password.
            if (clientConfig.password && this.credentials.password) {
               clientConfig.password.replace('___PWRD__', this.credentials.password);
            }
     
            if (this.credentials.user !== clientConfig.user || this.credentials.password !== clientConfig.password || this.xaddress !== clientConfig.hostname){
                var cam = new onvif.Cam(clientConfig, function(err) {             
                    if (!err) {
                        if (cam.profiles) {
                            for(var i = 0; i < cam.profiles.length; i++) {
                                profileNames.push({
                                    label: cam.profiles[i].name,
                                    value: cam.profiles[i].$.token
                                });
                            }
                        }
                        
                        response.json(profileNames);
                    }
                });
            }
            else {
                if (this.cam.profiles) {
return;
        }
        
        setOnvifStatus(node, "initializing");
        
        var options = {};
        options.hostname = this.xaddress;
        options.port = this.port;
        
        if (this.credentials && this.credentials.user) {
            options.username = this.credentials.user;
            options.password = this.credentials.password;
        }

        // Create a new camera instance, which will automatically connect to the device (to load configuration data)
        this.cam = new onvif.Cam(options, function(err) { 
            if (err) {
                // Make sure the Catch-node can catch the error
                node.error( err, {} );
                
                setOnvifStatus(node, "disconnected");
            }
            else {  
                setOnvifStatus(node, "connected"); 
            }
        });
        
        node.on('close', function(){
			setOnvifStatus(node, "");
            
            node.removeAllListeners("onvif_status");
		});
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'));

Is your System Free of Underlying Vulnerabilities?
Find Out Now