camstreamerlib 4.0.13 → 4.0.15

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.
@@ -37,6 +37,9 @@ class CamStreamerAPI extends BasicAPI_1.BasicAPI {
37
37
  }
38
38
  async isCSPassValid(pass, options) {
39
39
  const res = await this._getJson(`${BASE_PATH}/check_pass.cgi`, { pass }, options);
40
+ if (res.status !== 200) {
41
+ throw new Error(res.message);
42
+ }
40
43
  return res.data === '1';
41
44
  }
42
45
  async getCamStreamerAppLog(options) {
@@ -44,6 +47,9 @@ class CamStreamerAPI extends BasicAPI_1.BasicAPI {
44
47
  }
45
48
  async getStreamList(options) {
46
49
  const res = await this._getJson(`${BASE_PATH}/stream_list.cgi`, { action: 'get' }, options);
50
+ if (res.status !== 200) {
51
+ throw new Error(res.message);
52
+ }
47
53
  const oldStreamListRecord = zod_1.z.record(zod_1.z.string(), oldStreamSchema_1.oldStringStreamSchema).safeParse(res.data);
48
54
  if (oldStreamListRecord.success) {
49
55
  const data = Object.entries(oldStreamListRecord.data).map(([streamId, streamData]) => ({
@@ -88,6 +94,9 @@ class CamStreamerAPI extends BasicAPI_1.BasicAPI {
88
94
  }
89
95
  async getStream(streamId, options) {
90
96
  const res = await this._getJson(`${BASE_PATH}/stream_list.cgi`, { action: 'get', stream_id: streamId }, options);
97
+ if (res.status !== 200) {
98
+ throw new Error(res.message);
99
+ }
91
100
  const newStream = CamStreamerAPI_1.streamSchema.safeParse(res.data);
92
101
  if (newStream.success) {
93
102
  return newStream.data;
package/cjs/VapixAPI.d.ts CHANGED
@@ -101,10 +101,9 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
101
101
  usage: string;
102
102
  normalState: "open" | "closed";
103
103
  readonly?: boolean | undefined;
104
- }[] | undefined>;
104
+ }[]>;
105
105
  setPorts(ports: TPortSetSchema[], options?: THttpRequestOptions): Promise<void>;
106
106
  setPortStateSequence(port: number, sequence: TPortSequenceStateSchema[], options?: THttpRequestOptions): Promise<void>;
107
- private checkPortsAvailable;
108
107
  addCameraUser(username: string, pass: string, sgrp: string, comment?: string, options?: THttpRequestOptions): Promise<void>;
109
108
  getCameraUsers(options?: THttpRequestOptions): Promise<string[]>;
110
109
  editCameraUser(username: string, pass: string, options?: THttpRequestOptions): Promise<void>;
package/cjs/VapixAPI.js CHANGED
@@ -408,51 +408,66 @@ class VapixAPI extends BasicAPI_1.BasicAPI {
408
408
  return portResponseParsed.data.items ?? [];
409
409
  }
410
410
  catch (error) {
411
- await this.checkPortsAvailable(error);
411
+ if (error instanceof errors_1.ErrorWithResponse && error.res.status === 404) {
412
+ console.warn(error, 'Error while fetching ports, trying param.cgi directly');
413
+ const ports = await this.getParameter([constants_1.PORT_PARAMS.inputNbr, constants_1.PORT_PARAMS.outputNbr]);
414
+ const nbrOfPorts = Number(ports[constants_1.PORT_PARAMS.inputNbr] ?? 0) + Number(ports[constants_1.PORT_PARAMS.outputNbr] ?? 0);
415
+ if (nbrOfPorts === 0) {
416
+ return [];
417
+ }
418
+ const items = [];
419
+ for (let i = 0; i < nbrOfPorts; i++) {
420
+ const portDirection = (await this.getParameter([constants_1.PORT_PARAMS.direction(i)]))[constants_1.PORT_PARAMS.direction(i)];
421
+ if (portDirection === undefined) {
422
+ continue;
423
+ }
424
+ const info = await this.getParameter([
425
+ constants_1.PORT_PARAMS.configurable(i),
426
+ constants_1.PORT_PARAMS.usage(i),
427
+ portDirection === 'input' ? constants_1.PORT_PARAMS.inputState(i) : constants_1.PORT_PARAMS.outputState(i),
428
+ portDirection === 'input' ? constants_1.PORT_PARAMS.inputName(i) : constants_1.PORT_PARAMS.outputName(i),
429
+ ]);
430
+ const portState = portDirection === 'input'
431
+ ? info[constants_1.PORT_PARAMS.inputState(i)] === 'open'
432
+ ? 'closed'
433
+ : 'open'
434
+ : info[constants_1.PORT_PARAMS.outputState(i)] === 'open'
435
+ ? 'closed'
436
+ : 'open';
437
+ items.push({
438
+ port: String(i),
439
+ state: portState,
440
+ configurable: info[constants_1.PORT_PARAMS.configurable(i)] !== 'no',
441
+ usage: info[constants_1.PORT_PARAMS.usage(i)] ?? '',
442
+ direction: portDirection,
443
+ name: portDirection === 'input'
444
+ ? info[constants_1.PORT_PARAMS.inputName(i)] ?? 'Port ' + i
445
+ : info[constants_1.PORT_PARAMS.outputName(i)] ?? 'Port ' + i,
446
+ normalState: portState,
447
+ });
448
+ }
449
+ return items;
450
+ }
451
+ else {
452
+ throw error;
453
+ }
412
454
  }
413
455
  }
414
456
  async setPorts(ports, options) {
415
- try {
416
- await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
417
- apiVersion: '1.0',
418
- context: '',
419
- method: 'setPorts',
420
- params: { ports },
421
- }, undefined, options);
422
- }
423
- catch (error) {
424
- await this.checkPortsAvailable(error);
425
- }
457
+ await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
458
+ apiVersion: '1.0',
459
+ context: '',
460
+ method: 'setPorts',
461
+ params: { ports },
462
+ }, undefined, options);
426
463
  }
427
464
  async setPortStateSequence(port, sequence, options) {
428
- try {
429
- await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
430
- apiVersion: '1.0',
431
- context: '',
432
- method: 'setStateSequence',
433
- params: { port, sequence },
434
- }, undefined, options);
435
- }
436
- catch (error) {
437
- await this.checkPortsAvailable(error);
438
- }
439
- }
440
- async checkPortsAvailable(error) {
441
- if (error instanceof errors_1.ErrorWithResponse && error.res.status === 404) {
442
- const ports = await this.getParameter([constants_1.PORT_PARAMS.inputNbr, constants_1.PORT_PARAMS.outputNbr]);
443
- const inputPorts = ports[constants_1.PORT_PARAMS.inputNbr];
444
- const outputPorts = ports[constants_1.PORT_PARAMS.outputNbr];
445
- if ((inputPorts === undefined || inputPorts === '0') &&
446
- (outputPorts === undefined || outputPorts === '0')) {
447
- return [];
448
- }
449
- else {
450
- throw new errors_1.PortManagementError(inputPorts, outputPorts);
451
- }
452
- }
453
- else {
454
- throw error;
455
- }
465
+ await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
466
+ apiVersion: '1.0',
467
+ context: '',
468
+ method: 'setStateSequence',
469
+ params: { port, sequence },
470
+ }, undefined, options);
456
471
  }
