Skip to content

Commit

Permalink
Merge d826695 into 6797640
Browse files Browse the repository at this point in the history
  • Loading branch information
ManjunathaN committed Jun 8, 2021
2 parents 6797640 + d826695 commit 09f9ddb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/cam.js
Original file line number Diff line number Diff line change
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,7 @@ const http = require('http')
/**
* Camera class
* @param {object} options
* @param {boolean} options.isSecure Set true if `https:`, defaults to false
* @param {string} options.hostname
* @param {string} [options.username]
* @param {string} [options.password]
Expand All @@ -53,6 +55,7 @@ const http = require('http')
* Cam = require('onvif').Cam;
*
* new Cam({
* isSecure: <IS_SECURE>,
* hostname: <CAMERA_HOST>,
* username: <USERNAME>,
* password: <PASSWORD>
Expand All @@ -71,10 +74,11 @@ const http = require('http')
var Cam = function(options, callback) {
events.EventEmitter.call(this);
callback = callback || emptyFn;
this.isSecure = options.isSecure || false;
this.hostname = options.hostname;
this.username = options.username;
this.password = options.password;
this.port = options.port || 80;
this.port = options.port || (options.isSecure ? 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 +220,8 @@ Cam.prototype._request = function(options, callback) {
};

reqOptions.method = 'POST';
var req = http.request(reqOptions, function(res) {
var httpLib = this.isSecure ? https : http;
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 09f9ddb

Please sign in to comment.