camstreamerlib 4.0.0-beta.16 → 4.0.0-beta.18

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.
@@ -1,30 +1,47 @@
1
- import { IClient, TResponse } from './internal/types';
1
+ import { IClient, TBlobResponse, TParameters, TResponse } from './internal/types';
2
+ import { TExportDataType, TImportDataType } from './types/PlaneTrackerAPI';
3
+ export type TApiUser = {
4
+ userId: string;
5
+ userName: string;
6
+ userPriority: number;
7
+ };
2
8
  type ICAO = string;
3
9
  export declare const BASE_URL = "/local/planetracker";
4
10
  export declare class PlaneTrackerAPI<Client extends IClient<TResponse> = IClient<TResponse>> {
5
11
  private client;
6
- constructor(client: Client);
12
+ private apiUser;
13
+ private _apiUserQuery;
14
+ constructor(client: Client, apiUser: TApiUser);
7
15
  static getProxyUrlPath: () => string;
8
16
  checkCameraTime(): Promise<boolean>;
9
17
  fetchCameraSettings: () => Promise<any>;
18
+ setCameraSettings: (settingsJsonString: string) => Promise<TResponse>;
10
19
  fetchServerSettings: () => Promise<any>;
11
20
  fetchMapInfo: () => Promise<any>;
12
21
  fetchFlightInfo: (icao: ICAO) => Promise<any>;
13
22
  getZones: () => Promise<any>;
14
- setZones: (zonesJsonString: string) => Promise<any>;
23
+ setZones: (zonesJsonString: string) => Promise<TResponse>;
15
24
  getPriorityList: () => Promise<any>;
16
- setPriorityList: (priorityListJsonString: string) => Promise<any>;
25
+ setPriorityList: (priorityListJsonString: string) => Promise<TResponse>;
17
26
  getWhiteList: () => Promise<any>;
18
- setWhiteList: (whiteListJsonString: string) => Promise<any>;
27
+ setWhiteList: (whiteListJsonString: string) => Promise<TResponse>;
19
28
  getBlackList: () => Promise<any>;
20
- setBlackList: (blackListJsonString: string) => Promise<any>;
29
+ setBlackList: (blackListJsonString: string) => Promise<TResponse>;
21
30
  getTrackingMode: () => Promise<any>;
22
- setTrackingMode: (modeJsonString: string) => Promise<any>;
31
+ setTrackingMode: (modeJsonString: string) => Promise<TResponse>;
23
32
  startTrackingPlane: (icao: ICAO) => Promise<TResponse>;
24
33
  stopTrackingPlane: () => Promise<TResponse>;
25
34
  goToCoordinates: (lat: number, lon: number, alt?: number) => Promise<TResponse>;
26
- private _get;
27
- private _post;
35
+ exportAppSettings: (dataType: TExportDataType) => Promise<TBlobResponse<Client>>;
36
+ importAppSettings: (dataType: TImportDataType, formData: FormData) => Promise<TResponse>;
37
+ resetPtzCalibration: () => Promise<TResponse>;
38
+ checkGenetecConnection: (params: TParameters) => Promise<TResponse>;
39
+ getGenetecCameraList: (params: TParameters) => Promise<any>;
40
+ serverRunCheck: () => Promise<TResponse>;
41
+ private _getJson;
42
+ private _getBlob;
43
+ private parseBlobResponse;
28
44
  private _postJsonEncoded;
45
+ private _postUrlEncoded;
29
46
  }
30
47
  export {};
@@ -3,11 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlaneTrackerAPI = exports.BASE_URL = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const utils_1 = require("./internal/utils");
6
+ const errors_1 = require("./errors/errors");
6
7
  exports.BASE_URL = '/local/planetracker';
7
8
  class PlaneTrackerAPI {
8
9
  client;
9
- constructor(client) {
10
+ apiUser;
11
+ _apiUserQuery;
12
+ constructor(client, apiUser) {
10
13
  this.client = client;
14
+ this.apiUser = apiUser;
15
+ this._apiUserQuery = `userId=${this.apiUser.userId}&userName=${this.apiUser.userName}&userPriority=${this.apiUser.userPriority}`;
11
16
  }
12
17
  static getProxyUrlPath = () => `${exports.BASE_URL}/proxy.cgi`;
13
18
  async checkCameraTime() {
@@ -27,7 +32,7 @@ class PlaneTrackerAPI {
27
32
  message: zod_1.z.string(),
28
33
  }),
29
34
  ]);
30
- const response = await this._get(`${exports.BASE_URL}/camera_time.cgi`);
35
+ const response = await this._getJson(`${exports.BASE_URL}/camera_time.cgi`);
31
36
  const cameraTime = responseSchema.parse(response);