457
472
  async addCameraUser(username, pass, sgrp, comment, options) {
458
473
  const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
@@ -105,11 +105,4 @@ export declare class MigrationError extends Error {
105
105
  platform: string;
106
106
  }[]);
107
107
  }
108
- export declare class PortManagementError extends Error {
109
- readonly ports: {
110
- inputPorts?: string;
111
- outputPorts?: string;
112
- };
113
- constructor(nbrOfInputPorts?: string, nbrOfOutputPorts?: string);
114
- }
115
108
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PortManagementError = exports.MigrationError = exports.BadRequestError = exports.ServerError = exports.InvalidAltitudeError = exports.InvalidLatLngError = exports.CannotSetCoordsInAutoModeError = exports.ImportSettingsError = exports.ResetCalibrationError = exports.TimezoneFetchError = exports.TimezoneNotSetupError = exports.UtcTimeFetchError = exports.WsAuthorizationError = exports.StorageDataFetchError = exports.PtzNotSupportedError = exports.AddNewClipError = exports.FetchDeviceInfoError = exports.NoDeviceInfoError = exports.MaxFPSError = exports.SDCardJobError = exports.SDCardActionError = exports.ApplicationAPIError = exports.SettingParameterError = exports.ParameterNotFoundError = exports.JsonParseError = exports.ParsingBlobError = exports.ServiceNotFoundError = exports.ServiceUnavailableError = exports.ErrorWithResponse = void 0;
3
+ exports.MigrationError = exports.BadRequestError = exports.ServerError = exports.InvalidAltitudeError = exports.InvalidLatLngError = exports.CannotSetCoordsInAutoModeError = exports.ImportSettingsError = exports.ResetCalibrationError = exports.TimezoneFetchError = exports.TimezoneNotSetupError = exports.UtcTimeFetchError = exports.WsAuthorizationError = exports.StorageDataFetchError = exports.PtzNotSupportedError = exports.AddNewClipError = exports.FetchDeviceInfoError = exports.NoDeviceInfoError = exports.MaxFPSError = exports.SDCardJobError = exports.SDCardActionError = exports.ApplicationAPIError = exports.SettingParameterError = exports.ParameterNotFoundError = exports.JsonParseError = exports.ParsingBlobError = exports.ServiceNotFoundError = exports.ServiceUnavailableError = exports.ErrorWithResponse = void 0;
4
4
  class ErrorWithResponse extends Error {
5
5
  res;
6
6
  constructor(res) {
@@ -219,15 +219,3 @@ class MigrationError extends Error {
219
219
  }
220
220
  }
221
221
  exports.MigrationError = MigrationError;
222
- class PortManagementError extends Error {
223
- ports;
224
- constructor(nbrOfInputPorts, nbrOfOutputPorts) {
225
- super('Failed to fetch ports using portmanagement.cgi');
226
- this.name = 'PortManagementError';
227
- this.ports = {
228
- inputPorts: nbrOfInputPorts,
229
- outputPorts: nbrOfOutputPorts,
230
- };
231
- }
232
- }
233
- exports.PortManagementError = PortManagementError;
@@ -3,4 +3,11 @@ export declare const FIRMWARE_WITH_OVERLAYS_SUPPORT = "10.7.0";
3
3
  export declare const PORT_PARAMS: {
4
4
  readonly inputNbr: "Input.NbrOfInputs";
5
5
  readonly outputNbr: "Output.NbrOfOutputs";
6
+ readonly inputName: (port: number) => string;
7
+ readonly outputName: (port: number) => string;
8
+ readonly inputState: (port: number) => string;
9
+ readonly outputState: (port: number) => string;
10
+ readonly configurable: (port: number) => string;
11
+ readonly usage: (port: number) => string;
12
+ readonly direction: (port: number) => string;
6
13
  };
@@ -6,4 +6,11 @@ exports.FIRMWARE_WITH_OVERLAYS_SUPPORT = '10.7.0';
6
6
  exports.PORT_PARAMS = {
7
7
  inputNbr: 'Input.NbrOfInputs',
8
8
  outputNbr: 'Output.NbrOfOutputs',
9
+ inputName: (port) => `IOPort.I${port}.Input.Name`,
10
+ outputName: (port) => `IOPort.I${port}.Output.Name`,
11
+ inputState: (port) => `IOPort.I${port}.Input.Trig`,
12
+ outputState: (port) => `IOPort.I${port}.Output.Active`,
13
+ configurable: (port) => `IOPort.I${port}.Configurable`,
14
+ usage: (port) => `IOPort.I${port}.Usage`,
15
+ direction: (port) => `IOPort.I${port}.Direction`,
9
16
  };
@@ -34,6 +34,9 @@ export class CamStreamerAPI extends BasicAPI {
34
34
  }
35
35
  async isCSPassValid(pass, options) {
36
36
  const res = await this._getJson(`${BASE_PATH}/check_pass.cgi`, { pass }, options);
37
+ if (res.status !== 200) {
38
+ throw new Error(res.message);
39
+ }
37
40
  return res.data === '1';
38
41
  }
39
42
  async getCamStreamerAppLog(options) {
@@ -41,6 +44,9 @@ export class CamStreamerAPI extends BasicAPI {
41
44
  }
42
45
  async getStreamList(options) {
43
46
  const res = await this._getJson(`${BASE_PATH}/stream_list.cgi`, { action: 'get' }, options);
47
+ if (res.status !== 200) {
48
+ throw new Error(res.message);
49
+ }
44
50
  const oldStreamListRecord = z.record(z.string(), oldStringStreamSchema).safeParse(res.data);
45
51
  if (oldStreamListRecord.success) {
46
52
  const data = Object.entries(oldStreamListRecord.data).map(([streamId, streamData]) => ({
@@ -85,6 +91,9 @@ export class CamStreamerAPI extends BasicAPI {
85
91
  }
86
92
  async getStream(streamId, options) {
87
93
  const res = await this._getJson(`${BASE_PATH}/stream_list.cgi`, { action: 'get', stream_id: streamId }, options);
94
+ if (res.status !== 200) {
95
+ throw new Error(res.message);
96
+ }
88
97
  const newStream = streamSchema.safeParse(res.data);
89
98
  if (newStream.success) {
90
99
  return newStream.data;
package/esm/VapixAPI.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { arrayToUrl, isNullish, paramToUrl } from './internal/utils';
2
2
  import { sdCardWatchedStatuses, maxFpsResponseSchema, dateTimeinfoSchema, audioDeviceRequestSchema, audioSampleRatesResponseSchema, timeZoneSchema, getPortsResponseSchema, guardTourSchema, ptzOverviewSchema, cameraPTZItemDataSchema, applicationListSchema, sdCardInfoSchema, ALL_APP_IDS, allDateTimeInfoSchema, } from './types/VapixAPI';
3
- import { ApplicationAPIError, MaxFPSError, NoDeviceInfoError, PtzNotSupportedError, ErrorWithResponse, SDCardActionError, SDCardJobError, SettingParameterError, TimezoneFetchError, PortManagementError, } from './errors/errors';
3
+ import { ApplicationAPIError, MaxFPSError, NoDeviceInfoError, PtzNotSupportedError, ErrorWithResponse, SDCardActionError, SDCardJobError, SettingParameterError, TimezoneFetchError, } from './errors/errors';
4
4
  import { z } from 'zod';
5
5
  import { XMLParser } from 'fast-xml-parser';
6
6
  import { BasicAPI } from './internal/BasicAPI';
@@ -405,51 +405,66 @@ export class VapixAPI extends BasicAPI {
405
405
  return portResponseParsed.data.items ?? [];
406
406
  }
407
407
  catch (error) {
408
- await this.checkPortsAvailable(error);
408
+ if (error instanceof ErrorWithResponse && error.res.status === 404) {
409
+ console.warn(error, 'Error while fetching ports, trying param.cgi directly');
410
+ const ports = await this.getParameter([PORT_PARAMS.inputNbr, PORT_PARAMS.outputNbr]);
411
+ const nbrOfPorts = Number(ports[PORT_PARAMS.inputNbr] ?? 0) + Number(ports[PORT_PARAMS.outputNbr] ?? 0);
412
+ if (nbrOfPorts === 0) {
413
+ return [];
414
+ }
415
+ const items = [];
416
+ for (let i = 0; i < nbrOfPorts; i++) {
417
+ const portDirection = (await this.getParameter([PORT_PARAMS.direction(i)]))[PORT_PARAMS.direction(i)];
418
+ if (portDirection === undefined) {
419
+ continue;
420
+ }
421
+ const info = await this.getParameter([
422
+ PORT_PARAMS.configurable(i),
423
+ PORT_PARAMS.usage(i),
424
+ portDirection === 'input' ? PORT_PARAMS.inputState(i) : PORT_PARAMS.outputState(i),
425
+ portDirection === 'input' ? PORT_PARAMS.inputName(i) : PORT_PARAMS.outputName(i),
426
+ ]);
427
+ const portState = portDirection === 'input'
428
+ ? info[PORT_PARAMS.inputState(i)] === 'open'
429
+ ? 'closed'
430
+ : 'open'
431
+ : info[PORT_PARAMS.outputState(i)] === 'open'
432
+ ? 'closed'
433
+ : 'open';
434
+ items.push({
435
+ port: String(i),
436
+ state: portState,
437
+ configurable: info[PORT_PARAMS.configurable(i)] !== 'no',
438
+ usage: info[PORT_PARAMS.usage(i)] ?? '',
439
+ direction: portDirection,
440
+ name: portDirection === 'input'
441
+ ? info[PORT_PARAMS.inputName(i)] ?? 'Port ' + i
442
+ : info[PORT_PARAMS.outputName(i)] ?? 'Port ' + i,
443
+ normalState: portState,
444
+ });
445
+ }
446
+ return items;
447
+ }
448
+ else {
449
+ throw error;
450
+ }
409
451
  }
410
452
  }
411
453
  async setPorts(ports, options) {
412
- try {
413
- await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
414
- apiVersion: '1.0',
415
- context: '',
416
- method: 'setPorts',
417
- params: { ports },
418
- }, undefined, options);
419
- }
420
- catch (error) {
421
- await this.checkPortsAvailable(error);
422
- }
454
+ await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
455
+ apiVersion: '1.0',
456
+ context: '',
457
+ method: 'setPorts',
458
+ params: { ports },
459
+ }, undefined, options);
423
460
  }
424
461
  async setPortStateSequence(port, sequence, options) {
425
- try {
426
- await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
427
- apiVersion: '1.0',
428
- context: '',
429
- method: 'setStateSequence',
430
- params: { port, sequence },
431
- }, undefined, options);
432
- }
433
- catch (error) {
434
- await this.checkPortsAvailable(error);
435
- }
436
- }
437
- async checkPortsAvailable(error) {
438
- if (error instanceof ErrorWithResponse && error.res.status === 404) {
439
- const ports = await this.getParameter([PORT_PARAMS.inputNbr, PORT_PARAMS.outputNbr]);
440
- const inputPorts = ports[PORT_PARAMS.inputNbr];
441
- const outputPorts = ports[PORT_PARAMS.outputNbr];
442
- if ((inputPorts === undefined || inputPorts === '0') &&
443
- (outputPorts === undefined || outputPorts === '0')) {
444
- return [];
445
- }
446
- else {
447
- throw new PortManagementError(inputPorts, outputPorts);
448
- }
449
- }
450
- else {
451
- throw error;
452
- }
462
+ await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
463
+ apiVersion: '1.0',
464
+ context: '',
465
+ method: 'setStateSequence',
466
+ params: { port, sequence },
467
+ }, undefined, options);
453
468
  }
