Skip to content

Commit

Permalink
Merge 7bc082e into 6797640
Browse files Browse the repository at this point in the history
  • Loading branch information
ManjunathaN committed Jun 8, 2021
2 parents 6797640 + 7bc082e commit fa66a0c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/cam.js
Expand Up @@ -6,6 +6,7 @@
*/

const http = require('http')
, https = require('https')
, crypto = require('crypto')
, events = require('events')
, url = require('url')
Expand All @@ -29,6 +30,8 @@ const http = require('http')
/**
* Camera class
* @param {object} options
* @param {boolean} options.useSecure Set true if `https:`, defaults to false
* @param {object} options.secureOpts Set options for https like ca, cert, ciphers, rejectUnauthorized, secureOptions, secureProtocol, etc.
* @param {string} options.hostname
* @param {string} [options.username]
* @param {string} [options.password]
Expand All @@ -53,6 +56,8 @@ const http = require('http')
* Cam = require('onvif').Cam;
*
* new Cam({
* useSecure: <IS_SECURE>,
* secureOpts: {...<SECURE_OPTIONS>}
* hostname: <CAMERA_HOST>,
* username: <USERNAME>,
* password: <PASSWORD>
Expand All @@ -71,10 +76,12 @@ const http = require('http')
var Cam = function(options, callback) {
events.EventEmitter.call(this);
callback = callback || emptyFn;
this.useSecure = options.useSecure || false;
this.secureOpts = options.secureOpts || {};
this.hostname = options.hostname;
this.username = options.username;
this.password = options.password;
this.port = options.port || 80;
this.port = options.port || (options.useSecure ? 443 : 80);
this.path = options.path || '/onvif/device_service';
this.timeout = options.timeout || 120000;
this.agent = options.agent || false;
Expand Down Expand Up @@ -216,7 +223,12 @@ Cam.prototype._request = function(options, callback) {
};

reqOptions.method = 'POST';
var req = http.request(reqOptions, function(res) {
var httpLib = http;
if (this.useSecure) {
httpLib = https;
reqOptions = Object.assign({}, this.secureOpts, reqOptions);
}
var req = httpLib.request(reqOptions, function(res) {
var bufs = [], length = 0;
res.on('data', function(chunk) {
bufs.push(chunk);
Expand Down

0 comments on commit fa66a0c

Please sign in to comment.