camstreamerlib 4.0.0-beta.56 → 4.0.0-beta.58
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.
- package/cjs/PlaneTrackerAPI.js +24 -5
- package/cjs/errors/errors.js +36 -1
- package/cjs/internal/WsEvents.js +4 -4
- package/cjs/types/CamScripterAPI.js +5 -4
- package/cjs/types/common.js +4 -2
- package/cjs/types/ws/PlaneTrackerEvents.js +77 -1
- package/cjs/ws/CamOverlayEvents.js +1 -1
- package/cjs/ws/CamStreamerEvents.js +1 -1
- package/cjs/ws/CamSwitcherEvents.js +1 -1
- package/cjs/ws/PlaneTrackerEvents.js +9 -1
- package/esm/PlaneTrackerAPI.js +25 -6
- package/esm/errors/errors.js +30 -0
- package/esm/internal/WsEvents.js +4 -4
- package/esm/types/CamScripterAPI.js +5 -4
- package/esm/types/common.js +3 -1
- package/esm/types/ws/PlaneTrackerEvents.js +76 -0
- package/esm/ws/CamOverlayEvents.js +1 -1
- package/esm/ws/CamStreamerEvents.js +1 -1
- package/esm/ws/CamSwitcherEvents.js +1 -1
- package/esm/ws/PlaneTrackerEvents.js +10 -2
- package/package.json +1 -1
- package/types/CamScripterAPI.d.ts +4 -4
- package/types/CamSwitcherAPI.d.ts +5 -5
- package/types/PlaneTrackerAPI.d.ts +3 -9
- package/types/errors/errors.d.ts +15 -0
- package/types/internal/WsEvents.d.ts +7 -9
- package/types/types/CamScripterAPI.d.ts +12 -12
- package/types/types/CamSwitcherAPI.d.ts +32 -32
- package/types/types/common.d.ts +2 -0
- package/types/types/ws/PlaneTrackerEvents.d.ts +560 -0
package/cjs/PlaneTrackerAPI.js
CHANGED
|
@@ -120,21 +120,21 @@ class PlaneTrackerAPI {
|
|
|
120
120
|
}
|
|
121
121
|
async getPriorityList(options) {
|
|
122
122
|
const res = await this._getJson(`${BASE_PATH}/package/getPriorityList.cgi`, undefined, options);
|
|
123
|
-
return PlaneTrackerAPI_1.priorityListSchema.parse(res);
|
|
123
|
+
return PlaneTrackerAPI_1.priorityListSchema.parse(res).priorityList;
|
|
124
124
|
}
|
|
125
125
|
async setPriorityList(priorityList, options) {
|
|
126
126
|
return await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`, { priorityList }, this.apiUser, options);
|
|
127
127
|
}
|
|
128
128
|
async getWhiteList(options) {
|
|
129
129
|
const res = await this._getJson(`${BASE_PATH}/package/getWhiteList.cgi`, undefined, options);
|
|
130
|
-
return PlaneTrackerAPI_1.whiteListSchema.parse(res);
|
|
130
|
+
return PlaneTrackerAPI_1.whiteListSchema.parse(res).whiteList;
|
|
131
131
|
}
|
|
132
132
|
async setWhiteList(whiteList, options) {
|
|
133
133
|
return await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`, { whiteList }, this.apiUser, options);
|
|
134
134
|
}
|
|
135
135
|
async getBlackList(options) {
|
|
136
136
|
const res = await this._getJson(`${BASE_PATH}/package/getBlackList.cgi`, undefined, options);
|
|
137
|
-
return PlaneTrackerAPI_1.blackListSchema.parse(res);
|
|
137
|
+
return PlaneTrackerAPI_1.blackListSchema.parse(res).blackList;
|
|
138
138
|
}
|
|
139
139
|
async setBlackList(blackList, options) {
|
|
140
140
|
return await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`, { blackList }, this.apiUser, options);
|
|
@@ -152,11 +152,30 @@ class PlaneTrackerAPI {
|
|
|
152
152
|
}
|
|
153
153
|
async goToCoordinates(lat, lon, alt, options) {
|
|
154
154
|
const agent = this.getClient(options?.proxyParams);
|
|
155
|
-
|
|
155
|
+
const res = await agent.get({
|
|
156
156
|
path: `${BASE_PATH}/package/goToCoordinates.cgi`,
|
|
157
157
|
parameters: { lat, lon, alt, ...this.apiUser },
|
|
158
158
|
timeout: options?.timeout,
|
|
159
|
-
})
|
|
159
|
+
});
|
|
160
|
+
if (!res.ok) {
|
|
161
|
+
const statusText = (await res.json()).statusText;
|
|
162
|
+
if (res.status === 400 && statusText === 'Cannot set coordinates in automatic mode') {
|
|
163
|
+
throw new errors_1.CannotSetCoordsInAutoModeError();
|
|
164
|
+
}
|
|
165
|
+
if (res.status === 400 && statusText === 'Invalid lat/lon parameters') {
|
|
166
|
+
throw new errors_1.InvalidLatLngError();
|
|
167
|
+
}
|
|
168
|
+
if (res.status === 400 && statusText === 'Invalid alt parameter') {
|
|
169
|
+
throw new errors_1.InvalidAltitudeError();
|
|
170
|
+
}
|
|
171
|
+
if (res.status === 400) {
|
|
172
|
+
throw new errors_1.BadRequestError(await (0, utils_1.responseStringify)(res));
|
|
173
|
+
}
|
|
174
|
+
if (res.status === 500) {
|
|
175
|
+
throw new errors_1.ServerError();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return res;
|
|
160
179
|
}
|
|
161
180
|
async checkGenetecConnection(params, options) {
|
|
162
181
|
return await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
|
package/cjs/errors/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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 = void 0;
|
|
3
|
+
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 = void 0;
|
|
4
4
|
class ServiceUnavailableError extends Error {
|
|
5
5
|
constructor() {
|
|
6
6
|
super('Service is unavailable.');
|
|
@@ -154,3 +154,38 @@ class ImportSettingsError extends Error {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
exports.ImportSettingsError = ImportSettingsError;
|
|
157
|
+
class CannotSetCoordsInAutoModeError extends Error {
|
|
158
|
+
constructor() {
|
|
159
|
+
super("The automatic mode doesn't allow control of the camera.");
|
|
160
|
+
this.name = 'CannotSetCoordsInAutoModeError';
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.CannotSetCoordsInAutoModeError = CannotSetCoordsInAutoModeError;
|
|
164
|
+
class InvalidLatLngError extends Error {
|
|
165
|
+
constructor() {
|
|
166
|
+
super('The provided latitude or longitude parameters are invalid.');
|
|
167
|
+
this.name = 'InvalidLatLngError';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.InvalidLatLngError = InvalidLatLngError;
|
|
171
|
+
class InvalidAltitudeError extends Error {
|
|
172
|
+
constructor() {
|
|
173
|
+
super('The provided altitude parameter is invalid.');
|
|
174
|
+
this.name = 'InvalidAltitudeError';
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.InvalidAltitudeError = InvalidAltitudeError;
|
|
178
|
+
class ServerError extends Error {
|
|
179
|
+
constructor() {
|
|
180
|
+
super('An internal server error occurred.');
|
|
181
|
+
this.name = 'ServerError';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.ServerError = ServerError;
|
|
185
|
+
class BadRequestError extends Error {
|
|
186
|
+
constructor(err) {
|
|
187
|
+
super('An unknown error occurred: ' + err);
|
|
188
|
+
this.name = 'UnknownError';
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.BadRequestError = BadRequestError;
|
package/cjs/internal/WsEvents.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WsEvents = void 0;
|
|
4
4
|
class WsEvents {
|
|
5
|
-
|
|
5
|
+
validate;
|
|
6
6
|
ws;
|
|
7
7
|
_isDestroyed = false;
|
|
8
8
|
listeners = {};
|
|
9
|
-
constructor(
|
|
10
|
-
this.
|
|
9
|
+
constructor(validate, ws) {
|
|
10
|
+
this.validate = validate;
|
|
11
11
|
this.ws = ws;
|
|
12
12
|
this.ws.onMessage = (e) => this.onMessage(e);
|
|
13
13
|
}
|
|
@@ -43,7 +43,7 @@ class WsEvents {
|
|
|
43
43
|
}
|
|
44
44
|
try {
|
|
45
45
|
const eventData = JSON.parse(incomeData.toString());
|
|
46
|
-
const data = this.
|
|
46
|
+
const data = this.validate(eventData);
|
|
47
47
|
if (isInitEvent(data)) {
|
|
48
48
|
this.processMessage(data.data, true);
|
|
49
49
|
return;
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cameraTimeResponseSchema = exports.camscripterApiResponseSchema = exports.cameraStorageSchema = exports.packageConfigSchema = exports.packageInfoListSchema = exports.nodeStateSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
const common_1 = require("./common");
|
|
5
6
|
exports.nodeStateSchema = zod_1.z.object({
|
|
6
7
|
node_state: zod_1.z.union([zod_1.z.literal('OK'), zod_1.z.literal('NOT_INSTALLED'), zod_1.z.literal('NOT_FOUND')]),
|
|
7
8
|
});
|
|
8
9
|
exports.packageInfoListSchema = zod_1.z.array(zod_1.z.object({
|
|
9
|
-
storage:
|
|
10
|
+
storage: common_1.storageTypeSchema,
|
|
10
11
|
manifest: zod_1.z.object({
|
|
11
12
|
package_name: zod_1.z.string(),
|
|
12
13
|
package_menu_name: zod_1.z.string(),
|
|
@@ -20,10 +21,10 @@ exports.packageInfoListSchema = zod_1.z.array(zod_1.z.object({
|
|
|
20
21
|
exports.packageConfigSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.object({ enabled: zod_1.z.boolean() }));
|
|
21
22
|
exports.cameraStorageSchema = zod_1.z.union([
|
|
22
23
|
zod_1.z.tuple([
|
|
23
|
-
zod_1.z.object({ type:
|
|
24
|
-
zod_1.z.object({ type:
|
|
24
|
+
zod_1.z.object({ type: common_1.flashStorageTypeSchema, capacity_mb: zod_1.z.number() }),
|
|
25
|
+
zod_1.z.object({ type: common_1.sdCardStorageTypeSchema, capacity_mb: zod_1.z.number() }),
|
|
25
26
|
]),
|
|
26
|
-
zod_1.z.tuple([zod_1.z.object({ type:
|
|
27
|
+
zod_1.z.tuple([zod_1.z.object({ type: common_1.flashStorageTypeSchema, capacity_mb: zod_1.z.number() })]),
|
|
27
28
|
]);
|
|
28
29
|
exports.camscripterApiResponseSchema = zod_1.z.object({
|
|
29
30
|
status: zod_1.z.number(),
|
package/cjs/types/common.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.keyboardShortcutsSchema = exports.keyboardShortcutSchema = exports.networkCameraListSchema = exports.storageTypeSchema = exports.h264ProfileSchema = exports.audioChannelCountSchema = exports.audioChannelSchema = void 0;
|
|
3
|
+
exports.keyboardShortcutsSchema = exports.keyboardShortcutSchema = exports.networkCameraListSchema = exports.storageTypeSchema = exports.sdCardStorageTypeSchema = exports.flashStorageTypeSchema = exports.h264ProfileSchema = exports.audioChannelCountSchema = exports.audioChannelSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
exports.audioChannelSchema = zod_1.z.union([zod_1.z.literal('mono'), zod_1.z.literal('stereo')]);
|
|
6
6
|
exports.audioChannelCountSchema = zod_1.z.union([zod_1.z.literal(1), zod_1.z.literal(2)]);
|
|
7
7
|
exports.h264ProfileSchema = zod_1.z.union([zod_1.z.literal('high'), zod_1.z.literal('main'), zod_1.z.literal('baseline')]);
|
|
8
|
-
exports.
|
|
8
|
+
exports.flashStorageTypeSchema = zod_1.z.literal('FLASH');
|
|
9
|
+
exports.sdCardStorageTypeSchema = zod_1.z.literal('SD_DISK');
|
|
10
|
+
exports.storageTypeSchema = zod_1.z.union([exports.sdCardStorageTypeSchema, exports.flashStorageTypeSchema]);
|
|
9
11
|
exports.networkCameraListSchema = zod_1.z.array(zod_1.z.object({
|
|
10
12
|
name: zod_1.z.string(),
|
|
11
13
|
ip: zod_1.z.string(),
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ptrEventsSchema = exports.PlaneTrackerUserActions = exports.PlaneTrackerWsEvents = void 0;
|
|
3
|
+
exports.ptrEventsSchema = exports.planeTrackerUserActionData = exports.PlaneTrackerUserActions = exports.PlaneTrackerWsEvents = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
const PlaneTrackerAPI_1 = require("../PlaneTrackerAPI");
|
|
5
6
|
const apiFlightDataSchema = zod_1.z.object({
|
|
6
7
|
icao: zod_1.z.string(),
|
|
7
8
|
lat: zod_1.z.number(),
|
|
@@ -54,6 +55,81 @@ var PlaneTrackerUserActions;
|
|
|
54
55
|
PlaneTrackerUserActions["LOCK_API"] = "lockApi.cgi";
|
|
55
56
|
PlaneTrackerUserActions["UNLOCK_API"] = "unlockApi.cgi";
|
|
56
57
|
})(PlaneTrackerUserActions || (exports.PlaneTrackerUserActions = PlaneTrackerUserActions = {}));
|
|
58
|
+
exports.planeTrackerUserActionData = zod_1.z.discriminatedUnion('cgi', [
|
|
59
|
+
zod_1.z.object({
|
|
60
|
+
cgi: zod_1.z.literal(PlaneTrackerUserActions.TRACK_ICAO),
|
|
61
|
+
ip: zod_1.z.string(),
|
|
62
|
+
params: apiStringUserSchema.extend({
|
|
63
|
+
icao: zod_1.z.string(),
|
|
64
|
+
}),
|
|
65
|
+
}),
|
|
66
|
+
zod_1.z.object({
|
|
67
|
+
cgi: zod_1.z.literal(PlaneTrackerUserActions.RESET_ICAO),
|
|
68
|
+
ip: zod_1.z.string(),
|
|
69
|
+
params: apiStringUserSchema,
|
|
70
|
+
}),
|
|
71
|
+
zod_1.z.object({
|
|
72
|
+
cgi: zod_1.z.literal(PlaneTrackerUserActions.SET_PRIORITY_LIST),
|
|
73
|
+
ip: zod_1.z.string(),
|
|
74
|
+
params: apiStringUserSchema,
|
|
75
|
+
postJsonBody: zod_1.z.object({
|
|
76
|
+
priorityList: zod_1.z.array(zod_1.z.string()),
|
|
77
|
+
}),
|
|
78
|
+
}),
|
|
79
|
+
zod_1.z.object({
|
|
80
|
+
cgi: zod_1.z.literal(PlaneTrackerUserActions.SET_BLACK_LIST),
|
|
81
|
+
ip: zod_1.z.string(),
|
|
82
|
+
params: apiStringUserSchema,
|
|
83
|
+
postJsonBody: zod_1.z.object({
|
|
84
|
+
blackList: zod_1.z.array(zod_1.z.string()),
|
|
85
|
+
}),
|
|
86
|
+
}),
|
|
87
|
+
zod_1.z.object({
|
|
88
|
+
cgi: zod_1.z.literal(PlaneTrackerUserActions.SET_WHITE_LIST),
|
|
89
|
+
ip: zod_1.z.string(),
|
|
90
|
+
params: apiStringUserSchema,
|
|
91
|
+
postJsonBody: zod_1.z.object({
|
|
92
|
+
whiteList: zod_1.z.array(zod_1.z.string()),
|
|
93
|
+
}),
|
|
94
|
+
}),
|
|
95
|
+
zod_1.z.object({
|
|
96
|
+
cgi: zod_1.z.literal(PlaneTrackerUserActions.GO_TO_COORDINATES),
|
|
97
|
+
ip: zod_1.z.string(),
|
|
98
|
+
params: apiStringUserSchema.extend({
|
|
99
|
+
lat: zod_1.z.string(),
|
|
100
|
+
lon: zod_1.z.string(),
|
|
101
|
+
}),
|
|
102
|
+
}),
|
|
103
|
+
zod_1.z.object({
|
|
104
|
+
cgi: zod_1.z.literal(PlaneTrackerUserActions.SET_TRACKING_MODE),
|
|
105
|
+
ip: zod_1.z.string(),
|
|
106
|
+
params: apiStringUserSchema,
|
|
107
|
+
postJsonBody: PlaneTrackerAPI_1.trackingModeSchema,
|
|
108
|
+
}),
|
|
109
|
+
zod_1.z.object({
|
|
110
|
+
cgi: zod_1.z.literal(PlaneTrackerUserActions.SET_ZONES),
|
|
111
|
+
ip: zod_1.z.string(),
|
|
112
|
+
params: apiStringUserSchema,
|
|
113
|
+
postJsonBody: PlaneTrackerAPI_1.zonesSchema,
|
|
114
|
+
}),
|
|
115
|
+
zod_1.z.object({
|
|
116
|
+
cgi: zod_1.z.literal(PlaneTrackerUserActions.RESET_PTZ_CALIBRATION),
|
|
117
|
+
ip: zod_1.z.string(),
|
|
118
|
+
params: apiStringUserSchema,
|
|
119
|
+
}),
|
|
120
|
+
zod_1.z.object({
|
|
121
|
+
cgi: zod_1.z.literal(PlaneTrackerUserActions.LOCK_API),
|
|
122
|
+
ip: zod_1.z.string(),
|
|
123
|
+
params: apiStringUserSchema.extend({
|
|
124
|
+
timeout: zod_1.z.string(),
|
|
125
|
+
}),
|
|
126
|
+
}),
|
|
127
|
+
zod_1.z.object({
|
|
128
|
+
cgi: zod_1.z.literal(PlaneTrackerUserActions.UNLOCK_API),
|
|
129
|
+
ip: zod_1.z.string(),
|
|
130
|
+
params: apiStringUserSchema,
|
|
131
|
+
}),
|
|
132
|
+
]);
|
|
57
133
|
const ptrEventsDataSchema = zod_1.z.discriminatedUnion('type', [
|
|
58
134
|
zod_1.z.object({
|
|
59
135
|
type: zod_1.z.literal('CAMERA_POSITION'),
|
|
@@ -6,7 +6,7 @@ const CamOverlayEvents_1 = require("../types/ws/CamOverlayEvents");
|
|
|
6
6
|
class CamOverlayEvents extends WsEvents_1.WsEvents {
|
|
7
7
|
getAuthToken;
|
|
8
8
|
constructor(ws, getAuthToken) {
|
|
9
|
-
super(CamOverlayEvents_1.coEventsSchema, ws);
|
|
9
|
+
super((data) => CamOverlayEvents_1.coEventsSchema.parse(data), ws);
|
|
10
10
|
this.getAuthToken = getAuthToken;
|
|
11
11
|
this.ws.onOpen = this.sendInitMsg;
|
|
12
12
|
}
|
|
@@ -6,7 +6,7 @@ const CamStreamerEvents_1 = require("../types/ws/CamStreamerEvents");
|
|
|
6
6
|
class CamStreamerEvents extends WsEvents_1.WsEvents {
|
|
7
7
|
getAuthToken;
|
|
8
8
|
constructor(ws, getAuthToken) {
|
|
9
|
-
super(CamStreamerEvents_1.csEventsSchema, ws);
|
|
9
|
+
super((data) => CamStreamerEvents_1.csEventsSchema.parse(data), ws);
|
|
10
10
|
this.getAuthToken = getAuthToken;
|
|
11
11
|
this.ws.onOpen = this.sendInitMsg;
|
|
12
12
|
}
|
|
@@ -6,7 +6,7 @@ const CamSwitcherEvents_1 = require("../types/ws/CamSwitcherEvents");
|
|
|
6
6
|
class CamSwitcherEvents extends WsEvents_1.WsEvents {
|
|
7
7
|
getAuthToken;
|
|
8
8
|
constructor(ws, getAuthToken) {
|
|
9
|
-
super(CamSwitcherEvents_1.cswEventsSchema, ws);
|
|
9
|
+
super((data) => CamSwitcherEvents_1.cswEventsSchema.parse(data), ws);
|
|
10
10
|
this.getAuthToken = getAuthToken;
|
|
11
11
|
this.ws.onOpen = this.sendInitMsg;
|
|
12
12
|
}
|
|
@@ -6,7 +6,15 @@ const PlaneTrackerEvents_1 = require("../types/ws/PlaneTrackerEvents");
|
|
|
6
6
|
class PlaneTrackerEvents extends WsEvents_1.WsEvents {
|
|
7
7
|
_apiUser;
|
|
8
8
|
constructor(ws, _apiUser) {
|
|
9
|
-
super(
|
|
9
|
+
super((data) => {
|
|
10
|
+
const parsedData = PlaneTrackerEvents_1.ptrEventsSchema.parse(data);
|
|
11
|
+
if (parsedData.type === PlaneTrackerEvents_1.PlaneTrackerWsEvents.USER_ACTION) {
|
|
12
|
+
const { type, ...actionData } = parsedData;
|
|
13
|
+
const userAction = PlaneTrackerEvents_1.planeTrackerUserActionData.parse(actionData);
|
|
14
|
+
return { ...userAction, type };
|
|
15
|
+
}
|
|
16
|
+
return parsedData;
|
|
17
|
+
}, ws);
|
|
10
18
|
this._apiUser = _apiUser;
|
|
11
19
|
this.ws.onOpen = this.sendInitMsg;
|
|
12
20
|
}
|
package/esm/PlaneTrackerAPI.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { paramToUrl, responseStringify } from './internal/utils';
|
|
3
3
|
import { blackListSchema, cameraSettingsSchema, flightInfoSchema, getIcaoSchema, mapInfoSchema, priorityListSchema, serverSettingsSchema, trackingModeSchema, whiteListSchema, wsAliasResponseSchema, zonesSchema, } from './types/PlaneTrackerAPI';
|
|
4
|
-
import { ImportSettingsError, ParsingBlobError, ResetCalibrationError } from './errors/errors';
|
|
4
|
+
import { CannotSetCoordsInAutoModeError, ImportSettingsError, InvalidAltitudeError, InvalidLatLngError, ParsingBlobError, ResetCalibrationError, ServerError, BadRequestError, } from './errors/errors';
|
|
5
5
|
import { ProxyClient } from './internal/ProxyClient';
|
|
6
6
|
import { cameraListSchema } from './types/GenetecAgent';
|
|
7
7
|
const BASE_PATH = '/local/planetracker';
|
|
@@ -117,21 +117,21 @@ export class PlaneTrackerAPI {
|
|
|
117
117
|
}
|
|
118
118
|
async getPriorityList(options) {
|
|
119
119
|
const res = await this._getJson(`${BASE_PATH}/package/getPriorityList.cgi`, undefined, options);
|
|
120
|
-
return priorityListSchema.parse(res);
|
|
120
|
+
return priorityListSchema.parse(res).priorityList;
|
|
121
121
|
}
|
|
122
122
|
async setPriorityList(priorityList, options) {
|
|
123
123
|
return await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`, { priorityList }, this.apiUser, options);
|
|
124
124
|
}
|
|
125
125
|
async getWhiteList(options) {
|
|
126
126
|
const res = await this._getJson(`${BASE_PATH}/package/getWhiteList.cgi`, undefined, options);
|
|
127
|
-
return whiteListSchema.parse(res);
|
|
127
|
+
return whiteListSchema.parse(res).whiteList;
|
|
128
128
|
}
|
|
129
129
|
async setWhiteList(whiteList, options) {
|
|
130
130
|
return await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`, { whiteList }, this.apiUser, options);
|
|
131
131
|
}
|
|
132
132
|
async getBlackList(options) {
|
|
133
133
|
const res = await this._getJson(`${BASE_PATH}/package/getBlackList.cgi`, undefined, options);
|
|
134
|
-
return blackListSchema.parse(res);
|
|
134
|
+
return blackListSchema.parse(res).blackList;
|
|
135
135
|
}
|
|
136
136
|
async setBlackList(blackList, options) {
|
|
137
137
|
return await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`, { blackList }, this.apiUser, options);
|
|
@@ -149,11 +149,30 @@ export class PlaneTrackerAPI {
|
|
|
149
149
|
}
|
|
150
150
|
async goToCoordinates(lat, lon, alt, options) {
|
|
151
151
|
const agent = this.getClient(options?.proxyParams);
|
|
152
|
-
|
|
152
|
+
const res = await agent.get({
|
|
153
153
|
path: `${BASE_PATH}/package/goToCoordinates.cgi`,
|
|
154
154
|
parameters: { lat, lon, alt, ...this.apiUser },
|
|
155
155
|
timeout: options?.timeout,
|
|
156
|
-
})
|
|
156
|
+
});
|
|
157
|
+
if (!res.ok) {
|
|
158
|
+
const statusText = (await res.json()).statusText;
|
|
159
|
+
if (res.status === 400 && statusText === 'Cannot set coordinates in automatic mode') {
|
|
160
|
+
throw new CannotSetCoordsInAutoModeError();
|
|
161
|
+
}
|
|
162
|
+
if (res.status === 400 && statusText === 'Invalid lat/lon parameters') {
|
|
163
|
+
throw new InvalidLatLngError();
|
|
164
|
+
}
|
|
165
|
+
if (res.status === 400 && statusText === 'Invalid alt parameter') {
|
|
166
|
+
throw new InvalidAltitudeError();
|
|
167
|
+
}
|
|
168
|
+
if (res.status === 400) {
|
|
169
|
+
throw new BadRequestError(await responseStringify(res));
|
|
170
|
+
}
|
|
171
|
+
if (res.status === 500) {
|
|
172
|
+
throw new ServerError();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return res;
|
|
157
176
|
}
|
|
158
177
|
async checkGenetecConnection(params, options) {
|
|
159
178
|
return await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
|
package/esm/errors/errors.js
CHANGED
|
@@ -130,3 +130,33 @@ export class ImportSettingsError extends Error {
|
|
|
130
130
|
this.name = 'ImportSettingsError';
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
+
export class CannotSetCoordsInAutoModeError extends Error {
|
|
134
|
+
constructor() {
|
|
135
|
+
super("The automatic mode doesn't allow control of the camera.");
|
|
136
|
+
this.name = 'CannotSetCoordsInAutoModeError';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export class InvalidLatLngError extends Error {
|
|
140
|
+
constructor() {
|
|
141
|
+
super('The provided latitude or longitude parameters are invalid.');
|
|
142
|
+
this.name = 'InvalidLatLngError';
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export class InvalidAltitudeError extends Error {
|
|
146
|
+
constructor() {
|
|
147
|
+
super('The provided altitude parameter is invalid.');
|
|
148
|
+
this.name = 'InvalidAltitudeError';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
export class ServerError extends Error {
|
|
152
|
+
constructor() {
|
|
153
|
+
super('An internal server error occurred.');
|
|
154
|
+
this.name = 'ServerError';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export class BadRequestError extends Error {
|
|
158
|
+
constructor(err) {
|
|
159
|
+
super('An unknown error occurred: ' + err);
|
|
160
|
+
this.name = 'UnknownError';
|
|
161
|
+
}
|
|
162
|
+
}
|
package/esm/internal/WsEvents.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export class WsEvents {
|
|
2
|
-
|
|
2
|
+
validate;
|
|
3
3
|
ws;
|
|
4
4
|
_isDestroyed = false;
|
|
5
5
|
listeners = {};
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
6
|
+
constructor(validate, ws) {
|
|
7
|
+
this.validate = validate;
|
|
8
8
|
this.ws = ws;
|
|
9
9
|
this.ws.onMessage = (e) => this.onMessage(e);
|
|
10
10
|
}
|
|
@@ -40,7 +40,7 @@ export class WsEvents {
|
|
|
40
40
|
}
|
|
41
41
|
try {
|
|
42
42
|
const eventData = JSON.parse(incomeData.toString());
|
|
43
|
-
const data = this.
|
|
43
|
+
const data = this.validate(eventData);
|
|
44
44
|
if (isInitEvent(data)) {
|
|
45
45
|
this.processMessage(data.data, true);
|
|
46
46
|
return;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { flashStorageTypeSchema, sdCardStorageTypeSchema, storageTypeSchema } from './common';
|
|
2
3
|
export const nodeStateSchema = z.object({
|
|
3
4
|
node_state: z.union([z.literal('OK'), z.literal('NOT_INSTALLED'), z.literal('NOT_FOUND')]),
|
|
4
5
|
});
|
|
5
6
|
export const packageInfoListSchema = z.array(z.object({
|
|
6
|
-
storage:
|
|
7
|
+
storage: storageTypeSchema,
|
|
7
8
|
manifest: z.object({
|
|
8
9
|
package_name: z.string(),
|
|
9
10
|
package_menu_name: z.string(),
|
|
@@ -17,10 +18,10 @@ export const packageInfoListSchema = z.array(z.object({
|
|
|
17
18
|
export const packageConfigSchema = z.record(z.string(), z.object({ enabled: z.boolean() }));
|
|
18
19
|
export const cameraStorageSchema = z.union([
|
|
19
20
|
z.tuple([
|
|
20
|
-
z.object({ type:
|
|
21
|
-
z.object({ type:
|
|
21
|
+
z.object({ type: flashStorageTypeSchema, capacity_mb: z.number() }),
|
|
22
|
+
z.object({ type: sdCardStorageTypeSchema, capacity_mb: z.number() }),
|
|
22
23
|
]),
|
|
23
|
-
z.tuple([z.object({ type:
|
|
24
|
+
z.tuple([z.object({ type: flashStorageTypeSchema, capacity_mb: z.number() })]),
|
|
24
25
|
]);
|
|
25
26
|
export const camscripterApiResponseSchema = z.object({
|
|
26
27
|
status: z.number(),
|
package/esm/types/common.js
CHANGED
|
@@ -2,7 +2,9 @@ import { z } from 'zod';
|
|
|
2
2
|
export const audioChannelSchema = z.union([z.literal('mono'), z.literal('stereo')]);
|
|
3
3
|
export const audioChannelCountSchema = z.union([z.literal(1), z.literal(2)]);
|
|
4
4
|
export const h264ProfileSchema = z.union([z.literal('high'), z.literal('main'), z.literal('baseline')]);
|
|
5
|
-
export const
|
|
5
|
+
export const flashStorageTypeSchema = z.literal('FLASH');
|
|
6
|
+
export const sdCardStorageTypeSchema = z.literal('SD_DISK');
|
|
7
|
+
export const storageTypeSchema = z.union([sdCardStorageTypeSchema, flashStorageTypeSchema]);
|
|
6
8
|
export const networkCameraListSchema = z.array(z.object({
|
|
7
9
|
name: z.string(),
|
|
8
10
|
ip: z.string(),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { trackingModeSchema, zonesSchema } from '../PlaneTrackerAPI';
|
|
2
3
|
const apiFlightDataSchema = z.object({
|
|
3
4
|
icao: z.string(),
|
|
4
5
|
lat: z.number(),
|
|
@@ -51,6 +52,81 @@ export var PlaneTrackerUserActions;
|
|
|
51
52
|
PlaneTrackerUserActions["LOCK_API"] = "lockApi.cgi";
|
|
52
53
|
PlaneTrackerUserActions["UNLOCK_API"] = "unlockApi.cgi";
|
|
53
54
|
})(PlaneTrackerUserActions || (PlaneTrackerUserActions = {}));
|
|
55
|
+
export const planeTrackerUserActionData = z.discriminatedUnion('cgi', [
|
|
56
|
+
z.object({
|
|
57
|
+
cgi: z.literal(PlaneTrackerUserActions.TRACK_ICAO),
|
|
58
|
+
ip: z.string(),
|
|
59
|
+
params: apiStringUserSchema.extend({
|
|
60
|
+
icao: z.string(),
|
|
61
|
+
}),
|
|
62
|
+
}),
|
|
63
|
+
z.object({
|
|
64
|
+
cgi: z.literal(PlaneTrackerUserActions.RESET_ICAO),
|
|
65
|
+
ip: z.string(),
|
|
66
|
+
params: apiStringUserSchema,
|
|
67
|
+
}),
|
|
68
|
+
z.object({
|
|
69
|
+
cgi: z.literal(PlaneTrackerUserActions.SET_PRIORITY_LIST),
|
|
70
|
+
ip: z.string(),
|
|
71
|
+
params: apiStringUserSchema,
|
|
72
|
+
postJsonBody: z.object({
|
|
73
|
+
priorityList: z.array(z.string()),
|
|
74
|
+
}),
|
|
75
|
+
}),
|
|
76
|
+
z.object({
|
|
77
|
+
cgi: z.literal(PlaneTrackerUserActions.SET_BLACK_LIST),
|
|
78
|
+
ip: z.string(),
|
|
79
|
+
params: apiStringUserSchema,
|
|
80
|
+
postJsonBody: z.object({
|
|
81
|
+
blackList: z.array(z.string()),
|
|
82
|
+
}),
|
|
83
|
+
}),
|
|
84
|
+
z.object({
|
|
85
|
+
cgi: z.literal(PlaneTrackerUserActions.SET_WHITE_LIST),
|
|
86
|
+
ip: z.string(),
|
|
87
|
+
params: apiStringUserSchema,
|
|
88
|
+
postJsonBody: z.object({
|
|
89
|
+
whiteList: z.array(z.string()),
|
|
90
|
+
}),
|
|
91
|
+
}),
|
|
92
|
+
z.object({
|
|
93
|
+
cgi: z.literal(PlaneTrackerUserActions.GO_TO_COORDINATES),
|
|
94
|
+
ip: z.string(),
|
|
95
|
+
params: apiStringUserSchema.extend({
|
|
96
|
+
lat: z.string(),
|
|
97
|
+
lon: z.string(),
|
|
98
|
+
}),
|
|
99
|
+
}),
|
|
100
|
+
z.object({
|
|
101
|
+
cgi: z.literal(PlaneTrackerUserActions.SET_TRACKING_MODE),
|
|
102
|
+
ip: z.string(),
|
|
103
|
+
params: apiStringUserSchema,
|
|
104
|
+
postJsonBody: trackingModeSchema,
|
|
105
|
+
}),
|
|
106
|
+
z.object({
|
|
107
|
+
cgi: z.literal(PlaneTrackerUserActions.SET_ZONES),
|
|
108
|
+
ip: z.string(),
|
|
109
|
+
params: apiStringUserSchema,
|
|
110
|
+
postJsonBody: zonesSchema,
|
|
111
|
+
}),
|
|
112
|
+
z.object({
|
|
113
|
+
cgi: z.literal(PlaneTrackerUserActions.RESET_PTZ_CALIBRATION),
|
|
114
|
+
ip: z.string(),
|
|
115
|
+
params: apiStringUserSchema,
|
|
116
|
+
}),
|
|
117
|
+
z.object({
|
|
118
|
+
cgi: z.literal(PlaneTrackerUserActions.LOCK_API),
|
|
119
|
+
ip: z.string(),
|
|
120
|
+
params: apiStringUserSchema.extend({
|
|
121
|
+
timeout: z.string(),
|
|
122
|
+
}),
|
|
123
|
+
}),
|
|
124
|
+
z.object({
|
|
125
|
+
cgi: z.literal(PlaneTrackerUserActions.UNLOCK_API),
|
|
126
|
+
ip: z.string(),
|
|
127
|
+
params: apiStringUserSchema,
|
|
128
|
+
}),
|
|
129
|
+
]);
|
|
54
130
|
const ptrEventsDataSchema = z.discriminatedUnion('type', [
|
|
55
131
|
z.object({
|
|
56
132
|
type: z.literal('CAMERA_POSITION'),
|
|
@@ -3,7 +3,7 @@ import { coEventsSchema } from '../types/ws/CamOverlayEvents';
|
|
|
3
3
|
export class CamOverlayEvents extends WsEvents {
|
|
4
4
|
getAuthToken;
|
|
5
5
|
constructor(ws, getAuthToken) {
|
|
6
|
-
super(coEventsSchema, ws);
|
|
6
|
+
super((data) => coEventsSchema.parse(data), ws);
|
|
7
7
|
this.getAuthToken = getAuthToken;
|
|
8
8
|
this.ws.onOpen = this.sendInitMsg;
|
|
9
9
|
}
|
|
@@ -3,7 +3,7 @@ import { csEventsSchema } from '../types/ws/CamStreamerEvents';
|
|
|
3
3
|
export class CamStreamerEvents extends WsEvents {
|
|
4
4
|
getAuthToken;
|
|
5
5
|
constructor(ws, getAuthToken) {
|
|
6
|
-
super(csEventsSchema, ws);
|
|
6
|
+
super((data) => csEventsSchema.parse(data), ws);
|
|
7
7
|
this.getAuthToken = getAuthToken;
|
|
8
8
|
this.ws.onOpen = this.sendInitMsg;
|
|
9
9
|
}
|
|
@@ -3,7 +3,7 @@ import { cswEventsSchema } from '../types/ws/CamSwitcherEvents';
|
|
|
3
3
|
export class CamSwitcherEvents extends WsEvents {
|
|
4
4
|
getAuthToken;
|
|
5
5
|
constructor(ws, getAuthToken) {
|
|
6
|
-
super(cswEventsSchema, ws);
|
|
6
|
+
super((data) => cswEventsSchema.parse(data), ws);
|
|
7
7
|
this.getAuthToken = getAuthToken;
|
|
8
8
|
this.ws.onOpen = this.sendInitMsg;
|
|
9
9
|
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { WsEvents } from '../internal/WsEvents';
|
|
2
|
-
import { ptrEventsSchema } from '../types/ws/PlaneTrackerEvents';
|
|
2
|
+
import { PlaneTrackerWsEvents, planeTrackerUserActionData, ptrEventsSchema, } from '../types/ws/PlaneTrackerEvents';
|
|
3
3
|
export class PlaneTrackerEvents extends WsEvents {
|
|
4
4
|
_apiUser;
|
|
5
5
|
constructor(ws, _apiUser) {
|
|
6
|
-
super(
|
|
6
|
+
super((data) => {
|
|
7
|
+
const parsedData = ptrEventsSchema.parse(data);
|
|
8
|
+
if (parsedData.type === PlaneTrackerWsEvents.USER_ACTION) {
|
|
9
|
+
const { type, ...actionData } = parsedData;
|
|
10
|
+
const userAction = planeTrackerUserActionData.parse(actionData);
|
|
11
|
+
return { ...userAction, type };
|
|
12
|
+
}
|
|
13
|
+
return parsedData;
|
|
14
|
+
}, ws);
|
|
7
15
|
this._apiUser = _apiUser;
|
|
8
16
|
this.ws.onOpen = this.sendInitMsg;
|
|
9
17
|
}
|
package/package.json
CHANGED
|
@@ -12,17 +12,17 @@ export declare class CamScripterAPI<Client extends IClient<TResponse, any>> {
|
|
|
12
12
|
ip: string;
|
|
13
13
|
}[]>;
|
|
14
14
|
getStorageInfo(options?: THttpRequestOptions): Promise<[{
|
|
15
|
-
type: "
|
|
15
|
+
type: "FLASH";
|
|
16
16
|
capacity_mb: number;
|
|
17
17
|
}, {
|
|
18
|
-
type: "
|
|
18
|
+
type: "SD_DISK";
|
|
19
19
|
capacity_mb: number;
|
|
20
20
|
}] | [{
|
|
21
|
-
type: "
|
|
21
|
+
type: "FLASH";
|
|
22
22
|
capacity_mb: number;
|
|
23
23
|
}]>;
|
|
24
24
|
getPackageList(options?: THttpRequestOptions): Promise<{
|
|
25
|
-
storage: "
|
|
25
|
+
storage: "FLASH" | "SD_DISK";
|
|
26
26
|
manifest: {
|
|
27
27
|
package_name: string;
|
|
28
28
|
package_menu_name: string;
|