32
37
  if (!cameraTime.state) {
33
38
  console.error(`Camera time check failed: ${cameraTime.reason} - ${cameraTime.message}`);
@@ -35,79 +40,131 @@ class PlaneTrackerAPI {
35
40
  return cameraTime.state;
36
41
  }
37
42
  fetchCameraSettings = async () => {
38
- return await this._get(`${exports.BASE_URL}/package_camera_settings.cgi?action=get`);
43
+ return await this._getJson(`${exports.BASE_URL}/package_camera_settings.cgi`, { action: 'get' });
44
+ };
45
+ setCameraSettings = async (settingsJsonString) => {
46
+ return await this._postJsonEncoded(`${exports.BASE_URL}/package_camera_settings.cgi`, settingsJsonString, {
47
+ action: 'set',
48
+ });
39
49
  };
40
50
  fetchServerSettings = async () => {
41
- return await this._get(`${exports.BASE_URL}/package_server_settings.cgi?action=get`);
51
+ return await this._getJson(`${exports.BASE_URL}/package_server_settings.cgi`, { action: 'get' });
42
52
  };
43
53
  fetchMapInfo = async () => {
44
- return await this._get(`${exports.BASE_URL}/package/getMapInfo.cgi`);
54
+ return await this._getJson(`${exports.BASE_URL}/package/getMapInfo.cgi`);
45
55
  };
46
56
  fetchFlightInfo = async (icao) => {
47
- return await this._get(`${exports.BASE_URL}/package/flightInfo.cgi?icao=${icao}`);
57
+ return await this._getJson(`${exports.BASE_URL}/package/flightInfo.cgi`, { icao: encodeURIComponent(icao) });
48
58
  };
49
59
  getZones = async () => {
50
- return await this._get(`${exports.BASE_URL}/package/getZones.cgi`);
60
+ return await this._getJson(`${exports.BASE_URL}/package/getZones.cgi`);
51
61
  };
52
62
  setZones = async (zonesJsonString) => {
53
- return await this._postJsonEncoded(`${exports.BASE_URL}/package/setZones.cgi`, zonesJsonString);
63
+ return await this._postJsonEncoded(`${exports.BASE_URL}/package/setZones.cgi?${this._apiUserQuery}`, zonesJsonString);
54
64
  };
55
65
  getPriorityList = async () => {
56
- return await this._get(`${exports.BASE_URL}/package/getPriorityList.cgi`);
66
+ return await this._getJson(`${exports.BASE_URL}/package/getPriorityList.cgi`);
57
67
  };
58
68
  setPriorityList = async (priorityListJsonString) => {
59
- return await this._postJsonEncoded(`${exports.BASE_URL}/package/setPriorityList.cgi`, priorityListJsonString);
69
+ return await this._postJsonEncoded(`${exports.BASE_URL}/package/setPriorityList.cgi?${this._apiUserQuery}`, priorityListJsonString);
60
70
  };
61
71
  getWhiteList = async () => {
62
- return await this._get(`${exports.BASE_URL}/package/getWhiteList.cgi`);
72
+ return await this._getJson(`${exports.BASE_URL}/package/getWhiteList.cgi`);
63
73
  };
64
74
  setWhiteList = async (whiteListJsonString) => {
65
- return await this._postJsonEncoded(`${exports.BASE_URL}/package/setWhiteList.cgi`, whiteListJsonString);
75
+ return await this._postJsonEncoded(`${exports.BASE_URL}/package/setWhiteList.cgi?${this._apiUserQuery}`, whiteListJsonString);
66
76
  };
67
77
  getBlackList = async () => {
68
- return await this._get(`${exports.BASE_URL}/package/getBlackList.cgi`);
78
+ return await this._getJson(`${exports.BASE_URL}/package/getBlackList.cgi`);
69
79
  };
70
80
  setBlackList = async (blackListJsonString) => {
71
- return await this._postJsonEncoded(`${exports.BASE_URL}/package/setBlackList.cgi`, blackListJsonString);
81
+ return await this._postJsonEncoded(`${exports.BASE_URL}/package/setBlackList.cgi?${this._apiUserQuery}`, blackListJsonString);
72
82
  };
73
83
  getTrackingMode = async () => {
74
- return await this._get(`${exports.BASE_URL}/package/getTrackingMode.cgi`);
84
+ return await this._getJson(`${exports.BASE_URL}/package/getTrackingMode.cgi`);
75
85
  };
76
86
  setTrackingMode = async (modeJsonString) => {
77
- return await this._postJsonEncoded(`${exports.BASE_URL}/package/setTrackingMode.cgi`, modeJsonString);
87
+ return await this._postJsonEncoded(`${exports.BASE_URL}/package/setTrackingMode.cgi?${this._apiUserQuery}`, modeJsonString);
78
88
  };
79
89
  startTrackingPlane = async (icao) => {
80
- return await this.client.get(`${exports.BASE_URL}/package/trackIcao.cgi?icao=${icao}`);
90
+ return await this.client.get(`${exports.BASE_URL}/package/trackIcao.cgi`, {
91
+ icao: encodeURIComponent(icao),
92
+ ...this.apiUser,
93
+ });
81
94
  };
82
95
  stopTrackingPlane = async () => {
83
- return await this.client.get(`${exports.BASE_URL}/package/resetIcao.cgi`);
96
+ return await this.client.get(`${exports.BASE_URL}/package/resetIcao.cgi?${this._apiUserQuery}`);
84
97
  };
85
98
  goToCoordinates = async (lat, lon, alt) => {
86
- const url = `${exports.BASE_URL}/package/goToCoordinates.cgi?lat=${lat}&lon=${lon}`;
99
+ const url = `${exports.BASE_URL}/package/goToCoordinates.cgi?lat=${lat}&lon=${lon}&${this._apiUserQuery}`;
87
100
  return await this.client.get(`${url}${alt !== undefined ? `&alt=${alt}` : ''}`);
88
101
  };
89
- async _get(...args) {
102
+ exportAppSettings = async (dataType) => {
103
+ return await this._getBlob(`${exports.BASE_URL}/package_data.cgi`, { action: 'EXPORT', dataType });
104
+ };
105
+ importAppSettings = async (dataType, formData) => {
106
+ return await this.client.post(`${exports.BASE_URL}/package_data.cgi`, formData, { action: 'IMPORT', dataType });
107
+ };
108
+ resetPtzCalibration = async () => {
109
+ return await this.client.get(`${exports.BASE_URL}/package/resetPtzCalibration.cgi`);
110
+ };
111
+ checkGenetecConnection = async (params) => {
112
+ return await this._postUrlEncoded(`${exports.BASE_URL}/package/checkGenetecConnection.cgi`, params);
113
+ };
114
+ getGenetecCameraList = async (params) => {
115
+ const res = await this._postUrlEncoded(`${exports.BASE_URL}/package/getGenetecCameraList.cgi`, params);
116
+ return await res.json();
117
+ };
118
+ serverRunCheck = async () => {
119
+ return await this.client.get(`${exports.BASE_URL}/package/serverRunCheck.cgi`);
120
+ };
121
+ async _getJson(...args) {
90
122
  const res = await this.client.get(...args);
91
123
  if (res.ok) {
92
- return (await res.json());
124
+ return await res.json();
93
125
  }
94
126
  else {
95
127
  throw new Error(await (0, utils_1.responseStringify)(res));
96
128
  }
97
129
  }
98
- async _post(...args) {
99
- const res = await this.client.post(...args);
130
+ async _getBlob(...args) {
131
+ const res = await this.client.get(...args);
100
132
  if (res.ok) {
101
- return (await res.json());
133
+ return await this.parseBlobResponse(res);
102
134
  }
103
135
  else {
104
136
  throw new Error(await (0, utils_1.responseStringify)(res));
105
137
  }
106
138
  }
139
+ async parseBlobResponse(response) {
140
+ try {
141
+ return (await response.blob());
142
+ }
143
+ catch (err) {
144
+ throw new errors_1.ParsingBlobError(err);
145
+ }
146
+ }
107
147
  async _postJsonEncoded(...args) {
108
148
  const [path, data, params, headers] = args;
109
149
  const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
110
- return this._post(path, data, params, { ...baseHeaders, ...headers });
150
+ const res = await this.client.post(path, data, params, { ...baseHeaders, ...headers });
151
+ if (res.ok) {
152
+ return res;
153
+ }
154
+ else {
155
+ throw new Error(await (0, utils_1.responseStringify)(res));
156
+ }
157
+ }
158
+ async _postUrlEncoded(path, params, headers) {
159
+ const data = (0, utils_1.paramToUrl)(params);
160
+ const baseHeaders = { 'Content-Type': 'application/x-www-form-urlencoded' };
161
+ const res = await this.client.post(path, data, {}, { ...baseHeaders, ...headers });
162
+ if (res.ok) {
163
+ return res;
164
+ }
165
+ else {
166
+ throw new Error(await (0, utils_1.responseStringify)(res));
167
+ }
111
168
  }
112
169
  }
113
170
  exports.PlaneTrackerAPI = PlaneTrackerAPI;
package/cjs/VapixAPI.d.ts CHANGED
@@ -26,7 +26,7 @@ export declare class VapixAPI<Client extends IClient<TResponse> = IClient<TRespo
26
26
  dstEnabled: boolean;
27
27
  localDateTime: string;
28
28
  posixTimeZone: string;
29
- timeZone: string;
29
+ timeZone?: string | undefined;
30
30
  };
31
31
  }>;
