camstreamerlib 4.0.0-beta.159 → 4.0.0-beta.160

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.
@@ -9,7 +9,7 @@ export declare class PlaneTrackerAPI<Client extends IClient<TResponse, any>> ext
9
9
  static getWsEventsPath: () => string;
10
10
  checkAPIAvailable(options?: THttpRequestOptions): Promise<void>;
11
11
  checkCameraTime(options?: THttpRequestOptions): Promise<boolean>;
12
- serverRunCheck(options?: THttpRequestOptions): Promise<TResponse>;
12
+ serverRunCheck(options?: THttpRequestOptions): Promise<boolean>;
13
13
  getLiveViewAlias(rtspUrl: string, options?: THttpRequestOptions): Promise<{
14
14
  ws: string;
15
15
  ws_initial_message: string;
@@ -145,7 +145,7 @@ export declare class PlaneTrackerAPI<Client extends IClient<TResponse, any>> ext
145
145
  displaySystemInfo?: boolean | undefined;
146
146
  } | undefined;
147
147
  }>;
148
- setCameraSettings(settings: TCameraSettings, options?: THttpRequestOptions): Promise<TResponse>;
148
+ setCameraSettings(settings: TCameraSettings, options?: THttpRequestOptions): Promise<void>;
149
149
  fetchServerSettings(options?: THttpRequestOptions): Promise<{
150
150
  cameraCalibration: {
151
151
  posLat: number;
@@ -195,13 +195,13 @@ export declare class PlaneTrackerAPI<Client extends IClient<TResponse, any>> ext
195
195
  stopTrackingPlane(options?: THttpRequestOptions): Promise<void>;
196
196
  getIcao(by: TGetIcaoByOption, value: string, options?: THttpRequestOptions): Promise<string>;
197
197
  getPriorityList(options?: THttpRequestOptions): Promise<string[]>;
198
- setPriorityList(priorityList: TPriorityList['priorityList'], options?: THttpRequestOptions): Promise<TResponse>;
198
+ setPriorityList(priorityList: TPriorityList['priorityList'], options?: THttpRequestOptions): Promise<void>;
199
199
  getTypePriorityList(options?: THttpRequestOptions): Promise<string[]>;
200
- setTypePriorityList(typePriorityList: TTypePriorityList['typePriorityList'], options?: THttpRequestOptions): Promise<TResponse>;
200
+ setTypePriorityList(typePriorityList: TTypePriorityList['typePriorityList'], options?: THttpRequestOptions): Promise<void>;
201
201
  getWhiteList(options?: THttpRequestOptions): Promise<string[]>;
202
- setWhiteList(whiteList: TWhiteList['whiteList'], options?: THttpRequestOptions): Promise<TResponse>;
202
+ setWhiteList(whiteList: TWhiteList['whiteList'], options?: THttpRequestOptions): Promise<void>;
203
203
  getBlackList(options?: THttpRequestOptions): Promise<string[]>;
204
- setBlackList(blackList: TBlackList['blackList'], options?: THttpRequestOptions): Promise<TResponse>;
204
+ setBlackList(blackList: TBlackList['blackList'], options?: THttpRequestOptions): Promise<void>;
205
205
  fetchMapInfo(options?: THttpRequestOptions): Promise<{
206
206
  minZoom: number;
207
207
  maxZoom: number;
@@ -230,7 +230,7 @@ export declare class PlaneTrackerAPI<Client extends IClient<TResponse, any>> ext
230
230
  setZones(zones: TZones, options?: THttpRequestOptions): Promise<void>;
231
231
  goToCoordinates(lat: number, lon: number, alt?: number, options?: THttpRequestOptions): Promise<void>;
232
232
  downloadReport(options?: THttpRequestOptions): Promise<string>;
233
- checkGenetecConnection(params: TParameters, options?: THttpRequestOptions): Promise<TResponse>;
233
+ checkGenetecConnection(params: TParameters, options?: THttpRequestOptions): Promise<boolean>;
234
234
  getGenetecCameraList(params: TParameters, options?: THttpRequestOptions): Promise<{
235
235
  value: string;
236
236
  label: string;
@@ -24,7 +24,11 @@ class PlaneTrackerAPI extends BasicAPI_1.BasicAPI {
24
24
  }
25
25
  async serverRunCheck(options) {
26
26
  const agent = this.getClient(options?.proxyParams);
27
- return await agent.get({ path: `${BASE_PATH}/package/serverRunCheck.cgi`, timeout: options?.timeout });
27
+ const res = await agent.get({
28
+ path: `${BASE_PATH}/package/serverRunCheck.cgi`,
29
+ timeout: options?.timeout,
30
+ });
31
+ return res.status === 200;
28
32
  }
29
33
  async getLiveViewAlias(rtspUrl, options) {
30
34
  const agent = this.getClient(options?.proxyParams);
@@ -62,7 +66,7 @@ class PlaneTrackerAPI extends BasicAPI_1.BasicAPI {
62
66
  return PlaneTrackerAPI_1.cameraSettingsSchema.parse(res);
63
67
  }
64
68
  async setCameraSettings(settings, options) {
65
- return await this._postJsonEncoded(`${BASE_PATH}/package_camera_settings.cgi`, settings, {
69
+ await this._postJsonEncoded(`${BASE_PATH}/package_camera_settings.cgi`, settings, {
66
70
  action: 'set',
67
71
  }, options);
68
72
  }
@@ -121,28 +125,28 @@ class PlaneTrackerAPI extends BasicAPI_1.BasicAPI {
121
125
  return PlaneTrackerAPI_1.priorityListSchema.parse(res).priorityList;
122
126
  }
123
127
  async setPriorityList(priorityList, options) {
124
- return await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`, { priorityList }, this.apiUser, options);
128
+ await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`, { priorityList }, this.apiUser, options);
125
129
  }
126
130
  async getTypePriorityList(options) {
127
131
  const res = await this._getJson(`${BASE_PATH}/package/getTypePriorityList.cgi`, undefined, options);
128
132
  return PlaneTrackerAPI_1.typePriorityListSchema.parse(res).typePriorityList;
129
133
  }
130
134
  async setTypePriorityList(typePriorityList, options) {
131
- return await this._postJsonEncoded(`${BASE_PATH}/package/setTypePriorityList.cgi`, { typePriorityList }, this.apiUser, options);
135
+ await this._postJsonEncoded(`${BASE_PATH}/package/setTypePriorityList.cgi`, { typePriorityList }, this.apiUser, options);
132
136
  }
133
137
  async getWhiteList(options) {
134
138
  const res = await this._getJson(`${BASE_PATH}/package/getWhiteList.cgi`, undefined, options);
135
139
  return PlaneTrackerAPI_1.whiteListSchema.parse(res).whiteList;
136
140
  }
137
141
  async setWhiteList(whiteList, options) {
138
- return await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`, { whiteList }, this.apiUser, options);
142
+ await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`, { whiteList }, this.apiUser, options);
139
143
  }
140
144
  async getBlackList(options) {
141
145
  const res = await this._getJson(`${BASE_PATH}/package/getBlackList.cgi`, undefined, options);
142
146
  return PlaneTrackerAPI_1.blackListSchema.parse(res).blackList;
143
147
  }
144
148
  async setBlackList(blackList, options) {
145
- return await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`, { blackList }, this.apiUser, options);
149
+ await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`, { blackList }, this.apiUser, options);
146
150
  }
147
151
  async fetchMapInfo(options) {
148
152
  const res = await this._getJson(`${BASE_PATH}/package/getMapInfo.cgi`, undefined, options);
@@ -184,7 +188,8 @@ class PlaneTrackerAPI extends BasicAPI_1.BasicAPI {
184
188
  return this._getText(`${BASE_PATH}/report.cgi`, undefined, options);
185
189
  }
186
190
  async checkGenetecConnection(params, options) {
187
- return await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
191
+ const res = await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
192
+ return res.status === 200;
188
193
  }
189
194
  async getGenetecCameraList(params, options) {
190
195
  const res = await this._postUrlEncoded(`${BASE_PATH}/package/getGenetecCameraList.cgi`, params, options);
package/cjs/VapixAPI.d.ts CHANGED
@@ -27,7 +27,7 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
27
27
  private _doSDCardMountAction;
28
28
  fetchSDCardJobProgress(jobId: number, options?: THttpRequestOptions): Promise<number>;
29
29
  downloadCameraReport(options?: THttpRequestOptions): Promise<string>;
30
- getSystemLog(options?: THttpRequestOptions): Promise<TResponse>;
30
+ getSystemLog(options?: THttpRequestOptions): Promise<string>;
31
31
  getMaxFps(channel: number, options?: THttpRequestOptions): Promise<number>;
32
32
  getTimezone(options?: THttpRequestOptions): Promise<string>;
33
33
  getDateTimeInfo(options?: THttpRequestOptions): Promise<{
@@ -42,7 +42,7 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
42
42
  getDevicesSettings(options?: THttpRequestOptions): Promise<TAudioDevice[]>;
43
43
  fetchRemoteDeviceInfo<T extends Record<string, any>>(payload: T, options?: THttpRequestOptions): Promise<any>;
44
44
  getHeaders(options?: THttpRequestOptions): Promise<Record<string, string>>;
45
- setHeaders(headers: Record<string, string>, options?: THttpRequestOptions): Promise<TResponse>;
45
+ setHeaders(headers: Record<string, string>, options?: THttpRequestOptions): Promise<void>;
46
46
  getParameter(paramNames: string | string[], options?: THttpRequestOptions): Promise<Record<string, string>>;
47
47
  setParameter(params: Record<string, string | number | boolean>, options?: THttpRequestOptions): Promise<void>;
48
48
  getGuardTourList(options?: THttpRequestOptions): Promise<{
@@ -75,7 +75,7 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
75
75
  name: string;
76
76
  id: number;
77
77
  }[]>>;
78
- goToPreset(channel: number, presetName: string, options?: THttpRequestOptions): Promise<TResponse>;
78
+ goToPreset(channel: number, presetName: string, options?: THttpRequestOptions): Promise<void>;
79
79
  getPtzPosition(camera: number, options?: THttpRequestOptions): Promise<{
80
80
  pan?: number | undefined;
81
81
  tilt?: number | undefined;
@@ -93,13 +93,18 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
93
93
  }[]>;
94
94
  setPorts(ports: TPortSetSchema[], options?: THttpRequestOptions): Promise<void>;
95
95
  setPortStateSequence(port: number, sequence: TPortSequenceStateSchema[], options?: THttpRequestOptions): Promise<void>;
96
- addCameraUser(username: string, pass: string, sgrp: string, comment?: string, options?: THttpRequestOptions): Promise<TResponse>;
97
- getCameraUsers(options?: THttpRequestOptions): Promise<string>;
98
- editCameraUser(username: string, pass: string, options?: THttpRequestOptions): Promise<TResponse>;
99
- getRecordingRuleList(options?: THttpRequestOptions): Promise<Element | undefined>;
100
- addRecordingRule(params: Record<string, string>, options?: THttpRequestOptions): Promise<Element | undefined>;
101
- removeRecordingRule(profileId: string, options?: THttpRequestOptions): Promise<Element | undefined>;
102
- getDiskInfo(diskId?: string, options?: THttpRequestOptions): Promise<Element | undefined>;
96
+ addCameraUser(username: string, pass: string, sgrp: string, comment?: string, options?: THttpRequestOptions): Promise<void>;
97
+ getCameraUsers(options?: THttpRequestOptions): Promise<string[]>;
98
+ editCameraUser(username: string, pass: string, options?: THttpRequestOptions): Promise<void>;
99
+ getRecordingRuleList(options?: THttpRequestOptions): Promise<{
100
+ options: Record<string, string>;
101
+ diskid: string;
102
+ eventid: string;
103
+ profile: string;
104
+ }[]>;
105
+ addRecordingRule(params: Record<string, string>, options?: THttpRequestOptions): Promise<string | null>;
106
+ removeRecordingRule(profileId: string, options?: THttpRequestOptions): Promise<void>;
107
+ getDiskInfo(diskId?: string, options?: THttpRequestOptions): Promise<boolean>;
103
108
  getApplicationList(options?: THttpRequestOptions): Promise<{
104
109
  Name: string;
105
110
  NiceName: string;
@@ -117,6 +122,8 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
117
122
  restartApplication(applicationId: string, options?: THttpRequestOptions): Promise<void>;
118
123
  stopApplication(applicationId: string, options?: THttpRequestOptions): Promise<void>;
119
124
  installApplication(data: Parameters<typeof FormData.prototype.append>[1], fileName: string, options?: THttpRequestOptions): Promise<void>;
125
+ private static parseQueryString;
126
+ private static checkTextResponseForError;
120
127
  private static parseParameters;
121
128
  private static parseCameraPtzResponse;
122
129
  private static parsePtz;
package/cjs/VapixAPI.js CHANGED
@@ -160,8 +160,9 @@ class VapixAPI extends BasicAPI_1.BasicAPI {
160
160
  downloadCameraReport(options) {
161
161
  return this._getText('/axis-cgi/serverreport.cgi', { mode: 'text' }, options);
162
162
  }
163
- getSystemLog(options) {
164
- return this._postUrlEncoded('/axis-cgi/admin/systemlog.cgi', {}, options);
163
+ async getSystemLog(options) {
164
+ const res = await this._postUrlEncoded('/axis-cgi/admin/systemlog.cgi', {}, options);
165
+ return res.text();
165
166
  }
166
167
  async getMaxFps(channel, options) {
167
168
  const data = { apiVersion: '1.0', method: 'getCaptureModes' };
@@ -239,7 +240,7 @@ class VapixAPI extends BasicAPI_1.BasicAPI {
239
240
  }
240
241
  async setHeaders(headers, options) {
241
242
  const data = { apiVersion: '1.0', method: 'set', params: headers };
242
- return this._postJsonEncoded('/axis-cgi/customhttpheader.cgi', data, undefined, options);
243
+ await this._postJsonEncoded('/axis-cgi/customhttpheader.cgi', data, undefined, options);
243
244
  }
244
245
  async getParameter(paramNames, options) {
245
246
  const response = await this._postUrlEncoded('/axis-cgi/param.cgi', {
@@ -352,8 +353,8 @@ class VapixAPI extends BasicAPI_1.BasicAPI {
352
353
  });
353
354
  return VapixAPI_1.ptzOverviewSchema.parse(res);
354
355
  }
355
- goToPreset(channel, presetName, options) {
356
- return this._postUrlEncoded('/axis-cgi/com/ptz.cgi', {
356
+ async goToPreset(channel, presetName, options) {
357
+ await this._postUrlEncoded('/axis-cgi/com/ptz.cgi', {
357
358
  camera: channel.toString(),
358
359
  gotoserverpresetname: presetName,
359
360
  }, options);
@@ -396,7 +397,7 @@ class VapixAPI extends BasicAPI_1.BasicAPI {
396
397
  }, undefined, options);
397
398
  }
398
399
  async addCameraUser(username, pass, sgrp, comment, options) {
399
- return await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
400
+ const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
400
401
  action: 'add',
401
402
  user: username,
402
403
  pwd: pass,
@@ -404,39 +405,86 @@ class VapixAPI extends BasicAPI_1.BasicAPI {
404
405
  sgrp,
405
406
  comment,
406
407
  }, options);
408
+ await VapixAPI.checkTextResponseForError(res);
407
409
  }
408
410
  async getCameraUsers(options) {
409
411
  const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
410
412
  action: 'get',
411
413
  }, options);
412
- return await res.text();
414
+ const responseText = await VapixAPI.checkTextResponseForError(res);
415
+ const viewersString = responseText.match(/^viewer="([a-z0-9,]*)"/im)?.[1] ?? '';
416
+ return viewersString.split(',');
413
417
  }
414
418
  async editCameraUser(username, pass, options) {
415
- return await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
419
+ const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
416
420
  action: 'update',
417
421
  user: username,
418
422
  pwd: pass,
419
423
  }, options);
424
+ await VapixAPI.checkTextResponseForError(res);
420
425
  }
421
426
  async getRecordingRuleList(options) {
422
427
  const res = await this._getText('/axis-cgi/record/continuous/listconfiguration.cgi', undefined, options);
423
- return VapixAPI.parseXmlResponse(res, 'continuousrecordingconfigurations');
428
+ const resultNode = VapixAPI.parseXmlResponse(res, 'continuousrecordingconfigurations');
429
+ const configurationNodes = resultNode.getElementsByTagName('continuousrecordingconfiguration');
430
+ const configs = [];
431
+ for (const node of configurationNodes) {
432
+ if ((0, utils_1.isNullish)(node)) {
433
+ continue;
434
+ }
435
+ configs.push({
436
+ profile: node.getAttribute('profile') ?? '',
437
+ diskid: node.getAttribute('diskid') ?? '',
438
+ options: VapixAPI.parseQueryString(node.getAttribute('options')),
439
+ eventid: node.getAttribute('eventid') ?? '',
440
+ });
441
+ }
442
+ return configs;
424
443
  }
425
444
  async addRecordingRule(params, options) {
426
445
  const res = await this._getText('/axis-cgi/record/continuous/addconfiguration.cgi', params, options);
427
- return VapixAPI.parseXmlResponse(res, 'configure');
446
+ const resultNode = VapixAPI.parseXmlResponse(res, 'configure');
447
+ const result = resultNode.getAttribute('result');
448
+ if (result !== 'OK') {
449
+ throw new Error(resultNode.getAttribute('errormsg') ?? result ?? 'Unknown error');
450
+ }
451
+ return resultNode.getAttribute('profile');
428
452
  }
429
453
  async removeRecordingRule(profileId, options) {
430
454
  const res = await this._getText('/axis-cgi/record/continuous/removeconfiguration.cgi', {
431
455
  profile: profileId,
432
456
  }, options);
433
- return VapixAPI.parseXmlResponse(res, 'remove');
457
+ const resultNode = VapixAPI.parseXmlResponse(res, 'remove');
458
+ const result = resultNode.getAttribute('result');
459
+ if (result !== 'OK') {
460
+ throw new Error(resultNode.getAttribute('errormsg') ?? result ?? 'Unknown error');
461
+ }
434
462
  }
435
463
  async getDiskInfo(diskId = 'all', options) {
436
464
  const res = await this._getText('/axis-cgi/disks/list.cgi', {
437
465
  diskid: diskId,
438
466
  }, options);
439
- return VapixAPI.parseXmlResponse(res, 'disks');
467
+ const resultNode = VapixAPI.parseXmlResponse(res, 'disks');
468
+ const disks = resultNode.getElementsByTagName('disk');
469
+ if ((0, utils_1.isNullish)(disks) || disks.length === 0) {
470
+ return false;
471
+ }
472
+ const requiredReadyProps = {
473
+ status: 'OK',
474
+ locked: 'no',
475
+ readonly: 'no',
476
+ };
477
+ for (const disk of disks) {
478
+ let isReady = true;
479
+ for (const name in requiredReadyProps) {
480
+ const value = disk.getAttribute(name);
481
+ isReady = isReady && requiredReadyProps[name] === value;
482
+ }
483
+ if (isReady) {
484
+ return true;
485
+ }
486
+ }
487
+ return false;
440
488
  }
441
489
  async getApplicationList(options) {
442
490
  const agent = this.getClient(options?.proxyParams);
@@ -525,6 +573,21 @@ class VapixAPI extends BasicAPI_1.BasicAPI {
525
573
  throw new errors_1.ApplicationAPIError('INSTALL', text);
526
574
  }
527
575
  }
576
+ static parseQueryString = (queryString) => {
577
+ const entries = queryString
578
+ ?.split('&')
579
+ .filter((x) => x !== '')
580
+ .map((x) => x.split('=', 2));
581
+ return !(0, utils_1.isNullish)(entries) ? Object.fromEntries(entries) : {};
582
+ };
583
+ static checkTextResponseForError = async (response) => {
584
+ const responseText = await response.text();
585
+ const isError = responseText.match(/Error:([^<]*)/);
586
+ if (!(0, utils_1.isNullish)(isError)) {
587
+ throw new errors_1.ErrorWithResponse(response);
588
+ }
589
+ return responseText;
590
+ };
528
591
  static parseParameters = (response) => {
529
592
  const params = {};
530
593
  const lines = response.split(/[\r\n]/);
@@ -594,7 +657,7 @@ class VapixAPI extends BasicAPI_1.BasicAPI {
594
657
  static parseXmlResponse = (xml, nodeName) => {
595
658
  const doc = new DOMParser().parseFromString(xml, 'text/xml');
596
659
  const node = doc.getElementsByTagName(nodeName);
597
- if (node.length !== 1) {
660
+ if (node.length !== 1 || (0, utils_1.isNullish)(node[0])) {
598
661
  throw new Error('Invalid XML from camera');
599
662
  }
600
663
  return node[0];
@@ -1864,4 +1864,21 @@ export declare const portSequenceStateSchema: z.ZodObject<{
1864
1864
  time: number;
1865
1865
  }>;
1866
1866
  export type TPortSequenceStateSchema = z.infer<typeof portSequenceStateSchema>;
1867
+ export declare const recordingConfigItemSchema: z.ZodObject<{
1868
+ diskid: z.ZodString;
1869
+ eventid: z.ZodString;
1870
+ options: z.ZodRecord<z.ZodString, z.ZodString>;
1871
+ profile: z.ZodString;
1872
+ }, "strip", z.ZodTypeAny, {
1873
+ options: Record<string, string>;
1874
+ diskid: string;
1875
+ eventid: string;
1876
+ profile: string;
1877
+ }, {
1878
+ options: Record<string, string>;
1879
+ diskid: string;
1880
+ eventid: string;
1881
+ profile: string;
1882
+ }>;
1883
+ export type TRecordingConfigItem = z.infer<typeof recordingConfigItemSchema>;
1867
1884
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.portSequenceStateSchema = exports.portSetSchema = exports.getPortsResponseSchema = exports.portStatusSchema = exports.audioSampleRatesResponseSchema = exports.timeZoneSchema = exports.dateTimeinfoSchema = exports.maxFpsResponseSchema = exports.audioDeviceRequestSchema = exports.audioDeviceSchema = exports.audioDeviceInputOutputSchema = exports.audioDeviceConnectionTypeSchema = exports.audioDeviceSignalingTypeSchema = exports.audioDeviceSignalingChannelTypeSchema = exports.cameraPTZItemSchema = exports.cameraPTZItemDataSchema = exports.ptzOverviewSchema = exports.sdCardInfoSchema = exports.sdCardWatchedStatuses = exports.guardTourSchema = exports.ALL_APP_IDS = exports.APP_IDS = exports.applicationListSchema = exports.applicationSchema = void 0;
3
+ exports.recordingConfigItemSchema = exports.portSequenceStateSchema = exports.portSetSchema = exports.getPortsResponseSchema = exports.portStatusSchema = exports.audioSampleRatesResponseSchema = exports.timeZoneSchema = exports.dateTimeinfoSchema = exports.maxFpsResponseSchema = exports.audioDeviceRequestSchema = exports.audioDeviceSchema = exports.audioDeviceInputOutputSchema = exports.audioDeviceConnectionTypeSchema = exports.audioDeviceSignalingTypeSchema = exports.audioDeviceSignalingChannelTypeSchema = exports.cameraPTZItemSchema = exports.cameraPTZItemDataSchema = exports.ptzOverviewSchema = exports.sdCardInfoSchema = exports.sdCardWatchedStatuses = exports.guardTourSchema = exports.ALL_APP_IDS = exports.APP_IDS = exports.applicationListSchema = exports.applicationSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const transformers_1 = require("../internal/transformers");
6
6
  exports.applicationSchema = zod_1.z.object({
@@ -187,3 +187,9 @@ exports.portSequenceStateSchema = zod_1.z.object({
187
187
  state: zod_1.z.enum(['open', 'closed']),
188
188
  time: zod_1.z.number().min(0).max(65535),
189
189
  });
190
+ exports.recordingConfigItemSchema = zod_1.z.object({
191
+ diskid: zod_1.z.string(),
192
+ eventid: zod_1.z.string(),
193
+ options: zod_1.z.record(zod_1.z.string()),
194
+ profile: zod_1.z.string(),
195
+ });
@@ -21,7 +21,11 @@ export class PlaneTrackerAPI extends BasicAPI {
21
21
  }
22
22
  async serverRunCheck(options) {
23
23
  const agent = this.getClient(options?.proxyParams);
24
- return await agent.get({ path: `${BASE_PATH}/package/serverRunCheck.cgi`, timeout: options?.timeout });
24
+ const res = await agent.get({
25
+ path: `${BASE_PATH}/package/serverRunCheck.cgi`,
26
+ timeout: options?.timeout,
27
+ });
28
+ return res.status === 200;
25
29
  }
26
30
  async getLiveViewAlias(rtspUrl, options) {
27
31
  const agent = this.getClient(options?.proxyParams);
@@ -59,7 +63,7 @@ export class PlaneTrackerAPI extends BasicAPI {
59
63
  return cameraSettingsSchema.parse(res);
60
64
  }
61
65
  async setCameraSettings(settings, options) {
62
- return await this._postJsonEncoded(`${BASE_PATH}/package_camera_settings.cgi`, settings, {
66
+ await this._postJsonEncoded(`${BASE_PATH}/package_camera_settings.cgi`, settings, {
63
67
  action: 'set',
64
68
  }, options);
65
69
  }
@@ -118,28 +122,28 @@ export class PlaneTrackerAPI extends BasicAPI {
118
122
  return priorityListSchema.parse(res).priorityList;
119
123
  }
120
124
  async setPriorityList(priorityList, options) {
121
- return await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`, { priorityList }, this.apiUser, options);
125
+ await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`, { priorityList }, this.apiUser, options);
122
126
  }
123
127
  async getTypePriorityList(options) {
124
128
  const res = await this._getJson(`${BASE_PATH}/package/getTypePriorityList.cgi`, undefined, options);
125
129
  return typePriorityListSchema.parse(res).typePriorityList;
126
130
  }
127
131
  async setTypePriorityList(typePriorityList, options) {
128
- return await this._postJsonEncoded(`${BASE_PATH}/package/setTypePriorityList.cgi`, { typePriorityList }, this.apiUser, options);
132
+ await this._postJsonEncoded(`${BASE_PATH}/package/setTypePriorityList.cgi`, { typePriorityList }, this.apiUser, options);
129
133
  }
130
134
  async getWhiteList(options) {
131
135
  const res = await this._getJson(`${BASE_PATH}/package/getWhiteList.cgi`, undefined, options);
132
136
  return whiteListSchema.parse(res).whiteList;
133
137
  }
134
138
  async setWhiteList(whiteList, options) {
135
- return await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`, { whiteList }, this.apiUser, options);
139
+ await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`, { whiteList }, this.apiUser, options);
136
140
  }
137
141
  async getBlackList(options) {
138
142
  const res = await this._getJson(`${BASE_PATH}/package/getBlackList.cgi`, undefined, options);
139
143
  return blackListSchema.parse(res).blackList;
140
144
  }
141
145
  async setBlackList(blackList, options) {
142
- return await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`, { blackList }, this.apiUser, options);
146
+ await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`, { blackList }, this.apiUser, options);
143
147
  }
144
148
  async fetchMapInfo(options) {
145
149
  const res = await this._getJson(`${BASE_PATH}/package/getMapInfo.cgi`, undefined, options);
@@ -181,7 +185,8 @@ export class PlaneTrackerAPI extends BasicAPI {
181
185
  return this._getText(`${BASE_PATH}/report.cgi`, undefined, options);
182
186
  }
183
187
  async checkGenetecConnection(params, options) {
184
- return await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
188
+ const res = await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
189
+ return res.status === 200;
185
190
  }
186
191
  async getGenetecCameraList(params, options) {
187
192
  const res = await this._postUrlEncoded(`${BASE_PATH}/package/getGenetecCameraList.cgi`, params, options);
package/esm/VapixAPI.js CHANGED
@@ -157,8 +157,9 @@ export class VapixAPI extends BasicAPI {
157
157
  downloadCameraReport(options) {
158
158
  return this._getText('/axis-cgi/serverreport.cgi', { mode: 'text' }, options);
159
159
  }
160
- getSystemLog(options) {
161
- return this._postUrlEncoded('/axis-cgi/admin/systemlog.cgi', {}, options);
160
+ async getSystemLog(options) {
161
+ const res = await this._postUrlEncoded('/axis-cgi/admin/systemlog.cgi', {}, options);
162
+ return res.text();
162
163
  }
163
164
  async getMaxFps(channel, options) {
164
165
  const data = { apiVersion: '1.0', method: 'getCaptureModes' };
@@ -236,7 +237,7 @@ export class VapixAPI extends BasicAPI {
236
237
  }
237
238
  async setHeaders(headers, options) {
238
239
  const data = { apiVersion: '1.0', method: 'set', params: headers };
239
- return this._postJsonEncoded('/axis-cgi/customhttpheader.cgi', data, undefined, options);
240
+ await this._postJsonEncoded('/axis-cgi/customhttpheader.cgi', data, undefined, options);
240
241
  }
241
242
  async getParameter(paramNames, options) {
242
243
  const response = await this._postUrlEncoded('/axis-cgi/param.cgi', {
@@ -349,8 +350,8 @@ export class VapixAPI extends BasicAPI {
349
350
  });
350
351
  return ptzOverviewSchema.parse(res);
351
352
  }
352
- goToPreset(channel, presetName, options) {
353
- return this._postUrlEncoded('/axis-cgi/com/ptz.cgi', {
353
+ async goToPreset(channel, presetName, options) {
354
+ await this._postUrlEncoded('/axis-cgi/com/ptz.cgi', {
354
355
  camera: channel.toString(),
355
356
  gotoserverpresetname: presetName,
356
357
  }, options);
@@ -393,7 +394,7 @@ export class VapixAPI extends BasicAPI {
393
394
  }, undefined, options);
394
395
  }
395
396
  async addCameraUser(username, pass, sgrp, comment, options) {
396
- return await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
397
+ const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
397
398
  action: 'add',
398
399
  user: username,
399
400
  pwd: pass,
@@ -401,39 +402,86 @@ export class VapixAPI extends BasicAPI {
401
402
  sgrp,
402
403
  comment,
403
404
  }, options);
405
+ await VapixAPI.checkTextResponseForError(res);
404
406
  }
405
407
  async getCameraUsers(options) {
406
408
  const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
407
409
  action: 'get',
408
410
  }, options);
409
- return await res.text();
411
+ const responseText = await VapixAPI.checkTextResponseForError(res);
412
+ const viewersString = responseText.match(/^viewer="([a-z0-9,]*)"/im)?.[1] ?? '';
413
+ return viewersString.split(',');
410
414
  }
411
415
  async editCameraUser(username, pass, options) {
412
- return await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
416
+ const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
413
417
  action: 'update',
414
418
  user: username,
415
419
  pwd: pass,
416
420
  }, options);
421
+ await VapixAPI.checkTextResponseForError(res);
417
422
  }
418
423
  async getRecordingRuleList(options) {
419
424
  const res = await this._getText('/axis-cgi/record/continuous/listconfiguration.cgi', undefined, options);
420
- return VapixAPI.parseXmlResponse(res, 'continuousrecordingconfigurations');
425
+ const resultNode = VapixAPI.parseXmlResponse(res, 'continuousrecordingconfigurations');
426
+ const configurationNodes = resultNode.getElementsByTagName('continuousrecordingconfiguration');
427
+ const configs = [];
428
+ for (const node of configurationNodes) {
429
+ if (isNullish(node)) {
430
+ continue;
431
+ }
432
+ configs.push({
433
+ profile: node.getAttribute('profile') ?? '',
434
+ diskid: node.getAttribute('diskid') ?? '',
435
+ options: VapixAPI.parseQueryString(node.getAttribute('options')),
436
+ eventid: node.getAttribute('eventid') ?? '',
437
+ });
438
+ }
439
+ return configs;
421
440
  }
422
441
  async addRecordingRule(params, options) {
423
442
  const res = await this._getText('/axis-cgi/record/continuous/addconfiguration.cgi', params, options);
424
- return VapixAPI.parseXmlResponse(res, 'configure');
443
+ const resultNode = VapixAPI.parseXmlResponse(res, 'configure');
444
+ const result = resultNode.getAttribute('result');
445
+ if (result !== 'OK') {
446
+ throw new Error(resultNode.getAttribute('errormsg') ?? result ?? 'Unknown error');
447
+ }
448
+ return resultNode.getAttribute('profile');
425
449
  }
426
450
  async removeRecordingRule(profileId, options) {
427
451
  const res = await this._getText('/axis-cgi/record/continuous/removeconfiguration.cgi', {
428
452
  profile: profileId,
429
453
  }, options);
430
- return VapixAPI.parseXmlResponse(res, 'remove');
454
+ const resultNode = VapixAPI.parseXmlResponse(res, 'remove');
455
+ const result = resultNode.getAttribute('result');
456
+ if (result !== 'OK') {
457
+ throw new Error(resultNode.getAttribute('errormsg') ?? result ?? 'Unknown error');
458
+ }
431
459
  }
432
460
  async getDiskInfo(diskId = 'all', options) {
433
461
  const res = await this._getText('/axis-cgi/disks/list.cgi', {
434
462
  diskid: diskId,
435
463
  }, options);
436
- return VapixAPI.parseXmlResponse(res, 'disks');
464
+ const resultNode = VapixAPI.parseXmlResponse(res, 'disks');
465
+ const disks = resultNode.getElementsByTagName('disk');
466
+ if (isNullish(disks) || disks.length === 0) {
467
+ return false;
468
+ }
469
+ const requiredReadyProps = {
470
+ status: 'OK',
471
+ locked: 'no',
472
+ readonly: 'no',
473
+ };
474
+ for (const disk of disks) {
475
+ let isReady = true;
476
+ for (const name in requiredReadyProps) {
477
+ const value = disk.getAttribute(name);
478
+ isReady = isReady && requiredReadyProps[name] === value;
479
+ }
480
+ if (isReady) {
481
+ return true;
482
+ }
483
+ }
484
+ return false;
437
485
  }
438
486
  async getApplicationList(options) {
439
487
  const agent = this.getClient(options?.proxyParams);
@@ -522,6 +570,21 @@ export class VapixAPI extends BasicAPI {
522
570
  throw new ApplicationAPIError('INSTALL', text);
523
571
  }
524
572
  }
573
+ static parseQueryString = (queryString) => {
574
+ const entries = queryString
575
+ ?.split('&')
576
+ .filter((x) => x !== '')
577
+ .map((x) => x.split('=', 2));
578
+ return !isNullish(entries) ? Object.fromEntries(entries) : {};
579
+ };
580
+ static checkTextResponseForError = async (response) => {
581
+ const responseText = await response.text();
582
+ const isError = responseText.match(/Error:([^<]*)/);
583
+ if (!isNullish(isError)) {
584
+ throw new ErrorWithResponse(response);
585
+ }
586
+ return responseText;
587
+ };
525
588
  static parseParameters = (response) => {
526
589
  const params = {};
527
590
  const lines = response.split(/[\r\n]/);
@@ -591,7 +654,7 @@ export class VapixAPI extends BasicAPI {
591
654
  static parseXmlResponse = (xml, nodeName) => {
592
655
  const doc = new DOMParser().parseFromString(xml, 'text/xml');
593
656
  const node = doc.getElementsByTagName(nodeName);
594
- if (node.length !== 1) {
657
+ if (node.length !== 1 || isNullish(node[0])) {
595
658
  throw new Error('Invalid XML from camera');
596
659
  }
597
660
  return node[0];
@@ -184,3 +184,9 @@ export const portSequenceStateSchema = z.object({
184
184
  state: z.enum(['open', 'closed']),
185
185
  time: z.number().min(0).max(65535),
186
186
  });
187
+ export const recordingConfigItemSchema = z.object({
188
+ diskid: z.string(),
189
+ eventid: z.string(),
190
+ options: z.record(z.string()),
191
+ profile: z.string(),
192
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camstreamerlib",
3
- "version": "4.0.0-beta.159",
3
+ "version": "4.0.0-beta.160",
4
4
  "description": "Helper library for CamStreamer ACAP applications.",
5
5
  "prettier": "@camstreamer/prettier-config",
6
6
  "engine": {
@@ -9,7 +9,7 @@ export declare class PlaneTrackerAPI<Client extends IClient<TResponse, any>> ext
9
9
  static getWsEventsPath: () => string;
10
10
  checkAPIAvailable(options?: THttpRequestOptions): Promise<void>;
11
11
  checkCameraTime(options?: THttpRequestOptions): Promise<boolean>;
12
- serverRunCheck(options?: THttpRequestOptions): Promise<TResponse>;
12
+ serverRunCheck(options?: THttpRequestOptions): Promise<boolean>;
13
13
  getLiveViewAlias(rtspUrl: string, options?: THttpRequestOptions): Promise<{
14
14
  ws: string;
15
15
  ws_initial_message: string;
@@ -145,7 +145,7 @@ export declare class PlaneTrackerAPI<Client extends IClient<TResponse, any>> ext
145
145
  displaySystemInfo?: boolean | undefined;
146
146
  } | undefined;
147
147
  }>;
148
- setCameraSettings(settings: TCameraSettings, options?: THttpRequestOptions): Promise<TResponse>;
148
+ setCameraSettings(settings: TCameraSettings, options?: THttpRequestOptions): Promise<void>;
149
149
  fetchServerSettings(options?: THttpRequestOptions): Promise<{
150
150
  cameraCalibration: {
151
151
  posLat: number;
@@ -195,13 +195,13 @@ export declare class PlaneTrackerAPI<Client extends IClient<TResponse, any>> ext
195
195
  stopTrackingPlane(options?: THttpRequestOptions): Promise<void>;
196
196
  getIcao(by: TGetIcaoByOption, value: string, options?: THttpRequestOptions): Promise<string>;
197
197
  getPriorityList(options?: THttpRequestOptions): Promise<string[]>;
198
- setPriorityList(priorityList: TPriorityList['priorityList'], options?: THttpRequestOptions): Promise<TResponse>;
198
+ setPriorityList(priorityList: TPriorityList['priorityList'], options?: THttpRequestOptions): Promise<void>;
199
199
  getTypePriorityList(options?: THttpRequestOptions): Promise<string[]>;
200
- setTypePriorityList(typePriorityList: TTypePriorityList['typePriorityList'], options?: THttpRequestOptions): Promise<TResponse>;
200
+ setTypePriorityList(typePriorityList: TTypePriorityList['typePriorityList'], options?: THttpRequestOptions): Promise<void>;
201
201
  getWhiteList(options?: THttpRequestOptions): Promise<string[]>;
202
- setWhiteList(whiteList: TWhiteList['whiteList'], options?: THttpRequestOptions): Promise<TResponse>;
202
+ setWhiteList(whiteList: TWhiteList['whiteList'], options?: THttpRequestOptions): Promise<void>;
203
203
  getBlackList(options?: THttpRequestOptions): Promise<string[]>;
204
- setBlackList(blackList: TBlackList['blackList'], options?: THttpRequestOptions): Promise<TResponse>;
204
+ setBlackList(blackList: TBlackList['blackList'], options?: THttpRequestOptions): Promise<void>;
205
205
  fetchMapInfo(options?: THttpRequestOptions): Promise<{
206
206
  minZoom: number;
207
207
  maxZoom: number;
@@ -230,7 +230,7 @@ export declare class PlaneTrackerAPI<Client extends IClient<TResponse, any>> ext
230
230
  setZones(zones: TZones, options?: THttpRequestOptions): Promise<void>;
231
231
  goToCoordinates(lat: number, lon: number, alt?: number, options?: THttpRequestOptions): Promise<void>;
232
232
  downloadReport(options?: THttpRequestOptions): Promise<string>;
233
- checkGenetecConnection(params: TParameters, options?: THttpRequestOptions): Promise<TResponse>;
233
+ checkGenetecConnection(params: TParameters, options?: THttpRequestOptions): Promise<boolean>;
234
234
  getGenetecCameraList(params: TParameters, options?: THttpRequestOptions): Promise<{
235
235
  value: string;
236
236
  label: string;
@@ -27,7 +27,7 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
27
27
  private _doSDCardMountAction;
28
28
  fetchSDCardJobProgress(jobId: number, options?: THttpRequestOptions): Promise<number>;
29
29
  downloadCameraReport(options?: THttpRequestOptions): Promise<string>;
30
- getSystemLog(options?: THttpRequestOptions): Promise<TResponse>;
30
+ getSystemLog(options?: THttpRequestOptions): Promise<string>;
31
31
  getMaxFps(channel: number, options?: THttpRequestOptions): Promise<number>;
32
32
  getTimezone(options?: THttpRequestOptions): Promise<string>;
33
33
  getDateTimeInfo(options?: THttpRequestOptions): Promise<{
@@ -42,7 +42,7 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
42
42
  getDevicesSettings(options?: THttpRequestOptions): Promise<TAudioDevice[]>;
43
43
  fetchRemoteDeviceInfo<T extends Record<string, any>>(payload: T, options?: THttpRequestOptions): Promise<any>;
44
44
  getHeaders(options?: THttpRequestOptions): Promise<Record<string, string>>;
45
- setHeaders(headers: Record<string, string>, options?: THttpRequestOptions): Promise<TResponse>;
45
+ setHeaders(headers: Record<string, string>, options?: THttpRequestOptions): Promise<void>;
46
46
  getParameter(paramNames: string | string[], options?: THttpRequestOptions): Promise<Record<string, string>>;
47
47
  setParameter(params: Record<string, string | number | boolean>, options?: THttpRequestOptions): Promise<void>;
48
48
  getGuardTourList(options?: THttpRequestOptions): Promise<{
@@ -75,7 +75,7 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
75
75
  name: string;
76
76
  id: number;
77
77
  }[]>>;
78
- goToPreset(channel: number, presetName: string, options?: THttpRequestOptions): Promise<TResponse>;
78
+ goToPreset(channel: number, presetName: string, options?: THttpRequestOptions): Promise<void>;
79
79
  getPtzPosition(camera: number, options?: THttpRequestOptions): Promise<{
80
80
  pan?: number | undefined;
81
81
  tilt?: number | undefined;
@@ -93,13 +93,18 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
93
93
  }[]>;
94
94
  setPorts(ports: TPortSetSchema[], options?: THttpRequestOptions): Promise<void>;
95
95
  setPortStateSequence(port: number, sequence: TPortSequenceStateSchema[], options?: THttpRequestOptions): Promise<void>;
96
- addCameraUser(username: string, pass: string, sgrp: string, comment?: string, options?: THttpRequestOptions): Promise<TResponse>;
97
- getCameraUsers(options?: THttpRequestOptions): Promise<string>;
98
- editCameraUser(username: string, pass: string, options?: THttpRequestOptions): Promise<TResponse>;
99
- getRecordingRuleList(options?: THttpRequestOptions): Promise<Element | undefined>;
100
- addRecordingRule(params: Record<string, string>, options?: THttpRequestOptions): Promise<Element | undefined>;
101
- removeRecordingRule(profileId: string, options?: THttpRequestOptions): Promise<Element | undefined>;
102
- getDiskInfo(diskId?: string, options?: THttpRequestOptions): Promise<Element | undefined>;
96
+ addCameraUser(username: string, pass: string, sgrp: string, comment?: string, options?: THttpRequestOptions): Promise<void>;
97
+ getCameraUsers(options?: THttpRequestOptions): Promise<string[]>;
98
+ editCameraUser(username: string, pass: string, options?: THttpRequestOptions): Promise<void>;
99
+ getRecordingRuleList(options?: THttpRequestOptions): Promise<{
100
+ options: Record<string, string>;
101
+ diskid: string;
102
+ eventid: string;
103
+ profile: string;
104
+ }[]>;
105
+ addRecordingRule(params: Record<string, string>, options?: THttpRequestOptions): Promise<string | null>;
106
+ removeRecordingRule(profileId: string, options?: THttpRequestOptions): Promise<void>;
107
+ getDiskInfo(diskId?: string, options?: THttpRequestOptions): Promise<boolean>;
103
108
  getApplicationList(options?: THttpRequestOptions): Promise<{
104
109
  Name: string;
105
110
  NiceName: string;
@@ -117,6 +122,8 @@ export declare class VapixAPI<Client extends IClient<TResponse, any>> extends Ba
117
122
  restartApplication(applicationId: string, options?: THttpRequestOptions): Promise<void>;
118
123
  stopApplication(applicationId: string, options?: THttpRequestOptions): Promise<void>;
119
124
  installApplication(data: Parameters<typeof FormData.prototype.append>[1], fileName: string, options?: THttpRequestOptions): Promise<void>;
125
+ private static parseQueryString;
126
+ private static checkTextResponseForError;
120
127
  private static parseParameters;
121
128
  private static parseCameraPtzResponse;
122
129
  private static parsePtz;
@@ -1864,4 +1864,21 @@ export declare const portSequenceStateSchema: z.ZodObject<{
1864
1864
  time: number;
1865
1865
  }>;
1866
1866
  export type TPortSequenceStateSchema = z.infer<typeof portSequenceStateSchema>;
1867
+ export declare const recordingConfigItemSchema: z.ZodObject<{
1868
+ diskid: z.ZodString;
1869
+ eventid: z.ZodString;
1870
+ options: z.ZodRecord<z.ZodString, z.ZodString>;
1871
+ profile: z.ZodString;
1872
+ }, "strip", z.ZodTypeAny, {
1873
+ options: Record<string, string>;
1874
+ diskid: string;
1875
+ eventid: string;
1876
+ profile: string;
1877
+ }, {
1878
+ options: Record<string, string>;
1879
+ diskid: string;
1880
+ eventid: string;
1881
+ profile: string;
1882
+ }>;
1883
+ export type TRecordingConfigItem = z.infer<typeof recordingConfigItemSchema>;
1867
1884
  export {};