'use strict';
//region 1. Platform Libraries
const ipaddr = require('ipaddr.js');
//endregion
const isValidStreamIndex = index => Number.isInteger(Number(index)) && Number(index) >= 0;
const isWithinValidPublicIpRange = publicIp => {
const range = ipaddr.parse(publicIp).range();
return !(range === 'broadcast' || range === 'linkLocal' || range === 'loopback' || range === 'multicast' || range === 'private' || range === 'reserved' || range === 'unspecified');
};
const isValidPublicIP = ip => {
if (!ip) {
return new Error('No Public IP');
}
if (!ipaddr.isValid(ip)) {
return new Error(`Malformed Public IP ${ ip }`);
}
if (!isWithinValidPublicIpRange(ip)) {
return new Error(`Public IP in Invalid Range ${ ip }`);
}
return true;
};
const stripUndefined = obj => {
const result = obj;
Object.keys(result).forEach(key => {
if (result[key] && typeof result[key] === 'object') {
stripUndefined(result[key]);
} else if (result[key] === undefined) {
delete result[key];
}
});
return result;
};
const valueOf = (obj, ...args) => {
Iif (!obj) return null;
const context = { obj };
for (let i = 0; i < args.length; i++) {
Iif (!{}.hasOwnProperty.call(context.obj, args[i])) return undefined;
context.obj = context.obj[args[i]];
}
return context.obj;
};
module.exports = {
GetNested(obj) {
// TODO: Deprecated. Remove when possible.
if (!obj) return null;
for (var i = 1; i < arguments.length; i++) {
if (!obj.hasOwnProperty(arguments[i])) {
return undefined;
}
obj = obj[arguments[i]];
}
return obj;
},
isValidStreamIndex,
isValidPublicIP,
isWithinValidPublicIpRange,
stripUndefined,
valueOf
};
/**
* @typedef {object} Router
* @property {*} use
* @property {*} post
* @property {*} get
* @property {*} put
* @property {*} delete
*/
/**
* @typedef {object} RateControl
* @property {number} bitrate_limit
* @property {number} frame_rate_limit
*/
/**
* @typedef {object} H264
* @property {string} h264_profile
* @property {number} gov_length
*/
/**
* @typedef {object} VideoInfo
* @property {number} index
* @property {*} start_time
* @property {*} end_time
* @property {string} bucket_name
* @property {string} object_name
*/
/**
* @typedef {object} Stream
* @property {string} rtsp_url
* @property {number} trigger_idle_duration
* @property {number} trigger_prealarm_duration
* @property {number} trigger_video_duration
* @property {RateControl} rate_control
* @property {H264} h264
* @property {VideoInfo} video_info
* @property {string[]} triggered_streams
*/
/**
* @typedef {object} Camera
* @property {string} username
* @property {string} password
* @property {string} public_address
* @property {number} web_port
*/
//# sourceMappingURL=Utils.js.map |