454
469
  async addCameraUser(username, pass, sgrp, comment, options) {
455
470
  const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
@@ -188,14 +188,3 @@ export class MigrationError extends Error {
188
188
  this.unknown = unknown;
189
189
  }
190
190
  }
191
- export class PortManagementError extends Error {
192
- ports;
193
- constructor(nbrOfInputPorts, nbrOfOutputPorts) {
194
- super('Failed to fetch ports using portmanagement.cgi');
195
- this.name = 'PortManagementError';
196
- this.ports = {
197
- inputPorts: nbrOfInputPorts,
198
- outputPorts: nbrOfOutputPorts,
199
- };
200
- }
201
- }
@@ -3,4 +3,11 @@ export const FIRMWARE_WITH_OVERLAYS_SUPPORT = '10.7.0';
3
3
  export const PORT_PARAMS = {
4
4
  inputNbr: 'Input.NbrOfInputs',
5
5
  outputNbr: 'Output.NbrOfOutputs',
6
+ inputName: (port) => `IOPort.I${port}.Input.Name`,
7
+ outputName: (port) => `IOPort.I${port}.Output.Name`,
8
+ inputState: (port) => `IOPort.I${port}.Input.Trig`,
9
+ outputState: (port) => `IOPort.I${port}.Output.Active`,
10
+ configurable: (port) => `IOPort.I${port}.Configurable`,
11
+ usage: (port) => `IOPort.I${port}.Usage`,
12
+ direction: (port) => `IOPort.I${port}.Direction`,
6
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camstreamerlib",
3
- "version": "4.0.13",
3
+ "version": "4.0.15",
4
4
  "description": "Helper library for CamStreamer ACAP applications.",
5
5
  "prettier": "@camstreamer/prettier-config",
6
6
  "engine": {
@@ -101,10 +101,9 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
101
101
  usage: string;
102
102
  normalState: "open" | "closed";
103
103
  readonly?: boolean | undefined;
104
- }[] | undefined>;
104
+ }[]>;
105
105
  setPorts(ports: TPortSetSchema[], options?: THttpRequestOptions): Promise<void>;
