camstreamerlib 4.0.10 → 4.0.12

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.
@@ -89,8 +89,8 @@ class PlaneTrackerAPI extends BasicAPI_1.BasicAPI {
89
89
  }
90
90
  }
91
91
  async getDomainList(options) {
92
- const res = await this._getJson(`${BASE_PATH}/getDomainList.cgi`, { action: 'get' }, options);
93
- return PlaneTrackerAPI_1.domainListSchema.parse(res);
92
+ const res = await this._getJson(`${BASE_PATH}/package/getDomainList.cgi`, { action: 'get' }, options);
93
+ return zod_1.z.object({ domainList: PlaneTrackerAPI_1.domainListSchema }).parse(res).domainList;
94
94
  }
95
95
  async fetchFlightInfo(targetId, options) {
96
96
  const res = await this._getJson(`${BASE_PATH}/package/flightInfo.cgi`, { targetId }, options);
package/cjs/VapixAPI.d.ts CHANGED
@@ -101,9 +101,10 @@ 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
- }[]>;
104
+ }[] | undefined>;
105
105
  setPorts(ports: TPortSetSchema[], options?: THttpRequestOptions): Promise<void>;
106
106
  setPortStateSequence(port: number, sequence: TPortSequenceStateSchema[], options?: THttpRequestOptions): Promise<void>;
107
+ private checkPortsAvailable;
107
108
  addCameraUser(username: string, pass: string, sgrp: string, comment?: string, options?: THttpRequestOptions): Promise<void>;
108
109
  getCameraUsers(options?: THttpRequestOptions): Promise<string[]>;
109
110
  editCameraUser(username: string, pass: string, options?: THttpRequestOptions): Promise<void>;
package/cjs/VapixAPI.js CHANGED
@@ -7,6 +7,7 @@ const errors_1 = require("./errors/errors");
7
7
  const zod_1 = require("zod");
8
8
  const fast_xml_parser_1 = require("fast-xml-parser");
9
9
  const BasicAPI_1 = require("./internal/BasicAPI");
10
+ const constants_1 = require("./internal/constants");
10
11
  class VapixAPI extends BasicAPI_1.BasicAPI {
11
12
  CustomFormData;
12
13
  constructor(client, CustomFormData = FormData) {
@@ -152,12 +153,24 @@ class VapixAPI extends BasicAPI_1.BasicAPI {
152
153
  console.warn('Failed to fetch time zone data from time API v2:', error instanceof Error ? error.message : JSON.stringify(error));
153
154
  console.warn('Falling back to deprecated time API v1');
154
155
  }
155
- const data = await this.getAllDateTimeInfo(options);
156
- if (data.data.timeZone === undefined) {
157
- console.warn('Timezone not set up on the camera, using POSIX time zone as fallback');
158
- return zod_1.z.string().parse(data.data.posixTimeZone);
156
+ try {
157
+ const data = await this.getAllDateTimeInfo(options);
158
+ if (data.data.timeZone === undefined) {
159
+ console.warn('Timezone not set up on the camera, using POSIX time zone as fallback');
160
+ return zod_1.z.string().parse(data.data.posixTimeZone);
161
+ }
162
+ return zod_1.z.string().parse(data.data.timeZone);
163
+ }
164
+ catch (error) {
165
+ console.warn('Could not retreive timezone from either API endpoints, reading param.cgi');
166
+ const posixTimezone = (await this.getParameter('Time.POSIXTimeZone', options))['Time.POSIXTimeZone'];
167
+ if (posixTimezone !== undefined) {
168
+ return zod_1.z.string().parse(posixTimezone);
169
+ }
170
+ else {
171
+ throw error;
172
+ }
159
173
  }
160
- return zod_1.z.string().parse(data.data.timeZone);
161
174
  }
162
175
  async getAllDateTimeInfo(options) {
163
176
  const data = { apiVersion: '1.0', method: 'getAll' };
@@ -385,29 +398,61 @@ class VapixAPI extends BasicAPI_1.BasicAPI {
385
398
  });
386
399
  }
387
400
  async getPorts(options) {
388
- const res = await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
389
- apiVersion: '1.0',
390
- context: '',
391
- method: 'getPorts',
392
- }, undefined, options);
393
- const portResponseParsed = VapixAPI_1.getPortsResponseSchema.parse(await res.json());
394
- return portResponseParsed.data.items ?? [];
401
+ try {
402
+ const res = await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
403
+ apiVersion: '1.0',
404
+ context: '',
405
+ method: 'getPorts',
406
+ }, undefined, options);
407
+ const portResponseParsed = VapixAPI_1.getPortsResponseSchema.parse(await res.json());
408
+ return portResponseParsed.data.items ?? [];
409
+ }
410
+ catch (error) {
411
+ await this.checkPortsAvailable(error);
412
+ }
395
413
  }
