camstreamerlib 4.0.0-beta.37 → 4.0.0-beta.38
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/CamOverlayAPI.js +42 -69
- package/cjs/CamScripterAPI.js +30 -24
- package/cjs/CamStreamerAPI.js +30 -33
- package/cjs/CamSwitcherAPI.js +57 -52
- package/cjs/PlaneTrackerAPI.js +55 -66
- package/cjs/VapixAPI.js +23 -22
- package/cjs/{CamOverlayDrawingAPI.js → node/CamOverlayDrawingAPI.js} +1 -1
- package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/Painter.js +4 -14
- package/cjs/{CamScripterAPICameraEventsGenerator.js → node/CamScripterAPICameraEventsGenerator.js} +1 -1
- package/cjs/{VapixEvents.js → node/VapixEvents.js} +1 -1
- package/cjs/node/events/GenetecAgent.js +5 -27
- package/cjs/node/index.js +17 -0
- package/cjs/types/CamOverlayAPI/CamOverlayAPI.js +2 -2
- package/cjs/types/CamOverlayPainter.js +12 -0
- package/cjs/types/CamScripterAPICameraEventsGenerator.js +2 -0
- package/cjs/types/CamSwitcherAPI.js +38 -1
- package/cjs/types/GenetecAgent.js +31 -0
- package/cjs/types/PlaneTrackerAPI.js +277 -0
- package/cjs/types/VapixAPI.js +20 -2
- package/cjs/types/VapixEvents.js +2 -0
- package/esm/CamOverlayAPI.js +43 -70
- package/esm/CamScripterAPI.js +30 -24
- package/esm/CamStreamerAPI.js +30 -30
- package/esm/CamSwitcherAPI.js +58 -53
- package/esm/PlaneTrackerAPI.js +56 -67
- package/esm/VapixAPI.js +24 -23
- package/esm/{CamOverlayDrawingAPI.js → node/CamOverlayDrawingAPI.js} +1 -1
- package/esm/{CamOverlayPainter → node/CamOverlayPainter}/Painter.js +1 -11
- package/esm/{CamScripterAPICameraEventsGenerator.js → node/CamScripterAPICameraEventsGenerator.js} +1 -1
- package/esm/{VapixEvents.js → node/VapixEvents.js} +1 -1
- package/esm/node/events/GenetecAgent.js +1 -23
- package/esm/node/index.js +10 -0
- package/esm/types/CamOverlayAPI/CamOverlayAPI.js +1 -1
- package/esm/types/CamOverlayPainter.js +11 -1
- package/esm/types/CamSwitcherAPI.js +38 -1
- package/esm/types/GenetecAgent.js +28 -0
- package/esm/types/PlaneTrackerAPI.js +276 -1
- package/esm/types/VapixAPI.js +19 -1
- package/esm/types/VapixEvents.js +1 -0
- package/package.json +1 -1
- package/types/CamOverlayAPI.d.ts +16 -6
- package/types/CamScripterAPI.d.ts +34 -9
- package/types/CamStreamerAPI.d.ts +27 -5
- package/types/CamSwitcherAPI.d.ts +136 -23
- package/types/PlaneTrackerAPI.d.ts +201 -20
- package/types/VapixAPI.d.ts +46 -12
- package/types/bin/CreatePackage.d.ts +1 -0
- package/types/{CamOverlayDrawingAPI.d.ts → node/CamOverlayDrawingAPI.d.ts} +1 -1
- package/types/{CamOverlayPainter → node/CamOverlayPainter}/Frame.d.ts +2 -2
- package/types/{CamOverlayPainter → node/CamOverlayPainter}/Painter.d.ts +2 -13
- package/types/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.d.ts +1 -1
- package/types/node/CamScripterAPICameraEventsGenerator.d.ts +31 -0
- package/types/node/VapixEvents.d.ts +16 -0
- package/types/node/events/GenetecAgent.d.ts +1 -144
- package/types/node/index.d.ts +10 -0
- package/types/types/CamOverlayAPI/CamOverlayAPI.d.ts +2 -2
- package/types/types/CamOverlayDrawingAPI.d.ts +3 -13
- package/types/types/CamOverlayPainter.d.ts +12 -10
- package/types/types/CamScripterAPICameraEventsGenerator.d.ts +45 -0
- package/types/types/CamStreamerAPI.d.ts +2 -2
- package/types/types/CamSwitcherAPI.d.ts +111 -30
- package/types/types/GenetecAgent.d.ts +174 -0
- package/types/types/PlaneTrackerAPI.d.ts +859 -0
- package/types/types/VapixAPI.d.ts +54 -8
- package/types/types/VapixEvents.d.ts +15 -0
- package/types/types/common.d.ts +1 -0
- package/types/CamScripterAPICameraEventsGenerator.d.ts +0 -74
- package/types/VapixEvents.d.ts +0 -43
- /package/cjs/{CreatePackage.js → bin/CreatePackage.js} +0 -0
- /package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/Frame.js +0 -0
- /package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.js +0 -0
- /package/esm/{CreatePackage.js → bin/CreatePackage.js} +0 -0
- /package/esm/{CamOverlayPainter → node/CamOverlayPainter}/Frame.js +0 -0
- /package/esm/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.js +0 -0
- /package/{types/CreatePackage.d.ts → esm/types/CamScripterAPICameraEventsGenerator.js} +0 -0
package/esm/CamStreamerAPI.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import z from 'zod';
|
|
1
|
+
import { z } from 'zod';
|
|
2
2
|
import { ProxyClient } from './internal/ProxyClient';
|
|
3
3
|
import { responseStringify } from './internal/utils';
|
|
4
4
|
import { cameraStreamSchema } from './types/CamStreamerAPI';
|
|
@@ -11,28 +11,42 @@ export class CamStreamerAPI {
|
|
|
11
11
|
getClient(proxyParams) {
|
|
12
12
|
return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
|
|
13
13
|
}
|
|
14
|
+
async wsAuthorization(options) {
|
|
15
|
+
const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
|
|
16
|
+
if (res.status !== 200) {
|
|
17
|
+
throw new Error(`Server error on ws authorization: ${res.message}`);
|
|
18
|
+
}
|
|
19
|
+
return z.string().parse(res.data);
|
|
20
|
+
}
|
|
21
|
+
async getUtcTime(options) {
|
|
22
|
+
const res = await this._getJson(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
|
|
23
|
+
if (res.status !== 200) {
|
|
24
|
+
throw new Error(`Server error on get UTC time: ${res.message}`);
|
|
25
|
+
}
|
|
26
|
+
return z.number().parse(res.data);
|
|
27
|
+
}
|
|
14
28
|
async getStreamList(options) {
|
|
15
|
-
const
|
|
16
|
-
const list = z.record(z.string(), cameraStreamSchema).parse(
|
|
17
|
-
const
|
|
29
|
+
const res = await this._getJson(`${BASE_PATH}/stream/list.cgi`, undefined, options);
|
|
30
|
+
const list = z.record(z.string(), cameraStreamSchema).parse(res.data);
|
|
31
|
+
const streamList = {};
|
|
18
32
|
for (const [key, data] of Object.entries(list)) {
|
|
19
33
|
const streamId = parseInt(key);
|
|
20
|
-
|
|
34
|
+
streamList[streamId] = parseCameraStreamResponse(data);
|
|
21
35
|
}
|
|
22
|
-
return
|
|
36
|
+
return streamList;
|
|
23
37
|
}
|
|
24
38
|
async getStream(streamId, options) {
|
|
25
|
-
const
|
|
26
|
-
const cameraData = cameraStreamSchema.parse(
|
|
39
|
+
const res = await this._getJson(`${BASE_PATH}/stream/get.cgi`, { stream_id: streamId }, options);
|
|
40
|
+
const cameraData = cameraStreamSchema.parse(res.data);
|
|
27
41
|
return parseCameraStreamResponse(cameraData);
|
|
28
42
|
}
|
|
29
43
|
async getStreamParameter(streamId, paramName, options) {
|
|
30
|
-
const
|
|
31
|
-
return
|
|
44
|
+
const res = await this._getJson(`${BASE_PATH}/stream/get.cgi`, { stream_id: streamId }, options);
|
|
45
|
+
return z.string().parse(res.data[paramName]);
|
|
32
46
|
}
|
|
33
47
|
async setStream(streamId, params, options) {
|
|
34
48
|
const { streamDelay, startTime, stopTime, ...rest } = params;
|
|
35
|
-
return await this.
|
|
49
|
+
return await this._getJson(`${BASE_PATH}/stream/set.cgi`, {
|
|
36
50
|
stream_id: streamId,
|
|
37
51
|
streamDelay: streamDelay ?? '',
|
|
38
52
|
startTime: startTime ?? null,
|
|
@@ -41,31 +55,17 @@ export class CamStreamerAPI {
|
|
|
41
55
|
}, options);
|
|
42
56
|
}
|
|
43
57
|
async setStreamParameter(streamId, paramName, value, options) {
|
|
44
|
-
return await this.
|
|
58
|
+
return await this._getJson(`${BASE_PATH}/stream/set.cgi`, { stream_id: streamId, [paramName]: value }, options);
|
|
45
59
|
}
|
|
46
60
|
async isStreaming(streamId, options) {
|
|
47
|
-
const
|
|
48
|
-
return
|
|
61
|
+
const res = await this._getJson(`${BASE_PATH}/get_streamstat.cgi`, { stream_id: streamId }, options);
|
|
62
|
+
return res.data.is_streaming === 1;
|
|
49
63
|
}
|
|
50
64
|
async deleteStream(streamId, options) {
|
|
51
|
-
const res = await this.
|
|
65
|
+
const res = await this._getJson(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
|
|
52
66
|
return res.data.status === 200;
|
|
53
67
|
}
|
|
54
|
-
async
|
|
55
|
-
const res = await this.get(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
|
|
56
|
-
if (res.status !== 200) {
|
|
57
|
-
throw new Error(`Server error on ws authorization: ${res.message}`);
|
|
58
|
-
}
|
|
59
|
-
return res.data;
|
|
60
|
-
}
|
|
61
|
-
async getUtcTime(options) {
|
|
62
|
-
const res = await this.get(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
|
|
63
|
-
if (res.status !== 200) {
|
|
64
|
-
throw new Error(`Server error on get UTC time: ${res.message}`);
|
|
65
|
-
}
|
|
66
|
-
return res.data;
|
|
67
|
-
}
|
|
68
|
-
async get(path, parameters, options) {
|
|
68
|
+
async _getJson(path, parameters, options) {
|
|
69
69
|
const agent = this.getClient(options?.proxyParams);
|
|
70
70
|
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
71
71
|
if (res.ok) {
|
package/esm/CamSwitcherAPI.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { AddNewClipError } from './errors/errors';
|
|
3
3
|
import { isClip, isNullish, responseStringify } from './internal/utils';
|
|
4
|
-
import { storageInfoListSchema, outputInfoSchema, audioPushInfoSchema, clipListSchema, playlistQueueSchema, streamSaveLoadSchema, clipSaveLoadSchema, playlistSaveLoadSchema, trackerSaveLoadSchema, } from './types/CamSwitcherAPI';
|
|
4
|
+
import { storageInfoListSchema, outputInfoSchema, audioPushInfoSchema, clipListSchema, playlistQueueSchema, streamSaveLoadSchema, clipSaveLoadSchema, playlistSaveLoadSchema, trackerSaveLoadSchema, secondaryAudioSettingsSchema, globalAudioSettingsSchema, } from './types/CamSwitcherAPI';
|
|
5
5
|
import { networkCameraListSchema, } from './types/common';
|
|
6
6
|
import { VapixAPI } from './VapixAPI';
|
|
7
7
|
import { isFirmwareVersionAtLeast } from './internal/versionCompare';
|
|
@@ -17,9 +17,9 @@ export class CamSwitcherAPI {
|
|
|
17
17
|
this.CustomFormData = CustomFormData;
|
|
18
18
|
this.vapixAgent = new VapixAPI(client);
|
|
19
19
|
}
|
|
20
|
-
static
|
|
21
|
-
static
|
|
22
|
-
static
|
|
20
|
+
static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
|
|
21
|
+
static getWsEventsPath = () => `/local/camswitcher/events`;
|
|
22
|
+
static getClipPreviewPath = (id, storage) => `${BASE_PATH}/clip_preview.cgi?clip_name=${id}&storage=${storage}`;
|
|
23
23
|
getClient(proxyParams) {
|
|
24
24
|
return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
|
|
25
25
|
}
|
|
@@ -35,98 +35,105 @@ export class CamSwitcherAPI {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
async checkCameraTime(options) {
|
|
38
|
-
const
|
|
39
|
-
return z.boolean().parse(data);
|
|
38
|
+
const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
|
|
39
|
+
return z.boolean().parse(res.data);
|
|
40
40
|
}
|
|
41
41
|
async getNetworkCameraList(options) {
|
|
42
|
-
const
|
|
43
|
-
return networkCameraListSchema.parse(data);
|
|
42
|
+
const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
|
|
43
|
+
return networkCameraListSchema.parse(res.data);
|
|
44
44
|
}
|
|
45
45
|
async getMaxFps(source, options) {
|
|
46
|
-
const
|
|
47
|
-
video_source: source
|
|
46
|
+
const res = await this._getJson(`${BASE_PATH}/get_max_framerate.cgi`, {
|
|
47
|
+
video_source: source,
|
|
48
48
|
}, options);
|
|
49
|
-
return z.number().parse(data);
|
|
49
|
+
return z.number().parse(res.data);
|
|
50
50
|
}
|
|
51
51
|
async getStorageInfo(options) {
|
|
52
|
-
const
|
|
53
|
-
return storageInfoListSchema.parse(data);
|
|
52
|
+
const res = await this._getJson(`${BASE_PATH}/get_storage.cgi`, undefined, options);
|
|
53
|
+
return storageInfoListSchema.parse(res.data);
|
|
54
54
|
}
|
|
55
55
|
async wsAuthorization(options) {
|
|
56
|
-
const
|
|
57
|
-
return z.string().parse(data);
|
|
56
|
+
const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
|
|
57
|
+
return z.string().parse(res.data);
|
|
58
58
|
}
|
|
59
59
|
async getOutputInfo(options) {
|
|
60
|
-
const
|
|
61
|
-
return outputInfoSchema.parse(data);
|
|
60
|
+
const res = await this._getJson(`${BASE_PATH}/output_info.cgi`, undefined, options);
|
|
61
|
+
return outputInfoSchema.parse(res.data);
|
|
62
62
|
}
|
|
63
63
|
async getAudioPushInfo(options) {
|
|
64
|
-
const
|
|
65
|
-
return audioPushInfoSchema.parse(data);
|
|
64
|
+
const res = await this._getJson(`${BASE_PATH}/audio_push_info.cgi`, undefined, options);
|
|
65
|
+
return audioPushInfoSchema.parse(res.data);
|
|
66
66
|
}
|
|
67
67
|
async getStreamSaveList(options) {
|
|
68
|
-
const
|
|
69
|
-
return streamSaveLoadSchema.parse(data);
|
|
68
|
+
const res = await this._getJson(`${BASE_PATH}/streams.cgi`, { action: 'get' }, options);
|
|
69
|
+
return streamSaveLoadSchema.parse(res.data);
|
|
70
70
|
}
|
|
71
71
|
async getClipSaveList(options) {
|
|
72
|
-
const
|
|
73
|
-
return clipSaveLoadSchema.parse(data);
|
|
72
|
+
const res = await this._getJson(`${BASE_PATH}/clips.cgi`, { action: 'get' }, options);
|
|
73
|
+
return clipSaveLoadSchema.parse(res.data);
|
|
74
74
|
}
|
|
75
75
|
async getPlaylistSaveList(options) {
|
|
76
|
-
const
|
|
77
|
-
return playlistSaveLoadSchema.parse(data);
|
|
76
|
+
const res = await this._getJson(`${BASE_PATH}/playlists.cgi`, { action: 'get' }, options);
|
|
77
|
+
return playlistSaveLoadSchema.parse(res.data);
|
|
78
78
|
}
|
|
79
79
|
async getTrackerSaveList(options) {
|
|
80
|
-
const
|
|
81
|
-
return trackerSaveLoadSchema.parse(data);
|
|
80
|
+
const res = await this._getJson(`${BASE_PATH}/trackers.cgi`, { action: 'get' }, options);
|
|
81
|
+
return trackerSaveLoadSchema.parse(res.data);
|
|
82
82
|
}
|
|
83
83
|
async setStreamSaveList(data, options) {
|
|
84
|
-
return await this.
|
|
84
|
+
return await this._post(`${BASE_PATH}/streams.cgi`, data, { action: 'set' }, options);
|
|
85
85
|
}
|
|
86
86
|
async setClipSaveList(data, options) {
|
|
87
|
-
return await this.
|
|
87
|
+
return await this._post(`${BASE_PATH}/clips.cgi`, data, { action: 'set' }, options);
|
|
88
88
|
}
|
|
89
89
|
async setPlaylistSaveList(data, options) {
|
|
90
|
-
return await this.
|
|
90
|
+
return await this._post(`${BASE_PATH}/playlists.cgi`, data, { action: 'set' }, options);
|
|
91
91
|
}
|
|
92
92
|
async setTrackerSaveList(data, options) {
|
|
93
|
-
return await this.
|
|
93
|
+
return await this._post(`${BASE_PATH}/trackers.cgi`, data, { action: 'set' }, options);
|
|
94
94
|
}
|
|
95
95
|
async playlistSwitch(playlistName, options) {
|
|
96
|
-
await this.
|
|
96
|
+
await this._getJson(`${BASE_PATH}/playlist_switch.cgi`, { playlist_name: playlistName }, options);
|
|
97
97
|
}
|
|
98
98
|
async playlistQueuePush(playlistName, options) {
|
|
99
|
-
await this.
|
|
99
|
+
await this._getJson(`${BASE_PATH}/playlist_queue_push.cgi`, { playlist_name: playlistName }, options);
|
|
100
100
|
}
|
|
101
101
|
async playlistQueueClear(options) {
|
|
102
|
-
await this.
|
|
102
|
+
await this._getJson(`${BASE_PATH}/playlist_queue_clear.cgi`, undefined, options);
|
|
103
103
|
}
|
|
104
104
|
async playlistQueueList(options) {
|
|
105
|
-
const
|
|
106
|
-
return playlistQueueSchema.parse(data).playlistQueueList;
|
|
105
|
+
const res = await this._getJson(`${BASE_PATH}/playlist_queue_list.cgi`, undefined, options);
|
|
106
|
+
return playlistQueueSchema.parse(res.data).playlistQueueList;
|
|
107
107
|
}
|
|
108
108
|
async playlistQueuePlayNext(options) {
|
|
109
|
-
await this.
|
|
109
|
+
await this._getJson(`${BASE_PATH}/playlist_queue_play_next.cgi`, undefined, options);
|
|
110
110
|
}
|
|
111
111
|
async addNewClip(file, clipType, storage, clipId, fileName, options) {
|
|
112
|
-
const path = `${BASE_PATH}/clip_upload.cgi
|
|
112
|
+
const path = `${BASE_PATH}/clip_upload.cgi`;
|
|
113
113
|
const formData = new this.CustomFormData();
|
|
114
114
|
formData.append('clip_name', clipId);
|
|
115
115
|
formData.append('clip_type', clipType);
|
|
116
116
|
formData.append('file', file, fileName);
|
|
117
117
|
const agent = this.getClient(options?.proxyParams);
|
|
118
|
-
const res = await agent.post({
|
|
118
|
+
const res = await agent.post({
|
|
119
|
+
path,
|
|
120
|
+
data: formData,
|
|
121
|
+
parameters: {
|
|
122
|
+
storage: storage,
|
|
123
|
+
},
|
|
124
|
+
timeout: options?.timeout,
|
|
125
|
+
});
|
|
119
126
|
const output = (await res.json());
|
|
120
127
|
if (output.status !== 200) {
|
|
121
128
|
throw new AddNewClipError(output.message);
|
|
122
129
|
}
|
|
123
130
|
}
|
|
124
131
|
removeClip(clipId, storage, options) {
|
|
125
|
-
return this.
|
|
132
|
+
return this._getJson(`${BASE_PATH}/clip_remove.cgi`, { clip_name: clipId, storage }, options);
|
|
126
133
|
}
|
|
127
134
|
async getClipList(options) {
|
|
128
|
-
const
|
|
129
|
-
return clipListSchema.parse(data).clip_list;
|
|
135
|
+
const res = await this._getJson(`${BASE_PATH}/clip_list.cgi`, undefined, options);
|
|
136
|
+
return clipListSchema.parse(res.data).clip_list;
|
|
130
137
|
}
|
|
131
138
|
setCamSwitchOptions(data, cameraFWVersion, options) {
|
|
132
139
|
const bitrateVapixParams = parseBitrateOptionsToBitrateVapixParams(cameraFWVersion, data.bitrateMode, data);
|
|
@@ -227,7 +234,7 @@ export class CamSwitcherAPI {
|
|
|
227
234
|
settings.source = res.clip_name;
|
|
228
235
|
settings.storage = res.storage;
|
|
229
236
|
}
|
|
230
|
-
return settings;
|
|
237
|
+
return globalAudioSettingsSchema.parse(settings);
|
|
231
238
|
}
|
|
232
239
|
async getSecondaryAudioSettings(options) {
|
|
233
240
|
const res = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SECONDARY_AUDIO, options);
|
|
@@ -239,30 +246,28 @@ export class CamSwitcherAPI {
|
|
|
239
246
|
secondaryAudioLevel: res.secondary_audio_level ?? 1,
|
|
240
247
|
masterAudioLevel: res.master_audio_level ?? 1,
|
|
241
248
|
};
|
|
242
|
-
return settings;
|
|
249
|
+
return secondaryAudioSettingsSchema.parse(settings);
|
|
243
250
|
}
|
|
244
251
|
async getPermanentRtspUrlToken(options) {
|
|
245
252
|
const paramName = CSW_PARAM_NAMES.RTSP_TOKEN;
|
|
246
253
|
const res = await this.vapixAgent.getParameter([paramName], options);
|
|
247
|
-
return res[paramName] ?? '';
|
|
254
|
+
return z.string().parse(res[paramName] ?? '');
|
|
248
255
|
}
|
|
249
|
-
async
|
|
256
|
+
async _getJson(path, parameters, options) {
|
|
250
257
|
const agent = this.getClient(options?.proxyParams);
|
|
251
258
|
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
252
259
|
if (res.ok) {
|
|
253
|
-
|
|
254
|
-
return d.data;
|
|
260
|
+
return await res.json();
|
|
255
261
|
}
|
|
256
262
|
else {
|
|
257
263
|
throw new Error(await responseStringify(res));
|
|
258
264
|
}
|
|
259
265
|
}
|
|
260
|
-
async
|
|
266
|
+
async _post(path, data, parameters, options, headers) {
|
|
261
267
|
const agent = this.getClient(options?.proxyParams);
|
|
262
|
-
const res = await agent.post({ path, data
|
|
268
|
+
const res = await agent.post({ path, data, parameters, timeout: options?.timeout, headers });
|
|
263
269
|
if (res.ok) {
|
|
264
|
-
|
|
265
|
-
return parsed.message === 'OK';
|
|
270
|
+
return await res.json();
|
|
266
271
|
}
|
|
267
272
|
else {
|
|
268
273
|
throw new Error(await responseStringify(res));
|
|
@@ -302,7 +307,7 @@ const parseBitrateOptionsToBitrateVapixParams = (firmWareVersion, bitrateMode, c
|
|
|
302
307
|
if (!isFirmwareVersionAtLeast(firmWareVersion, FIRMWARE_WITH_BITRATE_MODES_SUPPORT)) {
|
|
303
308
|
return `videomaxbitrate=${cameraOptions.maximumBitRate}`;
|
|
304
309
|
}
|
|
305
|
-
if (bitrateMode ===
|
|
310
|
+
if (bitrateMode === undefined) {
|
|
306
311
|
return '';
|
|
307
312
|
}
|
|
308
313
|
const data = {
|
package/esm/PlaneTrackerAPI.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { responseStringify } from './internal/utils';
|
|
3
|
+
import { blackListSchema, cameraSettingsSchema, flightInfoSchema, mapInfoSchema, priorityListSchema, serverSettingsSchema, trackingModeSchema, whiteListSchema, zonesSchema, } from './types/PlaneTrackerAPI';
|
|
3
4
|
import { ParsingBlobError } from './errors/errors';
|
|
4
5
|
import { ProxyClient } from './internal/ProxyClient';
|
|
6
|
+
import { cameraListSchema } from './types/GenetecAgent';
|
|
5
7
|
const BASE_PATH = '/local/planetracker';
|
|
6
8
|
export class PlaneTrackerAPI {
|
|
7
9
|
client;
|
|
@@ -10,13 +12,13 @@ export class PlaneTrackerAPI {
|
|
|
10
12
|
this.client = client;
|
|
11
13
|
this.apiUser = apiUser;
|
|
12
14
|
}
|
|
13
|
-
static
|
|
15
|
+
static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
|
|
14
16
|
getClient(proxyParams) {
|
|
15
17
|
return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
|
|
16
18
|
}
|
|
17
19
|
async checkCameraTime(options) {
|
|
18
|
-
const
|
|
19
|
-
return z.boolean().parse(
|
|
20
|
+
const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
|
|
21
|
+
return z.boolean().parse(res.state);
|
|
20
22
|
}
|
|
21
23
|
async resetPtzCalibration(options) {
|
|
22
24
|
const agent = this.getClient(options?.proxyParams);
|
|
@@ -47,7 +49,8 @@ export class PlaneTrackerAPI {
|
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
async fetchCameraSettings(options) {
|
|
50
|
-
|
|
52
|
+
const res = await this._getJson(`${BASE_PATH}/package_camera_settings.cgi`, { action: 'get' }, options);
|
|
53
|
+
return cameraSettingsSchema.parse(res);
|
|
51
54
|
}
|
|
52
55
|
async setCameraSettings(settingsJsonString, options) {
|
|
53
56
|
return await this._postJsonEncoded(`${BASE_PATH}/package_camera_settings.cgi`, settingsJsonString, {
|
|
@@ -55,7 +58,8 @@ export class PlaneTrackerAPI {
|
|
|
55
58
|
}, options);
|
|
56
59
|
}
|
|
57
60
|
async fetchServerSettings(options) {
|
|
58
|
-
|
|
61
|
+
const res = await this._getJson(`${BASE_PATH}/package_server_settings.cgi`, { action: 'get' }, options);
|
|
62
|
+
return serverSettingsSchema.parse(res);
|
|
59
63
|
}
|
|
60
64
|
async exportAppSettings(dataType, options) {
|
|
61
65
|
return await this._getBlob(`${BASE_PATH}/package_data.cgi`, { action: 'EXPORT', dataType }, options);
|
|
@@ -70,13 +74,15 @@ export class PlaneTrackerAPI {
|
|
|
70
74
|
});
|
|
71
75
|
}
|
|
72
76
|
async fetchFlightInfo(icao, options) {
|
|
73
|
-
|
|
77
|
+
const res = await this._getJson(`${BASE_PATH}/package/flightInfo.cgi`, { icao }, options);
|
|
78
|
+
return flightInfoSchema.parse(res);
|
|
74
79
|
}
|
|
75
80
|
async getTrackingMode(options) {
|
|
76
|
-
|
|
81
|
+
const res = await this._getJson(`${BASE_PATH}/package/getTrackingMode.cgi`, undefined, options);
|
|
82
|
+
return trackingModeSchema.parse(res);
|
|
77
83
|
}
|
|
78
|
-
async setTrackingMode(
|
|
79
|
-
return await this._postJsonEncoded(`${BASE_PATH}/package/setTrackingMode.cgi`,
|
|
84
|
+
async setTrackingMode(mode, options) {
|
|
85
|
+
return await this._postJsonEncoded(`${BASE_PATH}/package/setTrackingMode.cgi`, { mode }, this.apiUser, options);
|
|
80
86
|
}
|
|
81
87
|
async startTrackingPlane(icao, options) {
|
|
82
88
|
const agent = this.getClient(options?.proxyParams);
|
|
@@ -95,31 +101,36 @@ export class PlaneTrackerAPI {
|
|
|
95
101
|
});
|
|
96
102
|
}
|
|
97
103
|
async getPriorityList(options) {
|
|
98
|
-
|
|
104
|
+
const res = await this._getJson(`${BASE_PATH}/package/getPriorityList.cgi`, undefined, options);
|
|
105
|
+
return priorityListSchema.parse(res);
|
|
99
106
|
}
|
|
100
|
-
async setPriorityList(
|
|
101
|
-
return await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`,
|
|
107
|
+
async setPriorityList(priorityList, options) {
|
|
108
|
+
return await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`, { priorityList }, this.apiUser, options);
|
|
102
109
|
}
|
|
103
110
|
async getWhiteList(options) {
|
|
104
|
-
|
|
111
|
+
const res = await this._getJson(`${BASE_PATH}/package/getWhiteList.cgi`, undefined, options);
|
|
112
|
+
return whiteListSchema.parse(res);
|
|
105
113
|
}
|
|
106
|
-
async setWhiteList(
|
|
107
|
-
return await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`,
|
|
114
|
+
async setWhiteList(whiteList, options) {
|
|
115
|
+
return await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`, { whiteList }, this.apiUser, options);
|
|
108
116
|
}
|
|
109
117
|
async getBlackList(options) {
|
|
110
|
-
|
|
118
|
+
const res = await this._getJson(`${BASE_PATH}/package/getBlackList.cgi`, undefined, options);
|
|
119
|
+
return blackListSchema.parse(res);
|
|
111
120
|
}
|
|
112
|
-
async setBlackList(
|
|
113
|
-
return await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`,
|
|
121
|
+
async setBlackList(blackList, options) {
|
|
122
|
+
return await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`, { blackList }, this.apiUser, options);
|
|
114
123
|
}
|
|
115
124
|
async fetchMapInfo(options) {
|
|
116
|
-
|
|
125
|
+
const res = await this._getJson(`${BASE_PATH}/package/getMapInfo.cgi`, undefined, options);
|
|
126
|
+
return mapInfoSchema.parse(res);
|
|
117
127
|
}
|
|
118
128
|
async getZones(options) {
|
|
119
|
-
|
|
129
|
+
const res = await this._getJson(`${BASE_PATH}/package/getZones.cgi`, undefined, options);
|
|
130
|
+
return zonesSchema.parse(res);
|
|
120
131
|
}
|
|
121
|
-
async setZones(
|
|
122
|
-
return await this._postJsonEncoded(`${BASE_PATH}/package/setZones.cgi`,
|
|
132
|
+
async setZones(zones, options) {
|
|
133
|
+
return await this._postJsonEncoded(`${BASE_PATH}/package/setZones.cgi`, { zones }, this.apiUser, options);
|
|
123
134
|
}
|
|
124
135
|
async goToCoordinates(lat, lon, alt, options) {
|
|
125
136
|
const agent = this.getClient(options?.proxyParams);
|
|
@@ -130,19 +141,25 @@ export class PlaneTrackerAPI {
|
|
|
130
141
|
});
|
|
131
142
|
}
|
|
132
143
|
async checkGenetecConnection(params, options) {
|
|
133
|
-
return await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
|
|
144
|
+
return await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, '', params, options);
|
|
134
145
|
}
|
|
135
146
|
async getGenetecCameraList(params, options) {
|
|
136
|
-
const res = await this._postUrlEncoded(`${BASE_PATH}/package/getGenetecCameraList.cgi`, params, options);
|
|
137
|
-
return
|
|
147
|
+
const res = await this._postUrlEncoded(`${BASE_PATH}/package/getGenetecCameraList.cgi`, '', params, options);
|
|
148
|
+
return cameraListSchema.parse(res);
|
|
138
149
|
}
|
|
139
|
-
async _getJson(path, parameters, options) {
|
|
150
|
+
async _getJson(path, parameters, options, headers) {
|
|
140
151
|
const agent = this.getClient(options?.proxyParams);
|
|
141
|
-
const res = await agent.get({
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
152
|
+
const res = await agent.get({ path, parameters, timeout: options?.timeout, headers });
|
|
153
|
+
if (res.ok) {
|
|
154
|
+
return await res.json();
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
throw new Error(await responseStringify(res));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async _post(path, data, parameters, options, headers) {
|
|
161
|
+
const agent = this.getClient(options?.proxyParams);
|
|
162
|
+
const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
|
|
146
163
|
if (res.ok) {
|
|
147
164
|
return await res.json();
|
|
148
165
|
}
|
|
@@ -152,11 +169,7 @@ export class PlaneTrackerAPI {
|
|
|
152
169
|
}
|
|
153
170
|
async _getBlob(path, parameters, options) {
|
|
154
171
|
const agent = this.getClient(options?.proxyParams);
|
|
155
|
-
const res = await agent.get({
|
|
156
|
-
path,
|
|
157
|
-
parameters,
|
|
158
|
-
timeout: options?.timeout,
|
|
159
|
-
});
|
|
172
|
+
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
160
173
|
if (res.ok) {
|
|
161
174
|
return await this.parseBlobResponse(res);
|
|
162
175
|
}
|
|
@@ -172,36 +185,12 @@ export class PlaneTrackerAPI {
|
|
|
172
185
|
throw new ParsingBlobError(err);
|
|
173
186
|
}
|
|
174
187
|
}
|
|
175
|
-
async
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
path,
|
|
179
|
-
data,
|
|
180
|
-
parameters,
|
|
181
|
-
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
|
|
182
|
-
timeout: options?.timeout,
|
|
183
|
-
});
|
|
184
|
-
if (res.ok) {
|
|
185
|
-
return res;
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
throw new Error(await responseStringify(res));
|
|
189
|
-
}
|
|
188
|
+
async _postUrlEncoded(path, data, parameters, options, headers) {
|
|
189
|
+
const baseHeaders = { 'Content-Type': 'application/x-www-form-urlencoded' };
|
|
190
|
+
return this._post(path, data, parameters, options, { ...baseHeaders, ...headers });
|
|
190
191
|
}
|
|
191
|
-
async
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
const res = await agent.post({
|
|
195
|
-
path,
|
|
196
|
-
data,
|
|
197
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
198
|
-
timeout: options?.timeout,
|
|
199
|
-
});
|
|
200
|
-
if (res.ok) {
|
|
201
|
-
return res;
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
throw new Error(await responseStringify(res));
|
|
205
|
-
}
|
|
192
|
+
async _postJsonEncoded(path, data, parameters, options, headers) {
|
|
193
|
+
const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
|
|
194
|
+
return this._post(path, data, parameters, options, { ...baseHeaders, ...headers });
|
|
206
195
|
}
|
|
207
196
|
}
|