camstreamerlib 1.8.0 → 1.8.1

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.
@@ -10,7 +10,7 @@ export declare type CamOverlayOptions = {
10
10
  auth?: string;
11
11
  serviceName?: string;
12
12
  serviceID?: number;
13
- camera?: number;
13
+ camera?: number | number[];
14
14
  };
15
15
  export declare type Field = {
16
16
  field_name: string;
@@ -44,7 +44,7 @@ export declare type Service = {
44
44
  schedule: string;
45
45
  name: string;
46
46
  identifier: string;
47
- camera: number;
47
+ cameraList: number[];
48
48
  };
49
49
  export declare type ServiceList = {
50
50
  services: Service[];
@@ -57,7 +57,7 @@ export declare class CamOverlayAPI extends EventEmitter {
57
57
  private auth;
58
58
  private serviceName;
59
59
  private serviceID;
60
- private camera;
60
+ private cameraList;
61
61
  private callId;
62
62
  private sendMessages;
63
63
  private ws;
@@ -86,4 +86,5 @@ export declare class CamOverlayAPI extends EventEmitter {
86
86
  setEnabled(enabled: boolean): Promise<void>;
87
87
  isEnabled(): Promise<boolean>;
88
88
  private getBaseVapixConnectionParams;
89
+ private compareCameraList;
89
90
  }
package/CamOverlayAPI.js CHANGED
@@ -16,7 +16,7 @@ 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, _h;
19
+ var _a, _b, _c, _d, _e, _f, _g;
20
20
  super();
21
21
  this.ws = null;
22
22
  this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
@@ -25,11 +25,17 @@ class CamOverlayAPI extends EventEmitter {
25
25
  }
26
26
  this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
27
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;
28
+ this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
29
29
  this.auth = (_e = options === null || options === void 0 ? void 0 : options.auth) !== null && _e !== void 0 ? _e : '';
30
30
  this.serviceName = (_f = options === null || options === void 0 ? void 0 : options.serviceName) !== null && _f !== void 0 ? _f : '';
31
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;
32
+ this.cameraList = [0];
33
+ if (Array.isArray(options === null || options === void 0 ? void 0 : options.camera)) {
34
+ this.cameraList = options.camera;
35
+ }
36
+ else if (typeof (options === null || options === void 0 ? void 0 : options.camera) === 'number') {
37
+ this.cameraList = [options.camera];
38
+ }
33
39
  this.callId = 0;
34
40
  this.sendMessages = {};
35
41
  EventEmitter.call(this);
@@ -37,7 +43,7 @@ class CamOverlayAPI extends EventEmitter {
37
43
  connect() {
38
44
  return __awaiter(this, void 0, void 0, function* () {
39
45
  try {
40
- if (this.serviceID == -1) {
46
+ if (this.serviceID === -1) {
41
47
  this.serviceID = yield this.createService();
42
48
  }
43
49
  yield this.openWebsocket();
@@ -70,14 +76,14 @@ class CamOverlayAPI extends EventEmitter {
70
76
  if (s.id > maxID) {
71
77
  maxID = s.id;
72
78
  }
73
- if (s.identifier == this.serviceName && s.name == 'scripter') {
79
+ if (s.identifier === this.serviceName && s.name === 'scripter') {
74
80
  service = s;
75
81
  break;
76
82
  }
77
83
  }
78
- if (service != null) {
79
- if (service.camera == undefined || service.camera != this.camera) {
80
- service.camera = this.camera;
84
+ if (service !== null) {
85
+ if (service.cameraList === undefined || !this.compareCameraList(service.cameraList)) {
86
+ service.cameraList = this.cameraList;
81
87
  yield this.updateServices(servicesJson);
82
88
  return service.id;
83
89
  }
@@ -93,7 +99,7 @@ class CamOverlayAPI extends EventEmitter {
93
99
  schedule: '',
94
100
  name: 'scripter',
95
101
  identifier: this.serviceName,
96
- camera: this.camera,
102
+ cameraList: this.cameraList,
97
103
  };
98
104
  servicesJson.services.push(service);
99
105
  yield this.updateServices(servicesJson);
@@ -119,7 +125,7 @@ class CamOverlayAPI extends EventEmitter {
119
125
  rejectUnauthorized: !this.tlsInsecure,
120
126
  headers: {},
121
127
  };
122
- if (digestHeader != undefined) {
128
+ if (digestHeader !== undefined) {
123
129
  options.headers['Authorization'] = Digest_1.Digest.getAuthHeader(userPass[0], userPass[1], 'GET', '/local/camoverlay/ws', digestHeader);
124
130
  }
125
131
  this.ws = new WebSocket(addr, 'cairo-api', options);
@@ -142,7 +148,7 @@ class CamOverlayAPI extends EventEmitter {
142
148
  }
143
149
  });
144
150
  this.ws.on('unexpected-response', (req, res) => __awaiter(this, void 0, void 0, function* () {
145
- if (res.statusCode == 401 && res.headers['www-authenticate'] != undefined)
151
+ if (res.statusCode === 401 && res.headers['www-authenticate'] !== undefined)
146
152
  this.openWebsocket(res.headers['www-authenticate']).then(resolve, reject);
147
153
  else {
148
154
  reject('Error: status code: ' + res.statusCode + ', ' + res.data);
@@ -220,14 +226,14 @@ class CamOverlayAPI extends EventEmitter {
220
226
  for (let field of fields) {
221
227
  const name = field.field_name;
222
228
  field_specs += `&${name}=${field.text}`;
223
- if (field.color != undefined) {
229
+ if (field.color !== undefined) {
224
230
  field_specs += `&${name}_color=${field.color}`;
225
231
  }
226
232
  }
227
233
  return this.promiseCGUpdate('update_text', field_specs);
228
234
  }
229
235
  formCoordinates(coordinates, x, y) {
230
- return coordinates != '' ? `&coord_system=${coordinates}&pos_x=${x}&pos_y=${y}` : '';
236
+ return coordinates !== '' ? `&coord_system=${coordinates}&pos_x=${x}&pos_y=${y}` : '';
231
237
  }
232
238
  updateCGImage(path, coordinates = '', x = 0, y = 0) {
233
239
  const coord = this.formCoordinates(coordinates, x, y);
@@ -270,8 +276,8 @@ class CamOverlayAPI extends EventEmitter {
270
276
  const response = (yield (0, HTTPRequest_1.httpRequest)(options, ''));
271
277
  const data = JSON.parse(response);
272
278
  for (let service of data.services) {
273
- if (service.id == this.serviceID) {
274
- return service.enabled == 1;
279
+ if (service.id === this.serviceID) {
280
+ return service.enabled === 1;
275
281
  }
276
282
  }
277
283
  throw new Error('Service not found.');
@@ -286,5 +292,9 @@ class CamOverlayAPI extends EventEmitter {
286
292
  rejectUnauthorized: !this.tlsInsecure,
287
293
  };
288
294
  }
295
+ compareCameraList(cameraList) {
296
+ return (this.cameraList.length === cameraList.length &&
297
+ this.cameraList.every((element, index) => element === cameraList[index]));
298
+ }
289
299
  }
290
300
  exports.CamOverlayAPI = CamOverlayAPI;
package/README.md CHANGED
@@ -197,7 +197,7 @@ Module for easy control of CamOverlay drawing API. For more details on supported
197
197
 
198
198
  ### methods
199
199
  #### CameraVapix(options)
200
- Options parameter contains access to the camera, service name, service ID and camera. If service ID is not specified, service is automatically created/selected based on serviceName. Specify video channel using parameter camera (in which View Area overlay will be shown). If omitted the default value camera=0 is used.
200
+ Options parameter contains access to the camera, service name, service ID and camera. If service ID is not specified, service is automatically created/selected based on serviceName. Specify video channel using parameter camera (in which View Area overlay will be shown). If you need to specify multiple video channels, you can use an array: `camera=[0,1]`. If omitted the default value `camera=0` is used.
201
201
  ```javascript
202
202
  options = {
203
203
  'ip': '127.0.0.1',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camstreamerlib",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Helper library for CamStreamer ACAP applications.",
5
5
  "prettier": "@camstreamer/prettier-config",
6
6
  "dependencies": {