Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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");
});