camstreamerlib 1.7.6 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,8 @@
3
3
  import * as EventEmitter from 'events';
4
4
  export declare type CamOverlayOptions = {
5
5
  protocol?: string;
6
+ tls?: boolean;
7
+ tlsInsecure?: boolean;
6
8
  ip?: string;
7
9
  port?: number;
8
10
  auth?: string;
@@ -48,7 +50,8 @@ export declare type ServiceList = {
48
50
  services: Service[];
49
51
  };
50
52
  export declare class CamOverlayAPI extends EventEmitter {
51
- private protocol;
53
+ private tls;
54
+ private tlsInsecure;
52
55
  private ip;
53
56
  private port;
54
57
  private auth;
@@ -82,4 +85,5 @@ export declare class CamOverlayAPI extends EventEmitter {
82
85
  updateInfoticker(text: string): Promise<void>;
83
86
  setEnabled(enabled: boolean): Promise<void>;
84
87
  isEnabled(): Promise<boolean>;
88
+ private getBaseVapixConnectionParams;
85
89
  }
package/CamOverlayAPI.js CHANGED
@@ -16,16 +16,20 @@ const Digest_1 = require("./Digest");
16
16
  const HTTPRequest_1 = require("./HTTPRequest");
17
17
  class CamOverlayAPI extends EventEmitter {
18
18
  constructor(options) {
19
- var _a, _b, _c, _d, _e, _f, _g;
19
+ var _a, _b, _c, _d, _e, _f, _g, _h;
20
20
  super();
21
21
  this.ws = null;
22
- this.protocol = (_a = options === null || options === void 0 ? void 0 : options.protocol) !== null && _a !== void 0 ? _a : 'ws';
23
- this.ip = (_b = options === null || options === void 0 ? void 0 : options.ip) !== null && _b !== void 0 ? _b : '127.0.0.1';
24
- this.port = ((_c = options === null || options === void 0 ? void 0 : options.port) !== null && _c !== void 0 ? _c : this.protocol == 'ws') ? 80 : 443;
25
- this.auth = (_d = options === null || options === void 0 ? void 0 : options.auth) !== null && _d !== void 0 ? _d : '';
26
- this.serviceName = (_e = options === null || options === void 0 ? void 0 : options.serviceName) !== null && _e !== void 0 ? _e : '';
27
- this.serviceID = (_f = options === null || options === void 0 ? void 0 : options.serviceID) !== null && _f !== void 0 ? _f : -1;
28
- this.camera = (_g = options === null || options === void 0 ? void 0 : options.camera) !== null && _g !== void 0 ? _g : 0;
22
+ this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
23
+ if ((options === null || options === void 0 ? void 0 : options.tls) === undefined && (options === null || options === void 0 ? void 0 : options.protocol) !== undefined) {
24
+ this.tls = options.protocol === 'wss';
25
+ }
26
+ this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
27
+ this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
28
+ this.port = ((_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : this.tls) ? 443 : 80;
29
+ this.auth = (_e = options === null || options === void 0 ? void 0 : options.auth) !== null && _e !== void 0 ? _e : '';
30
+ this.serviceName = (_f = options === null || options === void 0 ? void 0 : options.serviceName) !== null && _f !== void 0 ? _f : '';
31
+ this.serviceID = (_g = options === null || options === void 0 ? void 0 : options.serviceID) !== null && _g !== void 0 ? _g : -1;
32
+ this.camera = (_h = options === null || options === void 0 ? void 0 : options.camera) !== null && _h !== void 0 ? _h : 0;
29
33
  this.callId = 0;
30
34
  this.sendMessages = {};
31
35
  EventEmitter.call(this);
@@ -47,12 +51,9 @@ class CamOverlayAPI extends EventEmitter {
47
51
  createService() {
48
52
  var _a;
49
53
  return __awaiter(this, void 0, void 0, function* () {
50
- const options = {
51
- host: this.ip,
52
- port: this.port,
53
- path: '/local/camoverlay/api/services.cgi?action=get',
54
- auth: this.auth,
55
- };
54
+ const options = this.getBaseVapixConnectionParams();
55
+ options.method = 'GET';
56
+ options.path = '/local/camoverlay/api/services.cgi?action=get';
56
57
  const response = (yield (0, HTTPRequest_1.httpRequest)(options));
57
58
  let servicesJson;
58
59
  try {
@@ -102,22 +103,20 @@ class CamOverlayAPI extends EventEmitter {
102
103
  }
103
104
  updateServices(servicesJson) {
104
105
  return __awaiter(this, void 0, void 0, function* () {
105
- const options = {
106
- method: 'POST',
107
- host: this.ip,
108
- port: this.port,
109
- path: '/local/camoverlay/api/services.cgi?action=set',
110
- auth: this.auth,
111
- };
106
+ const options = this.getBaseVapixConnectionParams();
107
+ options.method = 'POST';
108
+ options.path = '/local/camoverlay/api/services.cgi?action=set';
112
109
  yield (0, HTTPRequest_1.httpRequest)(options, JSON.stringify(servicesJson));
113
110
  });
114
111
  }
115
112
  openWebsocket(digestHeader) {
116
113
  let promise = new Promise((resolve, reject) => {
117
- let userPass = this.auth.split(':');
118
- let addr = `${this.protocol}://${this.ip}:${this.port}/local/camoverlay/ws`;
119
- let options = {
114
+ const userPass = this.auth.split(':');
115
+ const protocol = this.tls ? 'wss' : 'ws';
116
+ const addr = `${protocol}://${this.ip}:${this.port}/local/camoverlay/ws`;
117
+ const options = {
120
118
  auth: this.auth,
119
+ rejectUnauthorized: !this.tlsInsecure,
121
120
  headers: {},
122
121
  };
123
122
  if (digestHeader != undefined) {
@@ -241,53 +240,33 @@ class CamOverlayAPI extends EventEmitter {
241
240
  }
242
241
  promiseCGUpdate(action, params) {
243
242
  return __awaiter(this, void 0, void 0, function* () {
244
- const path = encodeURI(`/local/camoverlay/api/customGraphics.cgi?action=${action}&service_id=${this.serviceID}${params}`);
245
- const options = {
246
- method: 'POST',
247
- host: this.ip,
248
- port: this.port,
249
- path: path,
250
- auth: this.auth,
251
- };
243
+ const options = this.getBaseVapixConnectionParams();
244
+ options.method = 'POST';
245
+ options.path = encodeURI(`/local/camoverlay/api/customGraphics.cgi?action=${action}&service_id=${this.serviceID}${params}`);
252
246
  yield (0, HTTPRequest_1.httpRequest)(options, '');
253
247
  });
254
248
  }
255
249
  updateInfoticker(text) {
256
250
  return __awaiter(this, void 0, void 0, function* () {
257
- const path = `/local/camoverlay/api/infoticker.cgi?service_id=${this.serviceID}&text=${text}`;
258
- const options = {
259
- method: 'GET',
260
- host: this.ip,
261
- port: this.port,
262
- path: path,
263
- auth: this.auth,
264
- };
251
+ const options = this.getBaseVapixConnectionParams();
252
+ options.method = 'GET';
253
+ options.path = `/local/camoverlay/api/infoticker.cgi?service_id=${this.serviceID}&text=${text}`;
265
254
  yield (0, HTTPRequest_1.httpRequest)(options, '');
266
255
  });
267
256
  }
268
257
  setEnabled(enabled) {
269
258
  return __awaiter(this, void 0, void 0, function* () {
270
- const value = enabled ? 1 : 0;
271
- const path = encodeURI(`/local/camoverlay/api/enabled.cgi?id_${this.serviceID}=${value}`);
272
- const options = {
273
- method: 'POST',
274
- host: this.ip,
275
- port: this.port,
276
- path: path,
277
- auth: this.auth,
278
- };
259
+ const options = this.getBaseVapixConnectionParams();
260
+ options.method = 'POST';
261
+ options.path = encodeURI(`/local/camoverlay/api/enabled.cgi?id_${this.serviceID}=${enabled ? 1 : 0}`);
279
262
  yield (0, HTTPRequest_1.httpRequest)(options, '');
280
263
  });
281
264
  }
282
265
  isEnabled() {
283
266
  return __awaiter(this, void 0, void 0, function* () {
284
- const options = {
285
- method: 'GET',
286
- host: this.ip,
287
- port: this.port,
288
- path: '/local/camoverlay/api/services.cgi?action=get',
289
- auth: this.auth,
290
- };
267
+ const options = this.getBaseVapixConnectionParams();
268
+ options.method = 'GET';
269
+ options.path = '/local/camoverlay/api/services.cgi?action=get';
291
270
  const response = (yield (0, HTTPRequest_1.httpRequest)(options, ''));
292
271
  const data = JSON.parse(response);
293
272
  for (let service of data.services) {
@@ -298,5 +277,14 @@ class CamOverlayAPI extends EventEmitter {
298
277
  throw new Error('Service not found.');
299
278
  });
300
279
  }
280
+ getBaseVapixConnectionParams() {
281
+ return {
282
+ protocol: this.tls ? 'https:' : 'http:',
283
+ host: this.ip,
284
+ port: this.port,
285
+ auth: this.auth,
286
+ rejectUnauthorized: !this.tlsInsecure,
287
+ };
288
+ }
301
289
  }
302
290
  exports.CamOverlayAPI = CamOverlayAPI;
@@ -1,11 +1,14 @@
1
1
  export declare type CamStreamerAPIOptions = {
2
2
  protocol?: string;
3
+ tls?: boolean;
4
+ tlsInsecure?: boolean;
3
5
  ip?: string;
4
6
  port?: number;
5
7
  auth?: string;
6
8
  };
7
9
  export declare class CamStreamerAPI {
8
- private protocol;
10
+ private tls;
11
+ private tlsInsecure;
9
12
  private ip;
10
13
  private port;
11
14
  private auth;
package/CamStreamerAPI.js CHANGED
@@ -13,11 +13,15 @@ exports.CamStreamerAPI = void 0;
13
13
  const HTTPRequest_1 = require("./HTTPRequest");
14
14
  class CamStreamerAPI {
15
15
  constructor(options) {
16
- var _a, _b, _c, _d;
17
- this.protocol = (_a = options === null || options === void 0 ? void 0 : options.protocol) !== null && _a !== void 0 ? _a : 'http';
18
- this.ip = (_b = options === null || options === void 0 ? void 0 : options.ip) !== null && _b !== void 0 ? _b : '127.0.0.1';
19
- this.port = ((_c = options === null || options === void 0 ? void 0 : options.port) !== null && _c !== void 0 ? _c : this.protocol == 'http') ? 80 : 443;
20
- this.auth = (_d = options === null || options === void 0 ? void 0 : options.auth) !== null && _d !== void 0 ? _d : '';
16
+ var _a, _b, _c, _d, _e;
17
+ this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
18
+ if ((options === null || options === void 0 ? void 0 : options.tls) === undefined && (options === null || options === void 0 ? void 0 : options.protocol) !== undefined) {
19
+ this.tls = options.protocol === 'https';
20
+ }
21
+ this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
22
+ this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
23
+ this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
24
+ this.auth = (_e = options === null || options === void 0 ? void 0 : options.auth) !== null && _e !== void 0 ? _e : '';
21
25
  }
22
26
  getStreamList() {
23
27
  return __awaiter(this, void 0, void 0, function* () {
@@ -52,10 +56,11 @@ class CamStreamerAPI {
52
56
  }
53
57
  getBaseConnectionParams() {
54
58
  return {
55
- protocol: this.protocol + ':',
59
+ protocol: this.tls ? 'https:' : 'http:',
56
60
  host: this.ip,
57
61
  port: this.port,
58
62
  auth: this.auth,
63
+ rejectUnauthorized: !this.tlsInsecure,
59
64
  };
60
65
  }
61
66
  }
@@ -1,11 +1,15 @@
1
1
  /// <reference types="node" />
2
2
  import * as EventEmitter from 'events';
3
3
  export declare type CamSwitcherAPIOptions = {
4
+ tls?: boolean;
5
+ tlsInsecure?: boolean;
4
6
  ip?: string;
5
7
  port?: number;
6
8
  auth?: string;
7
9
  };
8
10
  export declare class CamSwitcherAPI extends EventEmitter {
11
+ private tls;
12
+ private tlsInsecure;
9
13
  private ip;
10
14
  private port;
11
15
  private auth;
package/CamSwitcherAPI.js CHANGED
@@ -15,18 +15,23 @@ const EventEmitter = require("events");
15
15
  const HTTPRequest_1 = require("./HTTPRequest");
16
16
  class CamSwitcherAPI extends EventEmitter {
17
17
  constructor(options) {
18
- var _a, _b, _c;
18
+ var _a, _b, _c, _d, _e;
19
19
  super();
20
- this.ip = (_a = options === null || options === void 0 ? void 0 : options.ip) !== null && _a !== void 0 ? _a : '127.0.0.1';
21
- this.port = (_b = options === null || options === void 0 ? void 0 : options.port) !== null && _b !== void 0 ? _b : 80;
22
- this.auth = (_c = options === null || options === void 0 ? void 0 : options.auth) !== null && _c !== void 0 ? _c : '';
20
+ this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
21
+ this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
22
+ this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
23
+ this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : 80;
24
+ this.auth = (_e = options === null || options === void 0 ? void 0 : options.auth) !== null && _e !== void 0 ? _e : '';
23
25
  EventEmitter.call(this);
24
26
  }
25
27
  connect() {
26
28
  return __awaiter(this, void 0, void 0, function* () {
27
29
  try {
28
30
  const token = yield this.get('/local/camswitcher/ws_authorization.cgi');
29
- this.ws = new WebSocket(`ws://${this.ip}:${this.port}/local/camswitcher/events`, 'events');
31
+ const protocol = this.tls ? 'wss' : 'ws';
32
+ this.ws = new WebSocket(`${protocol}://${this.ip}:${this.port}/local/camswitcher/events`, 'events', {
33
+ rejectUnauthorized: !this.tlsInsecure,
34
+ });
30
35
  this.pingTimer = null;
31
36
  this.ws.on('open', () => {
32
37
  this.ws.send(JSON.stringify({ authorization: token }));
@@ -109,10 +114,11 @@ class CamSwitcherAPI extends EventEmitter {
109
114
  }
110
115
  getBaseConnectionParams() {
111
116
  return {
112
- protocol: 'http:',
117
+ protocol: this.tls ? 'https:' : 'http:',
113
118
  host: this.ip,
114
119
  port: this.port,
115
120
  auth: this.auth,
121
+ rejectUnauthorized: !this.tlsInsecure,
116
122
  };
117
123
  }
118
124
  }
package/CameraVapix.d.ts CHANGED
@@ -4,6 +4,8 @@ import * as http from 'http';
4
4
  import { EventEmitter2 as EventEmitter } from 'eventemitter2';
5
5
  export declare type CameraVapixOptions = {
6
6
  protocol?: string;
7
+ tls?: boolean;
8
+ tlsInsecure?: boolean;
7
9
  ip?: string;
8
10
  port?: number;
9
11
  auth?: string;
@@ -46,7 +48,8 @@ export declare type GuardTour = {
46
48
  }[];
47
49
  };
48
50
  export declare class CameraVapix extends EventEmitter {
49
- private protocol;
51
+ private tls;
52
+ private tlsInsecure;
50
53
  private ip;
51
54
  private port;
52
55
  private auth;
package/CameraVapix.js CHANGED
@@ -19,14 +19,18 @@ const RtspClient_1 = require("./RtspClient");
19
19
  const HTTPRequest_1 = require("./HTTPRequest");
20
20
  class CameraVapix extends eventemitter2_1.EventEmitter2 {
21
21
  constructor(options) {
22
- var _a, _b, _c, _d;
22
+ var _a, _b, _c, _d, _e;
23
23
  super();
24
24
  this.rtsp = null;
25
25
  this.ws = null;
26
- this.protocol = (_a = options === null || options === void 0 ? void 0 : options.protocol) !== null && _a !== void 0 ? _a : 'http';
27
- this.ip = (_b = options === null || options === void 0 ? void 0 : options.ip) !== null && _b !== void 0 ? _b : '127.0.0.1';
28
- this.port = (_c = options === null || options === void 0 ? void 0 : options.port) !== null && _c !== void 0 ? _c : (this.protocol == 'http' ? 80 : 443);
29
- this.auth = (_d = options === null || options === void 0 ? void 0 : options.auth) !== null && _d !== void 0 ? _d : '';
26
+ this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
27
+ if ((options === null || options === void 0 ? void 0 : options.tls) === undefined && (options === null || options === void 0 ? void 0 : options.protocol) !== undefined) {
28
+ this.tls = options.protocol === 'https';
29
+ }
30
+ this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
31
+ this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
32
+ this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
33
+ this.auth = (_e = options === null || options === void 0 ? void 0 : options.auth) !== null && _e !== void 0 ? _e : '';
30
34
  }
31
35
  getParameterGroup(groupNames) {
32
36
  return __awaiter(this, void 0, void 0, function* () {
@@ -318,10 +322,11 @@ class CameraVapix extends eventemitter2_1.EventEmitter2 {
318
322
  }
319
323
  getBaseVapixConnectionParams() {
320
324
  return {
321
- protocol: this.protocol + ':',
325
+ protocol: this.tls ? 'https:' : 'http:',
322
326
  host: this.ip,
323
327
  port: this.port,
324
328
  auth: this.auth,
329
+ rejectUnauthorized: !this.tlsInsecure,
325
330
  };
326
331
  }
327
332
  }
package/HTTPRequest.d.ts CHANGED
@@ -11,5 +11,6 @@ export declare type HttpRequestOptions = {
11
11
  headers?: {
12
12
  'Content-Type'?: string;
13
13
  };
14
+ rejectUnauthorized?: boolean;
14
15
  };
15
16
  export declare function httpRequest(options: HttpRequestOptions, postData?: string, noWaitForData?: boolean): Promise<string | http.IncomingMessage>;
package/HTTPRequest.js CHANGED
@@ -49,7 +49,7 @@ function request(options, postData, digestHeader, noWaitForData) {
49
49
  var _a, _b;
50
50
  if (digestHeader != undefined) {
51
51
  if (options.auth == undefined) {
52
- reject('No credentials found');
52
+ reject(new Error('No credentials found'));
53
53
  }
54
54
  const auth = options.auth.split(':');
55
55
  delete options.auth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camstreamerlib",
3
- "version": "1.7.6",
3
+ "version": "1.8.0",
4
4
  "description": "Helper library for CamStreamer ACAP applications.",
5
5
  "prettier": "@camstreamer/prettier-config",
6
6
  "dependencies": {