32
32
  getDevicesSettings(proxy?: TProxyParam): Promise<TAudioDevice[]>;
package/cjs/VapixAPI.js CHANGED
@@ -171,9 +171,27 @@ class VapixAPI {
171
171
  return captureMode.maxFPS;
172
172
  }
173
173
  async getTimezone(proxy = null) {
174
- const data = { apiVersion: '1.0', method: 'getDateTimeInfo' };
175
- const res = await this.postJson(proxy, '/axis-cgi/time.cgi', data);
176
- return (await res.json())?.timeZone ?? 'Europe/Prague';
174
+ try {
175
+ const resV2 = await this.client.get(proxy, '/config/rest/time/v2/timeZone');
176
+ if (!resV2.ok) {
177
+ throw new Error(await (0, utils_1.responseStringify)(resV2));
178
+ }
179
+ const json = await resV2.json();
180
+ const data = VapixAPI_1.timeZoneSchema.parse(json);
181
+ if (data.status === 'error') {
182
+ throw new Error(data.error.message);
183
+ }
184
+ return data.data.activeTimeZone;
185
+ }
186
+ catch (error) {
187
+ console.warn('Failed to fetch time zone data from time API v2:', error instanceof Error ? error.message : JSON.stringify(error));
188
+ console.warn('Falling back to deprecated time API v1');
189
+ }
190
+ const data = await this.getDateTimeInfo(proxy);
191
+ if (data.data.timeZone === undefined) {
192
+ throw new Error('Time zone not setup on the device');
193
+ }
194
+ return data.data.timeZone;
177
195
  }