396
414
  async setPorts(ports, options) {
397
- await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
398
- apiVersion: '1.0',
399
- context: '',
400
- method: 'setPorts',
401
- params: { ports },
402
- }, undefined, 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
+ }
403
426
  }
404
427
  async setPortStateSequence(port, sequence, options) {
405
- await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
406
- apiVersion: '1.0',
407
- context: '',
408
- method: 'setStateSequence',
409
- params: { port, sequence },
410
- }, undefined, 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
+ }
411
456
  }
412
457
  async addCameraUser(username, pass, sgrp, comment, options) {
413
458
  const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
@@ -105,4 +105,11 @@ 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
+ }
108
115
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
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;
4
4
  class ErrorWithResponse extends Error {
5
5
  res;
6
6
  constructor(res) {
@@ -219,3 +219,15 @@ 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;
@@ -1,2 +1,6 @@
1
1
  export declare const FIRMWARE_WITH_BITRATE_MODES_SUPPORT = "11.11.73";
2
2
  export declare const FIRMWARE_WITH_OVERLAYS_SUPPORT = "10.7.0";
3
+ export declare const PORT_PARAMS: {
4
+ readonly inputNbr: "Input.NbrOfInputs";
5
+ readonly outputNbr: "Output.NbrOfOutputs";
6
+ };
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FIRMWARE_WITH_OVERLAYS_SUPPORT = exports.FIRMWARE_WITH_BITRATE_MODES_SUPPORT = void 0;
3
+ exports.PORT_PARAMS = exports.FIRMWARE_WITH_OVERLAYS_SUPPORT = exports.FIRMWARE_WITH_BITRATE_MODES_SUPPORT = void 0;
4
4
  exports.FIRMWARE_WITH_BITRATE_MODES_SUPPORT = '11.11.73';
5
5
  exports.FIRMWARE_WITH_OVERLAYS_SUPPORT = '10.7.0';
6
+ exports.PORT_PARAMS = {
7
+ inputNbr: 'Input.NbrOfInputs',
8
+ outputNbr: 'Output.NbrOfOutputs',
9
+ };
@@ -105,6 +105,7 @@ declare const apiUserSchema: z.ZodObject<{
105
105
  export type TEventType = 'CAMERA_POSITION' | 'TRACKING_START' | 'TRACKING_STOP' | 'FLIGHT_LIST' | 'USER_ACTION' | 'CONNECTED_USERS' | 'FORCE_TRACKING_STATUS' | 'API_LOCK_STATUS';
106
106
  export declare enum EUserActions {
107
107
  TRACK_ICAO = "trackIcao.cgi",
108
+ TRACK_TARGET = "trackTarget.cgi",
108
109
  RESET_ICAO = "resetIcao.cgi",
109
110
  SET_PRIORITY_LIST = "setPriorityList.cgi",
110
111
  SET_BLACK_LIST = "setBlackList.cgi",
@@ -325,6 +326,50 @@ declare const eventsDataSchema: z.ZodUnion<readonly [z.ZodObject<{
325
326
  ip: string;
326
327
  cgi: EUserActions.TRACK_ICAO;
327
328
  postJsonBody?: any;
329
+ }>, z.ZodObject<{
330
+ type: z.ZodLiteral<"USER_ACTION">;
331
+ cgi: z.ZodLiteral<EUserActions.TRACK_TARGET>;
332
+ ip: z.ZodString;
333
+ params: z.ZodObject<{
334
+ userId: z.ZodString;
335
+ userName: z.ZodString;
336
+ userPriority: z.ZodString;
337
+ } & {
338
+ targetId: z.ZodString;
339
+ }, "strip", z.ZodTypeAny, {
340
+ targetId: string;
341
+ userId: string;
342
+ userName: string;
343
+ userPriority: string;
344
+ }, {
345
+ targetId: string;
346
+ userId: string;
347
+ userName: string;
348
+ userPriority: string;
349
+ }>;
350
+ postJsonBody: z.ZodAny;
351
+ }, "strip", z.ZodTypeAny, {
352
+ params: {
353
+ targetId: string;
354
+ userId: string;
355
+ userName: string;
356
+ userPriority: string;
357
+ };
358
+ type: "USER_ACTION";
359
+ ip: string;
360
+ cgi: EUserActions.TRACK_TARGET;
361
+ postJsonBody?: any;
362
+ }, {
363
+ params: {
364
+ targetId: string;
365
+ userId: string;
366
+ userName: string;
367
+ userPriority: string;
368
+ };
369
+ type: "USER_ACTION";
370
+ ip: string;
371
+ cgi: EUserActions.TRACK_TARGET;
372
+ postJsonBody?: any;
328
373
  }>, z.ZodObject<{
329
374
  type: z.ZodLiteral<"USER_ACTION">;
330
375
  cgi: z.ZodLiteral<EUserActions.RESET_ICAO>;
@@ -1279,6 +1324,50 @@ export declare const ptrEventsSchema: z.ZodUnion<readonly [z.ZodObject<{
1279
1324
  ip: string;
1280
1325
  cgi: EUserActions.TRACK_ICAO;
1281
1326
  postJsonBody?: any;
1327
+ }>, z.ZodObject<{
1328
+ type: z.ZodLiteral<"USER_ACTION">;
1329
+ cgi: z.ZodLiteral<EUserActions.TRACK_TARGET>;
1330
+ ip: z.ZodString;
1331
+ params: z.ZodObject<{
1332
+ userId: z.ZodString;
1333
+ userName: z.ZodString;
1334
+ userPriority: z.ZodString;
1335
+ } & {
1336
+ targetId: z.ZodString;
1337
+ }, "strip", z.ZodTypeAny, {
1338
+ targetId: string;
1339
+ userId: string;
1340
+ userName: string;
1341
+ userPriority: string;
1342
+ }, {
1343
+ targetId: string;
1344
+ userId: string;
1345
+ userName: string;
1346
+ userPriority: string;
1347
+ }>;
1348
+ postJsonBody: z.ZodAny;
1349
+ }, "strip", z.ZodTypeAny, {
1350
+ params: {
1351
+ targetId: string;
1352
+ userId: string;
1353
+ userName: string;
1354
+ userPriority: string;
1355
+ };
1356
+ type: "USER_ACTION";
1357
+ ip: string;
1358
+ cgi: EUserActions.TRACK_TARGET;
1359
+ postJsonBody?: any;
1360
+ }, {
1361
+ params: {
1362
+ targetId: string;
1363
+ userId: string;
1364
+ userName: string;
1365
+ userPriority: string;
1366
+ };
1367
+ type: "USER_ACTION";
1368
+ ip: string;
1369
+ cgi: EUserActions.TRACK_TARGET;
1370
+ postJsonBody?: any;
1282
1371
  }>, z.ZodObject<{
1283
1372
  type: z.ZodLiteral<"USER_ACTION">;
1284
1373
  cgi: z.ZodLiteral<EUserActions.RESET_ICAO>;
@@ -2075,6 +2164,17 @@ export declare const ptrEventsSchema: z.ZodUnion<readonly [z.ZodObject<{
2075
2164
  ip: string;
2076
2165
  cgi: EUserActions.TRACK_ICAO;
2077
2166
  postJsonBody?: any;
2167
+ } | {
2168
+ params: {
2169
+ targetId: string;
2170
+ userId: string;
2171
+ userName: string;
2172
+ userPriority: string;
2173
+ };
2174
+ type: "USER_ACTION";
2175
+ ip: string;
2176
+ cgi: EUserActions.TRACK_TARGET;
2177
+ postJsonBody?: any;
2078
2178
  } | {
2079
2179
  params: {
2080
2180
  userId: string;
@@ -2293,6 +2393,17 @@ export declare const ptrEventsSchema: z.ZodUnion<readonly [z.ZodObject<{
2293
2393
  ip: string;
2294
2394
  cgi: EUserActions.TRACK_ICAO;
2295
2395
  postJsonBody?: any;
2396
+ } | {
2397
+ params: {
2398
+ targetId: string;
2399
+ userId: string;
2400
+ userName: string;
2401
+ userPriority: string;
2402
+ };
2403
+ type: "USER_ACTION";
2404
+ ip: string;
2405
+ cgi: EUserActions.TRACK_TARGET;
2406
+ postJsonBody?: any;
2296
2407
  } | {
2297
2408
  params: {
2298
2409
  userId: string;
@@ -2667,6 +2778,50 @@ export declare const ptrEventsSchema: z.ZodUnion<readonly [z.ZodObject<{
2667
2778
  ip: string;
2668
2779
  cgi: EUserActions.TRACK_ICAO;
2669
2780
  postJsonBody?: any;
2781
+ }>, z.ZodObject<{
2782
+ type: z.ZodLiteral<"USER_ACTION">;
2783
+ cgi: z.ZodLiteral<EUserActions.TRACK_TARGET>;
2784
+ ip: z.ZodString;
2785
+ params: z.ZodObject<{
2786
+ userId: z.ZodString;
2787
+ userName: z.ZodString;
2788
+ userPriority: z.ZodString;
2789
+ } & {
2790
+ targetId: z.ZodString;
2791
+ }, "strip", z.ZodTypeAny, {
2792
+ targetId: string;
2793
+ userId: string;
2794
+ userName: string;
2795
+ userPriority: string;
2796
+ }, {
2797
+ targetId: string;
2798
+ userId: string;
2799
+ userName: string;
2800
+ userPriority: string;
2801
+ }>;
2802
+ postJsonBody: z.ZodAny;
2803
+ }, "strip", z.ZodTypeAny, {
2804
+ params: {
2805
+ targetId: string;
2806
+ userId: string;
2807
+ userName: string;
2808
+ userPriority: string;
2809
+ };
2810
+ type: "USER_ACTION";
2811
+ ip: string;
2812
+ cgi: EUserActions.TRACK_TARGET;
2813
+ postJsonBody?: any;
2814
+ }, {
2815
+ params: {
2816
+ targetId: string;
2817
+ userId: string;
2818
+ userName: string;
2819
+ userPriority: string;
2820
+ };
2821
+ type: "USER_ACTION";
2822
+ ip: string;
2823
+ cgi: EUserActions.TRACK_TARGET;
2824
+ postJsonBody?: any;
2670
2825
  }>, z.ZodObject<{
2671
2826
  type: z.ZodLiteral<"USER_ACTION">;
2672
2827
  cgi: z.ZodLiteral<EUserActions.RESET_ICAO>;
@@ -45,6 +45,7 @@ const apiUserSchema = userSchema.extend({
45
45
  var EUserActions;
46
46
  (function (EUserActions) {
47
47
  EUserActions["TRACK_ICAO"] = "trackIcao.cgi";
48
+ EUserActions["TRACK_TARGET"] = "trackTarget.cgi";
48
49
  EUserActions["RESET_ICAO"] = "resetIcao.cgi";
49
50
  EUserActions["SET_PRIORITY_LIST"] = "setPriorityList.cgi";
50
51
  EUserActions["SET_BLACK_LIST"] = "setBlackList.cgi";
@@ -74,6 +75,13 @@ const eventsDataSchema = zod_1.z.union([
74
75
  params: userSchema.extend({ icao: zod_1.z.string() }),
75
76
  postJsonBody: zod_1.z.any(),
76
77
  }),
78
+ zod_1.z.object({
79
+ type: zod_1.z.literal('USER_ACTION'),
80
+ cgi: zod_1.z.literal(EUserActions.TRACK_TARGET),
81
+ ip: zod_1.z.string(),
82
+ params: userSchema.extend({ targetId: zod_1.z.string() }),
83
+ postJsonBody: zod_1.z.any(),
84
+ }),
77
85
  zod_1.z.object({
78
86
  type: zod_1.z.literal('USER_ACTION'),
79
87
  cgi: zod_1.z.literal(EUserActions.RESET_ICAO),
@@ -86,8 +86,8 @@ export class PlaneTrackerAPI extends BasicAPI {
86
86
  }
87
87
  }
88
88
  async getDomainList(options) {
89
- const res = await this._getJson(`${BASE_PATH}/getDomainList.cgi`, { action: 'get' }, options);
90
- return domainListSchema.parse(res);
89
+ const res = await this._getJson(`${BASE_PATH}/package/getDomainList.cgi`, { action: 'get' }, options);
90
+ return z.object({ domainList: domainListSchema }).parse(res).domainList;
91
91
  }
92
92
  async fetchFlightInfo(targetId, options) {
93
93
  const res = await this._getJson(`${BASE_PATH}/package/flightInfo.cgi`, { targetId }, options);
package/esm/VapixAPI.js CHANGED
@@ -1,9 +1,10 @@
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, } from './errors/errors';
3
+ import { ApplicationAPIError, MaxFPSError, NoDeviceInfoError, PtzNotSupportedError, ErrorWithResponse, SDCardActionError, SDCardJobError, SettingParameterError, TimezoneFetchError, PortManagementError, } from './errors/errors';
4
4
  import { z } from 'zod';
5
5
  import { XMLParser } from 'fast-xml-parser';
6
6
  import { BasicAPI } from './internal/BasicAPI';
7
+ import { PORT_PARAMS } from './internal/constants';
7
8
  export class VapixAPI extends BasicAPI {
8
9
  CustomFormData;
9
10
  constructor(client, CustomFormData = FormData) {
@@ -149,12 +150,24 @@ export class VapixAPI extends BasicAPI {
149
150
  console.warn('Failed to fetch time zone data from time API v2:', error instanceof Error ? error.message : JSON.stringify(error));
150
151
  console.warn('Falling back to deprecated time API v1');
151
152
  }
152
- const data = await this.getAllDateTimeInfo(options);
153
- if (data.data.timeZone === undefined) {
154
- console.warn('Timezone not set up on the camera, using POSIX time zone as fallback');
155
- return z.string().parse(data.data.posixTimeZone);
153
+ try {
154
+ const data = await this.getAllDateTimeInfo(options);
155
+ if (data.data.timeZone === undefined) {
156
+ console.warn('Timezone not set up on the camera, using POSIX time zone as fallback');
157
+ return z.string().parse(data.data.posixTimeZone);
158
+ }
159
+ return z.string().parse(data.data.timeZone);
160
+ }
161
+ catch (error) {
162
+ console.warn('Could not retreive timezone from either API endpoints, reading param.cgi');
163
+ const posixTimezone = (await this.getParameter('Time.POSIXTimeZone', options))['Time.POSIXTimeZone'];
164
+ if (posixTimezone !== undefined) {
165
+ return z.string().parse(posixTimezone);
166
+ }
167
+ else {
168
+ throw error;
169
+ }
156
170
  }
157
- return z.string().parse(data.data.timeZone);
158
171
  }
159
172
  async getAllDateTimeInfo(options) {
160
173
  const data = { apiVersion: '1.0', method: 'getAll' };
@@ -382,29 +395,61 @@ export class VapixAPI extends BasicAPI {
382
395
  });
383
396
  }
384
397
  async getPorts(options) {
385
- const res = await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
386
- apiVersion: '1.0',
387
- context: '',
388
- method: 'getPorts',
389
- }, undefined, options);
390
- const portResponseParsed = getPortsResponseSchema.parse(await res.json());
391
- return portResponseParsed.data.items ?? [];
398
+ try {
399
+ const res = await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
400
+ apiVersion: '1.0',
401
+ context: '',
402
+ method: 'getPorts',
403
+ }, undefined, options);
404
+ const portResponseParsed = getPortsResponseSchema.parse(await res.json());
405
+ return portResponseParsed.data.items ?? [];
406
+ }
407
+ catch (error) {
408
+ await this.checkPortsAvailable(error);
409
+ }
392
410
  }
393
411
  async setPorts(ports, options) {
394
- await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
395
- apiVersion: '1.0',
396
- context: '',
397
- method: 'setPorts',
398
- params: { ports },
399
- }, undefined, 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
+ }
400
423
  }
401
424
  async setPortStateSequence(port, sequence, options) {
402
- await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
403
- apiVersion: '1.0',
404
- context: '',
405
- method: 'setStateSequence',
406
- params: { port, sequence },
407
- }, undefined, 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
+ }
408
453
  }
409
454
  async addCameraUser(username, pass, sgrp, comment, options) {
410
455
  const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
@@ -188,3 +188,14 @@ 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
+ }
@@ -1,2 +1,6 @@
1
1
  export const FIRMWARE_WITH_BITRATE_MODES_SUPPORT = '11.11.73';
2
2
  export const FIRMWARE_WITH_OVERLAYS_SUPPORT = '10.7.0';
3
+ export const PORT_PARAMS = {
4
+ inputNbr: 'Input.NbrOfInputs',
5
+ outputNbr: 'Output.NbrOfOutputs',
6
+ };
@@ -42,6 +42,7 @@ const apiUserSchema = userSchema.extend({
42
42
  export var EUserActions;
43
43
  (function (EUserActions) {
44
44
  EUserActions["TRACK_ICAO"] = "trackIcao.cgi";
45
+ EUserActions["TRACK_TARGET"] = "trackTarget.cgi";
45
46
  EUserActions["RESET_ICAO"] = "resetIcao.cgi";
46
47
  EUserActions["SET_PRIORITY_LIST"] = "setPriorityList.cgi";
47
48
  EUserActions["SET_BLACK_LIST"] = "setBlackList.cgi";
@@ -71,6 +72,13 @@ const eventsDataSchema = z.union([
71
72
  params: userSchema.extend({ icao: z.string() }),
72
73
  postJsonBody: z.any(),
73
74
  }),
75
+ z.object({
76
+ type: z.literal('USER_ACTION'),
77
+ cgi: z.literal(EUserActions.TRACK_TARGET),
78
+ ip: z.string(),
79
+ params: userSchema.extend({ targetId: z.string() }),
80
+ postJsonBody: z.any(),
81
+ }),
74
82
  z.object({
75
83
  type: z.literal('USER_ACTION'),
76
84
  cgi: z.literal(EUserActions.RESET_ICAO),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camstreamerlib",
3
- "version": "4.0.10",
3
+ "version": "4.0.12",
4
4
  "description": "Helper library for CamStreamer ACAP applications.",
5
5
  "prettier": "@camstreamer/prettier-config",
6
6
  "engine": {
@@ -101,9 +101,10 @@ 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
- }[]>;
104
+ }[] | undefined>;
105
105
  setPorts(ports: TPortSetSchema[], options?: THttpRequestOptions): Promise<void>;
106
106
  setPortStateSequence(port: number, sequence: TPortSequenceStateSchema[], options?: THttpRequestOptions): Promise<void>;
107
+ private checkPortsAvailable;
107
108
  addCameraUser(username: string, pass: string, sgrp: string, comment?: string, options?: THttpRequestOptions): Promise<void>;
108
109
  getCameraUsers(options?: THttpRequestOptions): Promise<string[]>;
109
110
  editCameraUser(username: string, pass: string, options?: THttpRequestOptions): Promise<void>;
@@ -105,4 +105,11 @@ 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
+ }
108
115
  export {};
@@ -1,2 +1,6 @@
1
1
  export declare const FIRMWARE_WITH_BITRATE_MODES_SUPPORT = "11.11.73";
2
2
  export declare const FIRMWARE_WITH_OVERLAYS_SUPPORT = "10.7.0";
3
+ export declare const PORT_PARAMS: {
4
+ readonly inputNbr: "Input.NbrOfInputs";
5
+ readonly outputNbr: "Output.NbrOfOutputs";
6
+ };
@@ -105,6 +105,7 @@ declare const apiUserSchema: z.ZodObject<{
105
105
  export type TEventType = 'CAMERA_POSITION' | 'TRACKING_START' | 'TRACKING_STOP' | 'FLIGHT_LIST' | 'USER_ACTION' | 'CONNECTED_USERS' | 'FORCE_TRACKING_STATUS' | 'API_LOCK_STATUS';
106
106
  export declare enum EUserActions {
107
107
  TRACK_ICAO = "trackIcao.cgi",
108
+ TRACK_TARGET = "trackTarget.cgi",
108
109
  RESET_ICAO = "resetIcao.cgi",
109
110
  SET_PRIORITY_LIST = "setPriorityList.cgi",
110
111
  SET_BLACK_LIST = "setBlackList.cgi",
@@ -325,6 +326,50 @@ declare const eventsDataSchema: z.ZodUnion<readonly [z.ZodObject<{
325
326
  ip: string;
326
327
  cgi: EUserActions.TRACK_ICAO;
327
328
  postJsonBody?: any;
329
+ }>, z.ZodObject<{
330
+ type: z.ZodLiteral<"USER_ACTION">;
331
+ cgi: z.ZodLiteral<EUserActions.TRACK_TARGET>;
332
+ ip: z.ZodString;
333
+ params: z.ZodObject<{
334
+ userId: z.ZodString;
335
+ userName: z.ZodString;
336
+ userPriority: z.ZodString;
337
+ } & {
338
+ targetId: z.ZodString;
339
+ }, "strip", z.ZodTypeAny, {
340
+ targetId: string;
341
+ userId: string;
342
+ userName: string;
343
+ userPriority: string;
344
+ }, {
345
+ targetId: string;
346
+ userId: string;
347
+ userName: string;
348
+ userPriority: string;
349
+ }>;
350
+ postJsonBody: z.ZodAny;
351
+ }, "strip", z.ZodTypeAny, {
352
+ params: {
353
+ targetId: string;
354
+ userId: string;
355
+ userName: string;
356
+ userPriority: string;
357
+ };
358
+ type: "USER_ACTION";
359
+ ip: string;
360
+ cgi: EUserActions.TRACK_TARGET;
361
+ postJsonBody?: any;
362
+ }, {
363
+ params: {
364
+ targetId: string;
365
+ userId: string;
366
+ userName: string;
367
+ userPriority: string;
368
+ };
369
+ type: "USER_ACTION";
370
+ ip: string;
371
+ cgi: EUserActions.TRACK_TARGET;
372
+ postJsonBody?: any;
328
373
  }>, z.ZodObject<{
329
374
  type: z.ZodLiteral<"USER_ACTION">;
330
375
  cgi: z.ZodLiteral<EUserActions.RESET_ICAO>;
@@ -1279,6 +1324,50 @@ export declare const ptrEventsSchema: z.ZodUnion<readonly [z.ZodObject<{
1279
1324
  ip: string;
1280
1325
  cgi: EUserActions.TRACK_ICAO;
1281
1326
  postJsonBody?: any;
1327
+ }>, z.ZodObject<{
1328
+ type: z.ZodLiteral<"USER_ACTION">;
1329
+ cgi: z.ZodLiteral<EUserActions.TRACK_TARGET>;
1330
+ ip: z.ZodString;
1331
+ params: z.ZodObject<{
1332
+ userId: z.ZodString;
1333
+ userName: z.ZodString;
1334
+ userPriority: z.ZodString;
1335
+ } & {
1336
+ targetId: z.ZodString;
1337
+ }, "strip", z.ZodTypeAny, {
1338
+ targetId: string;
1339
+ userId: string;
1340
+ userName: string;
1341
+ userPriority: string;
1342
+ }, {
1343
+ targetId: string;
1344
+ userId: string;
1345
+ userName: string;
1346
+ userPriority: string;
1347
+ }>;
1348
+ postJsonBody: z.ZodAny;
1349
+ }, "strip", z.ZodTypeAny, {
1350
+ params: {
1351
+ targetId: string;
1352
+ userId: string;
1353
+ userName: string;
1354
+ userPriority: string;
1355
+ };
1356
+ type: "USER_ACTION";
1357
+ ip: string;
1358
+ cgi: EUserActions.TRACK_TARGET;
1359
+ postJsonBody?: any;
1360
+ }, {
1361
+ params: {
1362
+ targetId: string;
1363
+ userId: string;
1364
+ userName: string;
1365
+ userPriority: string;
1366
+ };
1367
+ type: "USER_ACTION";
1368
+ ip: string;
1369
+ cgi: EUserActions.TRACK_TARGET;
1370
+ postJsonBody?: any;
1282
1371
  }>, z.ZodObject<{
1283
1372
  type: z.ZodLiteral<"USER_ACTION">;
1284
1373
  cgi: z.ZodLiteral<EUserActions.RESET_ICAO>;
@@ -2075,6 +2164,17 @@ export declare const ptrEventsSchema: z.ZodUnion<readonly [z.ZodObject<{
2075
2164
  ip: string;
2076
2165
  cgi: EUserActions.TRACK_ICAO;
2077
2166
  postJsonBody?: any;
2167
+ } | {
2168
+ params: {
2169
+ targetId: string;
2170
+ userId: string;
2171
+ userName: string;
2172
+ userPriority: string;
2173
+ };
2174
+ type: "USER_ACTION";
2175
+ ip: string;
2176
+ cgi: EUserActions.TRACK_TARGET;
2177
+ postJsonBody?: any;
2078
2178
  } | {
2079
2179
  params: {
2080
2180
  userId: string;
@@ -2293,6 +2393,17 @@ export declare const ptrEventsSchema: z.ZodUnion<readonly [z.ZodObject<{
2293
2393
  ip: string;
2294
2394
  cgi: EUserActions.TRACK_ICAO;
2295
2395
  postJsonBody?: any;
2396
+ } | {
2397
+ params: {
2398
+ targetId: string;
2399
+ userId: string;
2400
+ userName: string;
2401
+ userPriority: string;
2402
+ };
2403
+ type: "USER_ACTION";
2404
+ ip: string;
2405
+ cgi: EUserActions.TRACK_TARGET;
2406
+ postJsonBody?: any;
2296
2407
  } | {
2297
2408
  params: {
2298
2409
  userId: string;
@@ -2667,6 +2778,50 @@ export declare const ptrEventsSchema: z.ZodUnion<readonly [z.ZodObject<{
2667
2778
  ip: string;
2668
2779
  cgi: EUserActions.TRACK_ICAO;
2669
2780
  postJsonBody?: any;
2781
+ }>, z.ZodObject<{
2782
+ type: z.ZodLiteral<"USER_ACTION">;
2783
+ cgi: z.ZodLiteral<EUserActions.TRACK_TARGET>;
2784
+ ip: z.ZodString;
2785
+ params: z.ZodObject<{
2786
+ userId: z.ZodString;
2787
+ userName: z.ZodString;
2788
+ userPriority: z.ZodString;
2789
+ } & {
2790
+ targetId: z.ZodString;
2791
+ }, "strip", z.ZodTypeAny, {
2792
+ targetId: string;
2793
+ userId: string;
2794
+ userName: string;
2795
+ userPriority: string;
2796
+ }, {
2797
+ targetId: string;
2798
+ userId: string;
2799
+ userName: string;
2800
+ userPriority: string;
2801
+ }>;
2802
+ postJsonBody: z.ZodAny;
2803
+ }, "strip", z.ZodTypeAny, {
2804
+ params: {
2805
+ targetId: string;
2806
+ userId: string;
2807
+ userName: string;
2808
+ userPriority: string;
2809
+ };
2810
+ type: "USER_ACTION";
2811
+ ip: string;
2812
+ cgi: EUserActions.TRACK_TARGET;
2813
+ postJsonBody?: any;
2814
+ }, {
2815
+ params: {
2816
+ targetId: string;
2817
+ userId: string;
2818
+ userName: string;
2819
+ userPriority: string;
2820
+ };
2821
+ type: "USER_ACTION";
2822
+ ip: string;
2823
+ cgi: EUserActions.TRACK_TARGET;
2824
+ postJsonBody?: any;
2670
2825
  }>, z.ZodObject<{
2671
2826
  type: z.ZodLiteral<"USER_ACTION">;
2672
2827
  cgi: z.ZodLiteral<EUserActions.RESET_ICAO>;