106
106
  setPortStateSequence(port: number, sequence: TPortSequenceStateSchema[], options?: THttpRequestOptions): Promise<void>;
107
- private checkPortsAvailable;
108
107
  addCameraUser(username: string, pass: string, sgrp: string, comment?: string, options?: THttpRequestOptions): Promise<void>;
109
108
  getCameraUsers(options?: THttpRequestOptions): Promise<string[]>;
110
109
  editCameraUser(username: string, pass: string, options?: THttpRequestOptions): Promise<void>;
@@ -105,11 +105,4 @@ export declare class MigrationError extends Error {
105
105
  platform: string;
106
106
  }[]);
107
107
  }
108
- export declare class PortManagementError extends Error {
109
- readonly ports: {
110
- inputPorts?: string;
111
- outputPorts?: string;
112
- };
113
- constructor(nbrOfInputPorts?: string, nbrOfOutputPorts?: string);
114
- }
115
108
  export {};
@@ -3,4 +3,11 @@ export declare const FIRMWARE_WITH_OVERLAYS_SUPPORT = "10.7.0";
3
3
  export declare const PORT_PARAMS: {
4
4
  readonly inputNbr: "Input.NbrOfInputs";
5
5
  readonly outputNbr: "Output.NbrOfOutputs";
6
+ readonly inputName: (port: number) => string;
7
+ readonly outputName: (port: number) => string;
8
+ readonly inputState: (port: number) => string;
9
+ readonly outputState: (port: number) => string;
10
+ readonly configurable: (port: number) => string;
11
+ readonly usage: (port: number) => string;
12
+ readonly direction: (port: number) => string;
6
13
  };