178
196
  async getDateTimeInfo(proxy = null) {
179
197
  const data = { apiVersion: '1.0', method: 'getDateTimeInfo' };
package/cjs/index.d.ts CHANGED
@@ -15,3 +15,4 @@ export * from './types/CamSwitcherAPI';
15
15
  export * from './types/VapixAPI';
16
16
  export * from './types/CamOverlayAPI';
17
17
  export * from './models/CamOverlayAPI';
18
+ export * from './types/PlaneTrackerAPI';
package/cjs/index.js CHANGED
@@ -39,3 +39,4 @@ __exportStar(require("./types/CamSwitcherAPI"), exports);
39
39
  __exportStar(require("./types/VapixAPI"), exports);
40
40
  __exportStar(require("./types/CamOverlayAPI"), exports);
41
41
  __exportStar(require("./models/CamOverlayAPI"), exports);
42
+ __exportStar(require("./types/PlaneTrackerAPI"), exports);
@@ -0,0 +1,2 @@
1
+ export type TImportDataType = 'MAP_DATA' | 'SERVER_DATA' | 'ALL';
2
+ export type TExportDataType = 'NIGHT_SKY_CALIBRATION_DATA' | 'ALL';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1499,19 +1499,19 @@ export declare const dateTimeinfoSchema: z.ZodObject<{
1499
1499
  dstEnabled: z.ZodBoolean;
1500
1500
  localDateTime: z.ZodString;
1501
1501
  posixTimeZone: z.ZodString;
1502
- timeZone: z.ZodString;
1502
+ timeZone: z.ZodOptional<z.ZodString>;
1503
1503
  }, "strip", z.ZodTypeAny, {
1504
1504
  dateTime: string;
1505
1505
  dstEnabled: boolean;
1506
1506
  localDateTime: string;
1507
1507
  posixTimeZone: string;
1508
- timeZone: string;
1508
+ timeZone?: string | undefined;
1509
1509
  }, {
1510
1510
  dateTime: string;
1511
1511
  dstEnabled: boolean;
1512
1512
  localDateTime: string;
1513
1513
  posixTimeZone: string;
1514
- timeZone: string;
1514
+ timeZone?: string | undefined;
1515
1515
  }>;
1516
1516
  }, "strip", z.ZodTypeAny, {
1517
1517
  data: {
@@ -1519,7 +1519,7 @@ export declare const dateTimeinfoSchema: z.ZodObject<{
1519
1519
  dstEnabled: boolean;
1520
1520
  localDateTime: string;
1521
1521
  posixTimeZone: string;
1522
- timeZone: string;
1522
+ timeZone?: string | undefined;
1523
1523
  };
1524
1524
  }, {
1525
1525
  data: {
@@ -1527,9 +1527,48 @@ export declare const dateTimeinfoSchema: z.ZodObject<{
1527
1527
  dstEnabled: boolean;
1528
1528
  localDateTime: string;
1529
1529
  posixTimeZone: string;
1530
- timeZone: string;
1530
+ timeZone?: string | undefined;
1531
1531
  };
1532
1532
  }>;
1533
+ export declare const timeZoneSchema: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
1534
+ status: z.ZodLiteral<"success">;
1535
+ data: z.ZodObject<{
1536
+ activeTimeZone: z.ZodString;
1537
+ }, "strip", z.ZodTypeAny, {
1538
+ activeTimeZone: string;
1539
+ }, {
1540
+ activeTimeZone: string;
1541
+ }>;
1542
+ }, "strip", z.ZodTypeAny, {
1543
+ status: "success";
1544
+ data: {
1545
+ activeTimeZone: string;
1546
+ };
1547
+ }, {
1548
+ status: "success";
1549
+ data: {
1550
+ activeTimeZone: string;
1551
+ };
1552
+ }>, z.ZodObject<{
1553
+ status: z.ZodLiteral<"error">;
1554
+ error: z.ZodObject<{
1555
+ message: z.ZodString;
1556
+ }, "strip", z.ZodTypeAny, {
1557
+ message: string;
1558
+ }, {
1559
+ message: string;
1560
+ }>;
1561
+ }, "strip", z.ZodTypeAny, {
1562
+ status: "error";
1563
+ error: {
1564
+ message: string;
1565
+ };
1566
+ }, {
1567
+ status: "error";
1568
+ error: {
1569
+ message: string;
1570
+ };
1571
+ }>]>;
1533
1572
  export declare const audioSampleRatesResponseSchema: z.ZodObject<{
1534
1573
  data: z.ZodObject<{
1535
1574
  encoders: z.ZodObject<{
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.audioSampleRatesResponseSchema = exports.dateTimeinfoSchema = exports.maxFpsResponseSchema = exports.audioDeviceRequestSchema = exports.audioDeviceSchema = exports.audioDeviceInputOutputSchema = exports.audioDeviceConnectionTypeSchema = exports.audioDeviceSignalingTypeSchema = exports.audioDeviceSignalingChannelTypeSchema = exports.cameraPTZItemSchema = exports.cameraPTZItemDataSchema = exports.PtzOverviewSchema = exports.sdCardWatchedStatuses = exports.guardTourSchema = exports.APP_IDS = exports.applicationSchema = void 0;
3
+ 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.sdCardWatchedStatuses = exports.guardTourSchema = exports.APP_IDS = 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({
@@ -110,9 +110,23 @@ exports.dateTimeinfoSchema = zod_1.z.object({
110
110
  dstEnabled: zod_1.z.boolean(),
111
111
  localDateTime: zod_1.z.string(),
112
112
  posixTimeZone: zod_1.z.string(),
113
- timeZone: zod_1.z.string(),
113
+ timeZone: zod_1.z.string().optional(),
114
114
  }),
115
115
  });
116
+ exports.timeZoneSchema = zod_1.z.discriminatedUnion('status', [
117
+ zod_1.z.object({
118
+ status: zod_1.z.literal('success'),
119
+ data: zod_1.z.object({
120
+ activeTimeZone: zod_1.z.string(),
121
+ }),
122
+ }),
123
+ zod_1.z.object({
124
+ status: zod_1.z.literal('error'),
125
+ error: zod_1.z.object({
126
+ message: zod_1.z.string(),
127
+ }),
128
+ }),
129
+ ]);
116
130
  exports.audioSampleRatesResponseSchema = zod_1.z.object({
117
131
  data: zod_1.z.object({
118
132
  encoders: zod_1.z
@@ -30,7 +30,7 @@ class WsClient {
30
30
  };
31
31
  ws.onmessage = (e) => this.onmessage(e);
32
32
  ws.onclose = () => {
33
- this.restartTimeout = setTimeout(() => this.init(), REFRESH_TIMEOUT);
33
+ this.restartTimeout = window.setTimeout(() => this.init(), REFRESH_TIMEOUT);
34
34
  };
35
35
  this.ws = ws;
36
36
  }
@@ -43,7 +43,7 @@ class WsClient {
43
43
  this.destroyWebsocket();
44
44
  };
45
45
  destroyWebsocket() {
46
- if (this.restartTimeout) {
46
+ if (this.restartTimeout !== null) {
47
47
  clearTimeout(this.restartTimeout);
48
48
  this.restartTimeout = null;
49
49
  }
@@ -1,30 +1,47 @@
1
- import { IClient, TResponse } from './internal/types';
1
+ import { IClient, TBlobResponse, TParameters, TResponse } from './internal/types';
2
+ import { TExportDataType, TImportDataType } from './types/PlaneTrackerAPI';
3
+ export type TApiUser = {
4
+ userId: string;
5
+ userName: string;
6
+ userPriority: number;
7
+ };
2
8
  type ICAO = string;
3
9
  export declare const BASE_URL = "/local/planetracker";
4
10
  export declare class PlaneTrackerAPI<Client extends IClient<TResponse> = IClient<TResponse>> {
5
11
  private client;
6
- constructor(client: Client);
12
+ private apiUser;
13
+ private _apiUserQuery;
14
+ constructor(client: Client, apiUser: TApiUser);
7
15
  static getProxyUrlPath: () => string;
8
16
  checkCameraTime(): Promise<boolean>;
9
17
  fetchCameraSettings: () => Promise<any>;
18
+ setCameraSettings: (settingsJsonString: string) => Promise<TResponse>;
10
19
  fetchServerSettings: () => Promise<any>;
11
20
  fetchMapInfo: () => Promise<any>;
12
21
  fetchFlightInfo: (icao: ICAO) => Promise<any>;
13
22
  getZones: () => Promise<any>;
14
- setZones: (zonesJsonString: string) => Promise<any>;
23
+ setZones: (zonesJsonString: string) => Promise<TResponse>;
15
24
  getPriorityList: () => Promise<any>;
16
- setPriorityList: (priorityListJsonString: string) => Promise<any>;
25
+ setPriorityList: (priorityListJsonString: string) => Promise<TResponse>;
17
26
  getWhiteList: () => Promise<any>;
18
- setWhiteList: (whiteListJsonString: string) => Promise<any>;
27
+ setWhiteList: (whiteListJsonString: string) => Promise<TResponse>;
19
28
  getBlackList: () => Promise<any>;
20
- setBlackList: (blackListJsonString: string) => Promise<any>;
29
+ setBlackList: (blackListJsonString: string) => Promise<TResponse>;
21
30
  getTrackingMode: () => Promise<any>;
22
- setTrackingMode: (modeJsonString: string) => Promise<any>;
31
+ setTrackingMode: (modeJsonString: string) => Promise<TResponse>;
23
32
  startTrackingPlane: (icao: ICAO) => Promise<TResponse>;
24
33
  stopTrackingPlane: () => Promise<TResponse>;
25
34
  goToCoordinates: (lat: number, lon: number, alt?: number) => Promise<TResponse>;
26
- private _get;
27
- private _post;
35
+ exportAppSettings: (dataType: TExportDataType) => Promise<TBlobResponse<Client>>;
36
+ importAppSettings: (dataType: TImportDataType, formData: FormData) => Promise<TResponse>;
37
+ resetPtzCalibration: () => Promise<TResponse>;
38
+ checkGenetecConnection: (params: TParameters) => Promise<TResponse>;
39
+ getGenetecCameraList: (params: TParameters) => Promise<any>;
40
+ serverRunCheck: () => Promise<TResponse>;
41
+ private _getJson;
42
+ private _getBlob;
43
+ private parseBlobResponse;
28
44
  private _postJsonEncoded;
45
+ private _postUrlEncoded;
29
46
  }
30
47
  export {};
@@ -1,10 +1,15 @@
1
1
  import { z } from 'zod';
2
- import { responseStringify } from './internal/utils';
2
+ import { paramToUrl, responseStringify } from './internal/utils';
3
+ import { ParsingBlobError } from './errors/errors';
3
4
  export const BASE_URL = '/local/planetracker';
4
5
  export class PlaneTrackerAPI {
5
6
  client;
6
- constructor(client) {
7
+ apiUser;
8
+ _apiUserQuery;
9
+ constructor(client, apiUser) {
7
10
  this.client = client;
11
+ this.apiUser = apiUser;
12
+ this._apiUserQuery = `userId=${this.apiUser.userId}&userName=${this.apiUser.userName}&userPriority=${this.apiUser.userPriority}`;
8
13
  }
9
14
  static getProxyUrlPath = () => `${BASE_URL}/proxy.cgi`;
10
15
  async checkCameraTime() {
@@ -24,7 +29,7 @@ export class PlaneTrackerAPI {
24
29
  message: z.string(),
25
30
  }),
26
31
  ]);
27
- const response = await this._get(`${BASE_URL}/camera_time.cgi`);
32
+ const response = await this._getJson(`${BASE_URL}/camera_time.cgi`);
28
33
  const cameraTime = responseSchema.parse(response);
29
34
  if (!cameraTime.state) {
30
35
  console.error(`Camera time check failed: ${cameraTime.reason} - ${cameraTime.message}`);
@@ -32,78 +37,130 @@ export class PlaneTrackerAPI {
32
37
  return cameraTime.state;
33
38
  }
34
39
  fetchCameraSettings = async () => {
35
- return await this._get(`${BASE_URL}/package_camera_settings.cgi?action=get`);
40
+ return await this._getJson(`${BASE_URL}/package_camera_settings.cgi`, { action: 'get' });
41
+ };
42
+ setCameraSettings = async (settingsJsonString) => {
43
+ return await this._postJsonEncoded(`${BASE_URL}/package_camera_settings.cgi`, settingsJsonString, {
44
+ action: 'set',
45
+ });
36
46
  };
37
47
  fetchServerSettings = async () => {
38
- return await this._get(`${BASE_URL}/package_server_settings.cgi?action=get`);
48
+ return await this._getJson(`${BASE_URL}/package_server_settings.cgi`, { action: 'get' });
39
49
  };
40
50
  fetchMapInfo = async () => {
41
- return await this._get(`${BASE_URL}/package/getMapInfo.cgi`);
51
+ return await this._getJson(`${BASE_URL}/package/getMapInfo.cgi`);
42
52
  };
43
53
  fetchFlightInfo = async (icao) => {
44
- return await this._get(`${BASE_URL}/package/flightInfo.cgi?icao=${icao}`);
54
+ return await this._getJson(`${BASE_URL}/package/flightInfo.cgi`, { icao: encodeURIComponent(icao) });
45
55
  };
46
56
  getZones = async () => {
47
- return await this._get(`${BASE_URL}/package/getZones.cgi`);
57
+ return await this._getJson(`${BASE_URL}/package/getZones.cgi`);
48
58
  };
49
59
  setZones = async (zonesJsonString) => {
50
- return await this._postJsonEncoded(`${BASE_URL}/package/setZones.cgi`, zonesJsonString);
60
+ return await this._postJsonEncoded(`${BASE_URL}/package/setZones.cgi?${this._apiUserQuery}`, zonesJsonString);
51
61
  };
52
62
  getPriorityList = async () => {
53
- return await this._get(`${BASE_URL}/package/getPriorityList.cgi`);
63
+ return await this._getJson(`${BASE_URL}/package/getPriorityList.cgi`);
54
64
  };
55
65
  setPriorityList = async (priorityListJsonString) => {
56
- return await this._postJsonEncoded(`${BASE_URL}/package/setPriorityList.cgi`, priorityListJsonString);
66
+ return await this._postJsonEncoded(`${BASE_URL}/package/setPriorityList.cgi?${this._apiUserQuery}`, priorityListJsonString);
57
67
  };
58
68
  getWhiteList = async () => {
59
- return await this._get(`${BASE_URL}/package/getWhiteList.cgi`);
69
+ return await this._getJson(`${BASE_URL}/package/getWhiteList.cgi`);
60
70
  };
61
71
  setWhiteList = async (whiteListJsonString) => {
62
- return await this._postJsonEncoded(`${BASE_URL}/package/setWhiteList.cgi`, whiteListJsonString);
72
+ return await this._postJsonEncoded(`${BASE_URL}/package/setWhiteList.cgi?${this._apiUserQuery}`, whiteListJsonString);
63
73
  };
64
74
  getBlackList = async () => {
65
- return await this._get(`${BASE_URL}/package/getBlackList.cgi`);
75
+ return await this._getJson(`${BASE_URL}/package/getBlackList.cgi`);
66
76
  };
67
77
  setBlackList = async (blackListJsonString) => {
68
- return await this._postJsonEncoded(`${BASE_URL}/package/setBlackList.cgi`, blackListJsonString);
78
+ return await this._postJsonEncoded(`${BASE_URL}/package/setBlackList.cgi?${this._apiUserQuery}`, blackListJsonString);
69
79
  };
70
80
  getTrackingMode = async () => {
71
- return await this._get(`${BASE_URL}/package/getTrackingMode.cgi`);
81
+ return await this._getJson(`${BASE_URL}/package/getTrackingMode.cgi`);
72
82
  };
73
83
  setTrackingMode = async (modeJsonString) => {
74
- return await this._postJsonEncoded(`${BASE_URL}/package/setTrackingMode.cgi`, modeJsonString);
84
+ return await this._postJsonEncoded(`${BASE_URL}/package/setTrackingMode.cgi?${this._apiUserQuery}`, modeJsonString);
75
85
  };
76
86
  startTrackingPlane = async (icao) => {
77
- return await this.client.get(`${BASE_URL}/package/trackIcao.cgi?icao=${icao}`);
87
+ return await this.client.get(`${BASE_URL}/package/trackIcao.cgi`, {
88
+ icao: encodeURIComponent(icao),
89
+ ...this.apiUser,
90
+ });
78
91
  };
79
92
  stopTrackingPlane = async () => {
80
- return await this.client.get(`${BASE_URL}/package/resetIcao.cgi`);
93
+ return await this.client.get(`${BASE_URL}/package/resetIcao.cgi?${this._apiUserQuery}`);
81
94
  };
82
95
  goToCoordinates = async (lat, lon, alt) => {
83
- const url = `${BASE_URL}/package/goToCoordinates.cgi?lat=${lat}&lon=${lon}`;
96
+ const url = `${BASE_URL}/package/goToCoordinates.cgi?lat=${lat}&lon=${lon}&${this._apiUserQuery}`;
84
97
  return await this.client.get(`${url}${alt !== undefined ? `&alt=${alt}` : ''}`);
85
98
  };
86
- async _get(...args) {
99
+ exportAppSettings = async (dataType) => {
100
+ return await this._getBlob(`${BASE_URL}/package_data.cgi`, { action: 'EXPORT', dataType });
101
+ };
102
+ importAppSettings = async (dataType, formData) => {
103
+ return await this.client.post(`${BASE_URL}/package_data.cgi`, formData, { action: 'IMPORT', dataType });
104
+ };
105
+ resetPtzCalibration = async () => {
106
+ return await this.client.get(`${BASE_URL}/package/resetPtzCalibration.cgi`);
107
+ };
108
+ checkGenetecConnection = async (params) => {
109
+ return await this._postUrlEncoded(`${BASE_URL}/package/checkGenetecConnection.cgi`, params);
110
+ };
111
+ getGenetecCameraList = async (params) => {
112
+ const res = await this._postUrlEncoded(`${BASE_URL}/package/getGenetecCameraList.cgi`, params);
113
+ return await res.json();
114
+ };
115
+ serverRunCheck = async () => {
116
+ return await this.client.get(`${BASE_URL}/package/serverRunCheck.cgi`);
117
+ };
118
+ async _getJson(...args) {
87
119
  const res = await this.client.get(...args);
88
120
  if (res.ok) {
89
- return (await res.json());
121
+ return await res.json();
90
122
  }
91
123
  else {
92
124
  throw new Error(await responseStringify(res));
93
125
  }
94
126
  }
95
- async _post(...args) {
96
- const res = await this.client.post(...args);
127
+ async _getBlob(...args) {
128
+ const res = await this.client.get(...args);
97
129
  if (res.ok) {
98
- return (await res.json());
130
+ return await this.parseBlobResponse(res);
99
131
  }
100
132
  else {
101
133
  throw new Error(await responseStringify(res));
102
134
  }
103
135
  }
136
+ async parseBlobResponse(response) {
137
+ try {
138
+ return (await response.blob());
139
+ }
140
+ catch (err) {
141
+ throw new ParsingBlobError(err);
142
+ }
143
+ }
104
144
  async _postJsonEncoded(...args) {
105
145
  const [path, data, params, headers] = args;
106
146
  const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
107
- return this._post(path, data, params, { ...baseHeaders, ...headers });
147
+ const res = await this.client.post(path, data, params, { ...baseHeaders, ...headers });
148
+ if (res.ok) {
149
+ return res;
150
+ }
151
+ else {
152
+ throw new Error(await responseStringify(res));
153
+ }
154
+ }
155
+ async _postUrlEncoded(path, params, headers) {
156
+ const data = paramToUrl(params);
157
+ const baseHeaders = { 'Content-Type': 'application/x-www-form-urlencoded' };
158
+ const res = await this.client.post(path, data, {}, { ...baseHeaders, ...headers });
159
+ if (res.ok) {
160
+ return res;
161
+ }
162
+ else {
163
+ throw new Error(await responseStringify(res));
164
+ }
108
165
  }
109
166
  }
package/esm/VapixAPI.d.ts CHANGED
@@ -26,7 +26,7 @@ export declare class VapixAPI<Client extends IClient<TResponse> = IClient<TRespo
26
26
  dstEnabled: boolean;
27
27
  localDateTime: string;
28
28
  posixTimeZone: string;
29
- timeZone: string;
29
+ timeZone?: string | undefined;
30
30
  };
31
31
  }>;
32
32
  getDevicesSettings(proxy?: TProxyParam): Promise<TAudioDevice[]>;
package/esm/VapixAPI.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as prettifyXml from 'prettify-xml';
2
2
  import { arrayToUrl, isNullish, paramToUrl, responseStringify } from './internal/utils';
3
- import { sdCardWatchedStatuses, APP_IDS, maxFpsResponseSchema, dateTimeinfoSchema, audioDeviceRequestSchema, audioSampleRatesResponseSchema, } from './types/VapixAPI';
3
+ import { sdCardWatchedStatuses, APP_IDS, maxFpsResponseSchema, dateTimeinfoSchema, audioDeviceRequestSchema, audioSampleRatesResponseSchema, timeZoneSchema, } from './types/VapixAPI';
4
4
  import { ApplicationAPIError, MaxFPSError, NoDeviceInfoError, PtzNotSupportedError, SDCardActionError, SDCardJobError, } from './errors/errors';
5
5
  import { ProxyClient } from './internal/ProxyClient';
6
6
  import { z } from 'zod';
@@ -168,9 +168,27 @@ export class VapixAPI {
168
168
  return captureMode.maxFPS;
169
169
  }
170
170
  async getTimezone(proxy = null) {
171
- const data = { apiVersion: '1.0', method: 'getDateTimeInfo' };
172
- const res = await this.postJson(proxy, '/axis-cgi/time.cgi', data);
173
- return (await res.json())?.timeZone ?? 'Europe/Prague';
171
+ try {
172
+ const resV2 = await this.client.get(proxy, '/config/rest/time/v2/timeZone');
173
+ if (!resV2.ok) {
174
+ throw new Error(await responseStringify(resV2));
175
+ }
176
+ const json = await resV2.json();
177
+ const data = timeZoneSchema.parse(json);
178
+ if (data.status === 'error') {
179
+ throw new Error(data.error.message);
180
+ }
181
+ return data.data.activeTimeZone;
182
+ }
183
+ catch (error) {
184
+ console.warn('Failed to fetch time zone data from time API v2:', error instanceof Error ? error.message : JSON.stringify(error));
185
+ console.warn('Falling back to deprecated time API v1');
186
+ }
187
+ const data = await this.getDateTimeInfo(proxy);
188
+ if (data.data.timeZone === undefined) {
189
+ throw new Error('Time zone not setup on the device');
190
+ }
191
+ return data.data.timeZone;
174
192
  }
175
193
  async getDateTimeInfo(proxy = null) {
176
194
  const data = { apiVersion: '1.0', method: 'getDateTimeInfo' };
package/esm/index.d.ts CHANGED
@@ -15,3 +15,4 @@ export * from './types/CamSwitcherAPI';
15
15
  export * from './types/VapixAPI';
16
16
  export * from './types/CamOverlayAPI';
17
17
  export * from './models/CamOverlayAPI';
18
+ export * from './types/PlaneTrackerAPI';
package/esm/index.js CHANGED
@@ -15,3 +15,4 @@ export * from './types/CamSwitcherAPI';
15
15
  export * from './types/VapixAPI';
16
16
  export * from './types/CamOverlayAPI';
17
17
  export * from './models/CamOverlayAPI';
18
+ export * from './types/PlaneTrackerAPI';
@@ -0,0 +1,2 @@
1
+ export type TImportDataType = 'MAP_DATA' | 'SERVER_DATA' | 'ALL';
2
+ export type TExportDataType = 'NIGHT_SKY_CALIBRATION_DATA' | 'ALL';
@@ -0,0 +1 @@
1
+ export {};
@@ -1499,19 +1499,19 @@ export declare const dateTimeinfoSchema: z.ZodObject<{
1499
1499
  dstEnabled: z.ZodBoolean;
1500
1500
  localDateTime: z.ZodString;
1501
1501
  posixTimeZone: z.ZodString;
1502
- timeZone: z.ZodString;
1502
+ timeZone: z.ZodOptional<z.ZodString>;
1503
1503
  }, "strip", z.ZodTypeAny, {
1504
1504
  dateTime: string;
1505
1505
  dstEnabled: boolean;
1506
1506
  localDateTime: string;
1507
1507
  posixTimeZone: string;
1508
- timeZone: string;
1508
+ timeZone?: string | undefined;
1509
1509
  }, {
1510
1510
  dateTime: string;
1511
1511
  dstEnabled: boolean;
1512
1512
  localDateTime: string;
1513
1513
  posixTimeZone: string;
1514
- timeZone: string;
1514
+ timeZone?: string | undefined;
1515
1515
  }>;
1516
1516
  }, "strip", z.ZodTypeAny, {
1517
1517
  data: {
@@ -1519,7 +1519,7 @@ export declare const dateTimeinfoSchema: z.ZodObject<{
1519
1519
  dstEnabled: boolean;
1520
1520
  localDateTime: string;
1521
1521
  posixTimeZone: string;
1522
- timeZone: string;
1522
+ timeZone?: string | undefined;
1523
1523
  };
1524
1524
  }, {
1525
1525
  data: {
@@ -1527,9 +1527,48 @@ export declare const dateTimeinfoSchema: z.ZodObject<{
1527
1527
  dstEnabled: boolean;
1528
1528
  localDateTime: string;
1529
1529
  posixTimeZone: string;
1530
- timeZone: string;
1530
+ timeZone?: string | undefined;
1531
1531
  };
1532
1532
  }>;
1533
+ export declare const timeZoneSchema: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
1534
+ status: z.ZodLiteral<"success">;
1535
+ data: z.ZodObject<{
1536
+ activeTimeZone: z.ZodString;
1537
+ }, "strip", z.ZodTypeAny, {
1538
+ activeTimeZone: string;
1539
+ }, {
1540
+ activeTimeZone: string;
1541
+ }>;
1542
+ }, "strip", z.ZodTypeAny, {
1543
+ status: "success";
1544
+ data: {
1545
+ activeTimeZone: string;
1546
+ };
1547
+ }, {
1548
+ status: "success";
1549
+ data: {
1550
+ activeTimeZone: string;
1551
+ };
1552
+ }>, z.ZodObject<{
1553
+ status: z.ZodLiteral<"error">;
1554
+ error: z.ZodObject<{
1555
+ message: z.ZodString;
1556
+ }, "strip", z.ZodTypeAny, {
1557
+ message: string;
1558
+ }, {
1559
+ message: string;
1560
+ }>;
1561
+ }, "strip", z.ZodTypeAny, {
1562
+ status: "error";
1563
+ error: {
1564
+ message: string;
1565
+ };
1566
+ }, {
1567
+ status: "error";
1568
+ error: {
1569
+ message: string;
1570
+ };
1571
+ }>]>;
1533
1572
  export declare const audioSampleRatesResponseSchema: z.ZodObject<{
1534
1573
  data: z.ZodObject<{
1535
1574
  encoders: z.ZodObject<{
@@ -107,9 +107,23 @@ export const dateTimeinfoSchema = z.object({
107
107
  dstEnabled: z.boolean(),
108
108
  localDateTime: z.string(),
109
109
  posixTimeZone: z.string(),
110
- timeZone: z.string(),
110
+ timeZone: z.string().optional(),
111
111
  }),
112
112
  });
113
+ export const timeZoneSchema = z.discriminatedUnion('status', [
114
+ z.object({
115
+ status: z.literal('success'),
116
+ data: z.object({
117
+ activeTimeZone: z.string(),
118
+ }),
119
+ }),
120
+ z.object({
121
+ status: z.literal('error'),
122
+ error: z.object({
123
+ message: z.string(),
124
+ }),
125
+ }),
126
+ ]);
113
127
  export const audioSampleRatesResponseSchema = z.object({
114
128
  data: z.object({
115
129
  encoders: z
@@ -27,7 +27,7 @@ export class WsClient {
27
27
  };
28
28
  ws.onmessage = (e) => this.onmessage(e);
29
29
  ws.onclose = () => {
30
- this.restartTimeout = setTimeout(() => this.init(), REFRESH_TIMEOUT);
30
+ this.restartTimeout = window.setTimeout(() => this.init(), REFRESH_TIMEOUT);
31
31
  };
32
32
  this.ws = ws;
33
33
  }
@@ -40,7 +40,7 @@ export class WsClient {
40
40
  this.destroyWebsocket();
41
41
  };
42
42
  destroyWebsocket() {
43
- if (this.restartTimeout) {
43
+ if (this.restartTimeout !== null) {
44
44
  clearTimeout(this.restartTimeout);
45
45
  this.restartTimeout = null;
46
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camstreamerlib",
3
- "version": "4.0.0-beta.16",
3
+ "version": "4.0.0-beta.18",
4
4
  "description": "Helper library for CamStreamer ACAP applications.",
5
5
  "prettier": "@camstreamer/prettier-config",
6
6
  "dependencies": {