Skip to content

Commit

Permalink
Merge f4de4b5 into 2a7f9fe
Browse files Browse the repository at this point in the history
  • Loading branch information
bl0ggy committed Feb 20, 2020
2 parents 2a7f9fe + f4de4b5 commit 721e7ed
Showing 1 changed file with 52 additions and 19 deletions.
71 changes: 52 additions & 19 deletions lib/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,29 @@
module.exports = function(Cam) {
const linerase = require('./utils').linerase;

/**
* @typedef {object} Cam~NTPManual
* @property {string} options.type Network host type: IPv4, IPv6 or DNS. - enum { 'IPv4', 'IPv6', 'DNS' }
* @property {string} [options.IPv4Address] IPv4 address
* @property {string} [options.IPv6Address] IPv6 address
* @property {string} [options.DNSname] DNS name
* @property {string} [options.extension]
*/

/**
* @typedef {object} Cam~NTPFromDHCP
* @property {string} options.type Network host type: IPv4, IPv6 or DNS. - enum { 'IPv4', 'IPv6', 'DNS' }
* @property {string} [options.IPv4Address] IPv4 address
* @property {string} [options.IPv6Address] IPv6 address
* @property {string} [options.DNSname] DNS name
* @property {string} [options.extension]
*/

/**
* @typedef {object} Cam~NTPInformation
* @property {boolean} fromDHCP Indicates if NTP information is to be retrieved by using DHCP
* @property {object} [NTPFromDHCP] List of NTP addresses retrieved by using DHCP
* @property {object} [NTPManual] List of manually entered NTP addresses
* @property {Array.<Cam~NTPFromDHCP>} [NTPFromDHCP] List of NTP addresses retrieved by using DHCP
* @property {Array.<Cam~NTPManual>} [NTPManual] List of manually entered NTP addresses
*/

/**
Expand Down Expand Up @@ -44,28 +62,43 @@ module.exports = function(Cam) {
* Set the NTP settings on a device
* @param {object} options
* @param {boolean} options.fromDHCP Indicate if NTP address information is to be retrieved using DHCP
* @param {string} [options.type] Network host type: IPv4, IPv6 or DNS.
* @param {string} [options.ipv4Address] IPv4 address
* @param {string} [options.ipv6Address] IPv6 address
* @param {string} [options.dnsName] DNS name
* @param {string} [options.extension]
* @param {Array.<Cam~NTPManual>} [options.NTPManual] List of NTP addresses
* @param {Cam~RequestCallback} [callback]
*/
Cam.prototype.setNTP = function(options, callback) {
if (!Array.isArray(options.NTPManual)) {
options.NTPManual = [];
}
// For backward compatibility
if (options.type || options.ipv4Address || options.ipv6Address || options.dnsName || options.extension) {
// Note the case changes to follow the xml parser rules
options.NTPManual.push({
type: options.type,
IPv4Address: options.ipv4Address,
IPv6Address: options.ipv6Address,
DNSname: options.dnsName,
extension: options.extension,
})
}
let body = this._envelopeHeader() +
'<SetNTP xmlns="http://www.onvif.org/ver10/device/wsdl">' +
'<FromDHCP>' + options.fromDHCP + '</FromDHCP>';
if (options.NTPManual && Array.isArray(options.NTPManual)) {
options.NTPManual.forEach((NTPManual)=>{
body += ( NTPManual.type ? '<NTPManual>' +
'<Type xmlns="http://www.onvif.org/ver10/schema">' + NTPManual.type + '</Type>' +
( NTPManual.IPv4Address ? '<IPv4Address xmlns="http://www.onvif.org/ver10/schema">' + NTPManual.IPv4Address + '</IPv4Address>' : '' ) +
( NTPManual.IPv6Address ? '<IPv6Address xmlns="http://www.onvif.org/ver10/schema">' + NTPManual.IPv6Address + '</IPv6Address>' : '' ) +
( NTPManual.DNSname ? '<DNSname>' + NTPManual.DNSname + '</DNSname>' : '' ) +
( NTPManual.extension ? '<Extension>' + NTPManual.extension + '</Extension>' : '' ) +
'</NTPManual>' : '');
});
}
body += '</SetNTP>' +
this._envelopeFooter();
this._request({
service: 'device'
, body: this._envelopeHeader() +
'<SetNTP xmlns="http://www.onvif.org/ver10/device/wsdl">' +
'<FromDHCP>' + options.fromDHCP + '</FromDHCP>' +
( options.type ? '<NTPManual>' +
'<Type xmlns="http://www.onvif.org/ver10/schema">' + options.type + '</Type>' +
( options.ipv4Address ? '<IPv4Address xmlns="http://www.onvif.org/ver10/schema">' + options.ipv4Address + '</IPv4Address>' : '' ) +
( options.ipv6Address ? '<IPv6Address xmlns="http://www.onvif.org/ver10/schema">' + options.ipv6Address + '</IPv6Address>' : '' ) +
( options.dnsName ? '<DNSname>' + options.dnsName + '</DNSname>' : '' ) +
( options.extension ? '<Extension>' + options.extension + '</Extension>' : '' ) +
'</NTPManual>' : '') +
'</SetNTP>' +
this._envelopeFooter()
, body: body
}, callback.bind(this));
};

Expand Down

0 comments on commit 721e7ed

Please sign in to comment.