Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support: Imaging #544

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dist/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ class Camera {
if (this.ptz) {
this.ptz.setDefaultProfileToken(profile.$.token);
}

if (this.imaging) {
this.imaging.setDefaultProfileToken(profile.VideoSourceConfiguration.SourceToken);
}
}
});
return profileList;
Expand Down
4 changes: 2 additions & 2 deletions dist/modules/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ class Discovery {
if (typeof probeMatch.Types === 'string') {
types = probeMatch.Types.split(/\s+/);
} else if (typeof probeMatch.Types === 'object' && typeof probeMatch.Types._ === 'string') {
types = probeMatch.Types._.split(/\s+/);
}
types = probeMatch.Types._.split(/\s+/);
}
}
}
}
Expand Down
155 changes: 146 additions & 9 deletions dist/modules/imaging.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
const Soap = require('../utils/soap');

const Util = require('../utils/util');

class Imaging {
constructor() {
this.soap = new Soap();
this.timeDiff = 0;
this.serviceAddress = null;
this.username = null;
this.password = null;
this.namespaceAttributes = ['xmlns:tns1="http://www.onvif.org/ver10/topics"', 'xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl"'];
this.defaultProfileToken = null;
this.namespaceAttributes = ['xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl"', 'xmlns:tt="http://www.onvif.org/ver10/schema"'];
}

init(timeDiff, serviceAddress, username, password) {
Expand All @@ -17,27 +20,161 @@ class Imaging {
this.password = password;
}

setDefaultProfileToken(profileToken) {
this.defaultProfileToken = profileToken;
}

createRequest(body) {
const soapEnvelope = this.soap.createRequest({
return this.soap.createRequest({
body: body,
xmlns: this.namespaceAttributes,
diff: this.timeDiff,
username: this.username,
password: this.password
});
return soapEnvelope;
}

getImagingSettings() {
return new Promise((resolve, reject) => {
reject(new Error('Not implemented'));
buildRequest(methodName, xml, callback) {
const promise = new Promise((resolve, reject) => {
let errMsg = '';

if (typeof callback !== 'undefined' && callback !== null) {
if (errMsg = Util.isInvalidValue(callback, 'function')) {
reject(new Error(`The "callback" argument for ${methodName} is invalid:` + errMsg));
return;
}
}

if (typeof methodName === 'undefined' || methodName === null) {
reject(new Error('The "methodName" argument for buildRequest is required.'));
return;
} else {
if (errMsg = Util.isInvalidValue(methodName, 'string')) {
reject(new Error('The "methodName" argument for buildRequest is invalid:' + errMsg));
return;
}
}

let soapBody = '';

if (typeof xml === 'undefined' || xml === null || xml === '') {
soapBody += `<timg:${methodName}/>`;
} else {
soapBody += `<timg:${methodName}>`;
soapBody += xml;
soapBody += `</timg:${methodName}>`;
}

const soapEnvelope = this.createRequest(soapBody);
this.soap.makeRequest('imaging', this.serviceAddress, methodName, soapEnvelope).then(results => {
resolve(results);
}).catch(error => {
reject(error);
});
});

if (Util.isValidCallback(callback)) {
promise.then(results => {
callback(null, results);
}).catch(error => {
callback(error);
});
} else {
return promise;
}
}

setImagingSettings() {
return new Promise((resolve, reject) => {
reject(new Error('Not implemented'));
getImagingSettings(profileToken, callback) {
const promise = new Promise((resolve, reject) => {
profileToken = profileToken || this.defaultProfileToken;
let errMsg = '';

if (typeof callback !== 'undefined' && callback !== null) {
if (errMsg = Util.isInvalidValue(callback, 'function')) {
reject(new Error('The "callback" argument for getImagingSettings is invalid:' + errMsg));
return;
}
}

if (errMsg = Util.isInvalidValue(profileToken, 'string')) {
reject(new Error('The "profileToken" argument for getImagingSettings is invalid: ' + errMsg));
return;
}

let soapBody = '';
soapBody = '<timg:VideoSourceToken>' + profileToken + '</timg:VideoSourceToken>';
this.buildRequest('GetImagingSettings', soapBody).then(results => {
resolve(results);
}).catch(error => {
reject(error);
});
});

if (Util.isValidCallback(callback)) {
promise.then(results => {
callback(null, results);
}).catch(error => {
callback(error);
});
} else {
return promise;
}
}

setImagingSettings(profileToken, options, callback) {
const promise = new Promise((resolve, reject) => {
profileToken = profileToken || this.defaultProfileToken;
let errMsg = '';

if (typeof callback !== 'undefined' && callback !== null) {
if (errMsg = Util.isInvalidValue(callback, 'function')) {
reject(new Error('The "callback" argument for getImagingSettings is invalid:' + errMsg));
return;
}
}

if (errMsg = Util.isInvalidValue(profileToken, 'string')) {
reject(new Error('The "profileToken" argument for getImagingSettings is invalid: ' + errMsg));
return;
}

let soapBody = '';
soapBody = '<timg:VideoSourceToken>' + profileToken + '</timg:VideoSourceToken>';
soapBody += '<timg:ImagingSettings>';

if (typeof options.Brightness !== 'undefined' && options.Brightness !== null) {
soapBody += '<tt:Brightness>' + parseFloat(options.Brightness) + '</tt:Brightness>';
}

if (typeof options.ColorSaturation !== 'undefined' && options.ColorSaturation !== null) {
soapBody += '<tt:ColorSaturation>' + parseFloat(options.ColorSaturation) + '</tt:ColorSaturation>';
}

if (typeof options.Contrast !== 'undefined' && options.Contrast !== null) {
soapBody += '<tt:Contrast>' + parseFloat(options.Contrast) + '</tt:Contrast>';
}

if (typeof options.Sharpness !== 'undefined' && options.Sharpness !== null) {
soapBody += '<tt:Sharpness>' + parseFloat(options.Sharpness) + '</tt:Sharpness>';
}

soapBody += '</timg:ImagingSettings>';
this.buildRequest('SetImagingSettings', soapBody).then(results => {
resolve(results);
}).catch(error => {
reject(error);
});
});

if (Util.isValidCallback(callback)) {
promise.then(results => {
callback(null, results);
}).catch(error => {
callback(error);
});
} else {
return promise;
}
}

getOptions() {
Expand Down
37 changes: 37 additions & 0 deletions dist/modules/ptz.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,43 @@ class Ptz {
}
}

getPtzTours(profileToken, callback) {
const promise = new Promise((resolve, reject) => {
profileToken = profileToken || this.defaultProfileToken;
let errMsg = '';

if (typeof callback !== 'undefined' && callback !== null) {
if (errMsg = Util.isInvalidValue(callback, 'function')) {
reject(new Error('The "callback" argument for getPresets is invalid:' + errMsg));
return;
}
}

if (errMsg = Util.isInvalidValue(profileToken, 'string')) {
reject(new Error('The "profileToken" argument for getPresets is invalid: ' + errMsg));
return;
}

let soapBody = '';
soapBody += '<tptz:ProfileToken>' + profileToken + '</tptz:ProfileToken>';
this.buildRequest('GetPresetTours', soapBody).then(results => {
resolve(results);
}).catch(error => {
reject(error);
});
});

if (Util.isValidCallback(callback)) {
promise.then(results => {
callback(null, results);
}).catch(error => {
callback(error);
});
} else {
return promise;
}
}

}

module.exports = Ptz;
6 changes: 6 additions & 0 deletions dist/onvif-nvt.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class OnvifManager {
constructor() {
this.discovery = null;
this.cameras = {};
this.timeout = null;
}

add(name) {
Expand Down Expand Up @@ -61,6 +62,11 @@ class OnvifManager {
}
}

setTimeout(timeout) {
this.timeout = parseInt(timeout);
return this;
}

}

module.exports = new OnvifManager();
7 changes: 7 additions & 0 deletions dist/utils/soap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const Request = require('request');

const Config = require('./config');

const Manager = require('../onvif-nvt');

class Soap {
constructor() {
this.username = '';
Expand Down Expand Up @@ -185,6 +187,11 @@ class Soap {
sendImmediately: false
}
};

if (Manager.timeout > 0) {
options.timeout = Manager.timeout;
}

Request(options, (error, response, body) => {
if (error) {
console.error(error);
Expand Down
8 changes: 4 additions & 4 deletions dist/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ function isInvalidValue(value, type, allowEmpty) {
if (value.match(/[^\x20-\x7e]/)) {
return ' The value must consist of ascii characters.';
} else if (type !== 'xml' && value.match(/[\<\>]/)) {
return ' Invalid characters were found in the value ("<", ">")';
} else if (type === 'xml' && !value.match(/[\<\>]/)) {
return ' Valid characters were found in the value for xml ("<", ">")';
}
return ' Invalid characters were found in the value ("<", ">")';
} else if (type === 'xml' && !value.match(/[\<\>]/)) {
return ' Valid characters were found in the value for xml ("<", ">")';
}
}

return '';
Expand Down
2 changes: 1 addition & 1 deletion docs/Access.html
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Access.ht
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Jun 11 2021 11:44:06 GMT-0600 (Mountain Daylight Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Sep 17 2021 12:22:59 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/AccessRules.html
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Access.ht
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Jun 11 2021 11:44:06 GMT-0600 (Mountain Daylight Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Sep 17 2021 12:22:59 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Action.html
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Access.ht
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Jun 11 2021 11:44:06 GMT-0600 (Mountain Daylight Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Sep 17 2021 12:22:59 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -3168,7 +3168,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Access.ht
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Jun 11 2021 11:44:06 GMT-0600 (Mountain Daylight Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Sep 17 2021 12:22:59 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions docs/Camera.html
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ <h4 class="name" id="getProfiles"><span class="type-signature"></span>getProfile

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="camera.js.html">camera.js</a>, <a href="camera.js.html#line572">line 572</a>
<a href="camera.js.html">camera.js</a>, <a href="camera.js.html#line575">line 575</a>
</li></ul></dd>


Expand Down Expand Up @@ -1086,7 +1086,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Access.ht
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Jun 11 2021 11:44:06 GMT-0600 (Mountain Daylight Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Sep 17 2021 12:22:59 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Core.html
Original file line number Diff line number Diff line change
Expand Up @@ -8316,7 +8316,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Access.ht
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Jun 11 2021 11:44:06 GMT-0600 (Mountain Daylight Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Sep 17 2021 12:22:59 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Credential.html
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Access.ht
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Jun 11 2021 11:44:06 GMT-0600 (Mountain Daylight Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Sep 17 2021 12:22:59 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/DeviceIO.html
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Access.ht
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Jun 11 2021 11:44:06 GMT-0600 (Mountain Daylight Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Fri Sep 17 2021 12:22:59 GMT+0200 (Central European Summer Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading