camstreamerlib 4.0.34 → 4.0.35-64a81fd
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.d.ts +6 -0
- package/cjs/CamOverlayAPI.js +16 -0
- package/cjs/CamSwitcherAPI.d.ts +1 -1
- package/cjs/PlaneTrackerAPI.d.ts +43 -10
- package/cjs/PlaneTrackerAPI.js +2 -1
- package/cjs/VapixAPI.js +19 -13
- package/cjs/VapixAPI.test.d.ts +1 -0
- package/cjs/VapixAPI.test.js +146 -0
- package/cjs/errors/errors.js +4 -4
- package/cjs/types/CamSwitcherAPI.d.ts +4 -4
- package/cjs/types/PlaneTrackerAPI.d.ts +205 -39
- package/cjs/types/PlaneTrackerAPI.js +61 -22
- package/cjs/types/PlaneTrackerAPI.test.d.ts +1 -0
- package/cjs/types/PlaneTrackerAPI.test.js +90 -0
- package/cjs/types/common.d.ts +13 -0
- package/cjs/types/common.js +6 -1
- package/cjs/types/ws/CamSwitcherEvents.d.ts +8 -8
- package/esm/CamOverlayAPI.js +17 -1
- package/esm/PlaneTrackerAPI.js +2 -1
- package/esm/VapixAPI.js +20 -14
- package/esm/VapixAPI.test.js +144 -0
- package/esm/errors/errors.js +4 -4
- package/esm/types/PlaneTrackerAPI.js +60 -21
- package/esm/types/PlaneTrackerAPI.test.js +88 -0
- package/esm/types/common.js +5 -0
- package/package.json +107 -110
- package/types/CamOverlayAPI.d.ts +6 -0
- package/types/CamSwitcherAPI.d.ts +1 -1
- package/types/PlaneTrackerAPI.d.ts +43 -10
- package/types/VapixAPI.test.d.ts +1 -0
- package/types/types/CamSwitcherAPI.d.ts +4 -4
- package/types/types/PlaneTrackerAPI.d.ts +205 -39
- package/types/types/PlaneTrackerAPI.test.d.ts +1 -0
- package/types/types/common.d.ts +13 -0
- package/types/types/ws/CamSwitcherEvents.d.ts +8 -8
|
@@ -54,15 +54,15 @@ declare const cswEventsDataSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
|
|
|
54
54
|
}, "strip", z.ZodTypeAny, {
|
|
55
55
|
type: "StreamSwitchVideoError";
|
|
56
56
|
playlist_name: string;
|
|
57
|
-
playlist_active_stream: number;
|
|
58
57
|
info: string;
|
|
58
|
+
playlist_active_stream: number;
|
|
59
59
|
stream_name?: string | undefined;
|
|
60
60
|
clip_name?: string | undefined;
|
|
61
61
|
}, {
|
|
62
62
|
type: "StreamSwitchVideoError";
|
|
63
63
|
playlist_name: string;
|
|
64
|
-
playlist_active_stream: number;
|
|
65
64
|
info: string;
|
|
65
|
+
playlist_active_stream: number;
|
|
66
66
|
stream_name?: string | undefined;
|
|
67
67
|
clip_name?: string | undefined;
|
|
68
68
|
}>, z.ZodObject<{
|
|
@@ -207,15 +207,15 @@ export declare const cswEventsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObje
|
|
|
207
207
|
}, "strip", z.ZodTypeAny, {
|
|
208
208
|
type: "StreamSwitchVideoError";
|
|
209
209
|
playlist_name: string;
|
|
210
|
-
playlist_active_stream: number;
|
|
211
210
|
info: string;
|
|
211
|
+
playlist_active_stream: number;
|
|
212
212
|
stream_name?: string | undefined;
|
|
213
213
|
clip_name?: string | undefined;
|
|
214
214
|
}, {
|
|
215
215
|
type: "StreamSwitchVideoError";
|
|
216
216
|
playlist_name: string;
|
|
217
|
-
playlist_active_stream: number;
|
|
218
217
|
info: string;
|
|
218
|
+
playlist_active_stream: number;
|
|
219
219
|
stream_name?: string | undefined;
|
|
220
220
|
clip_name?: string | undefined;
|
|
221
221
|
}>, z.ZodObject<{
|
|
@@ -323,8 +323,8 @@ export declare const cswEventsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObje
|
|
|
323
323
|
} | {
|
|
324
324
|
type: "StreamSwitchVideoError";
|
|
325
325
|
playlist_name: string;
|
|
326
|
-
playlist_active_stream: number;
|
|
327
326
|
info: string;
|
|
327
|
+
playlist_active_stream: number;
|
|
328
328
|
stream_name?: string | undefined;
|
|
329
329
|
clip_name?: string | undefined;
|
|
330
330
|
} | {
|
|
@@ -376,8 +376,8 @@ export declare const cswEventsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObje
|
|
|
376
376
|
} | {
|
|
377
377
|
type: "StreamSwitchVideoError";
|
|
378
378
|
playlist_name: string;
|
|
379
|
-
playlist_active_stream: number;
|
|
380
379
|
info: string;
|
|
380
|
+
playlist_active_stream: number;
|
|
381
381
|
stream_name?: string | undefined;
|
|
382
382
|
clip_name?: string | undefined;
|
|
383
383
|
} | {
|
|
@@ -464,15 +464,15 @@ export declare const cswEventsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObje
|
|
|
464
464
|
}, "strip", z.ZodTypeAny, {
|
|
465
465
|
type: "StreamSwitchVideoError";
|
|
466
466
|
playlist_name: string;
|
|
467
|
-
playlist_active_stream: number;
|
|
468
467
|
info: string;
|
|
468
|
+
playlist_active_stream: number;
|
|
469
469
|
stream_name?: string | undefined;
|
|
470
470
|
clip_name?: string | undefined;
|
|
471
471
|
}, {
|
|
472
472
|
type: "StreamSwitchVideoError";
|
|
473
473
|
playlist_name: string;
|
|
474
|
-
playlist_active_stream: number;
|
|
475
474
|
info: string;
|
|
475
|
+
playlist_active_stream: number;
|
|
476
476
|
stream_name?: string | undefined;
|
|
477
477
|
clip_name?: string | undefined;
|
|
478
478
|
}>, z.ZodObject<{
|
package/esm/CamOverlayAPI.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ErrorWithResponse, ServiceNotFoundError, StorageDataFetchError } from './errors/errors';
|
|
2
|
-
import { networkCameraListSchema } from './types/common';
|
|
2
|
+
import { networkCameraListSchema, wsAliasResponseSchema } from './types/common';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { ImageType, serviceListSchema, servicesSchema, wsResponseSchema, getStorageDataListSchema, getFileListSchema, } from './types/CamOverlayAPI';
|
|
5
5
|
import { BasicAPI } from './internal/BasicAPI';
|
|
@@ -26,6 +26,22 @@ export class CamOverlayAPI extends BasicAPI {
|
|
|
26
26
|
async getMjpegStreamImage(mjpegUrl, options) {
|
|
27
27
|
return await this._getBlob(`${BASE_PATH}/fetch_mjpeg_image.cgi`, { mjpeg_url: decodeURIComponent(mjpegUrl) }, options);
|
|
28
28
|
}
|
|
29
|
+
async isViewerPassValid(pass, options) {
|
|
30
|
+
const res = await this._getJson(`${BASE_PATH}/check_pass.cgi`, { pass }, options);
|
|
31
|
+
if (res.status !== 200) {
|
|
32
|
+
throw new Error(res.message);
|
|
33
|
+
}
|
|
34
|
+
return res.data === '1';
|
|
35
|
+
}
|
|
36
|
+
async getLiveViewAlias(rtspUrl, options) {
|
|
37
|
+
const agent = this.getClient(options?.proxyParams);
|
|
38
|
+
const res = await agent.get({
|
|
39
|
+
path: `${BASE_PATH}/getLiveViewAlias.cgi`,
|
|
40
|
+
parameters: { rtsp_url: rtspUrl },
|
|
41
|
+
timeout: options?.timeout,
|
|
42
|
+
});
|
|
43
|
+
return wsAliasResponseSchema.parse(await res.json());
|
|
44
|
+
}
|
|
29
45
|
async listFiles(fileType, options) {
|
|
30
46
|
const res = await this._getJson(`${BASE_PATH}/upload_${fileType}.cgi`, { action: 'list' }, options);
|
|
31
47
|
return getFileListSchema(fileType).parse(res.list);
|
package/esm/PlaneTrackerAPI.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { blackListSchema, cameraSettingsSchema, domainListSchema, flightInfoSchema, getIcaoSchema, mapInfoSchema, milestoneCameraListSchema, priorityListSchema, serverSettingsSchema, trackingModeSchema, whiteListSchema,
|
|
2
|
+
import { blackListSchema, cameraSettingsSchema, domainListSchema, flightInfoSchema, getIcaoSchema, mapInfoSchema, milestoneCameraListSchema, priorityListSchema, serverSettingsSchema, trackingModeSchema, whiteListSchema, zonesSchema, } from './types/PlaneTrackerAPI';
|
|
3
3
|
import { CannotSetCoordsInAutoModeError, ImportSettingsError, InvalidAltitudeError, InvalidLatLngError, ResetCalibrationError, ServerError, BadRequestError, } from './errors/errors';
|
|
4
|
+
import { wsAliasResponseSchema } from './types/common';
|
|
4
5
|
import { BasicAPI } from './internal/BasicAPI';
|
|
5
6
|
import { apiUserInputSchema } from './types/ws/PlaneTrackerEvents';
|
|
6
7
|
const BASE_PATH = '/local/planetracker';
|
package/esm/VapixAPI.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { arrayToUrl, isNullish, paramToUrl } from './internal/utils';
|
|
2
|
-
import { sdCardWatchedStatuses, maxFpsResponseSchema, dateTimeinfoSchema, audioDeviceRequestSchema, audioSampleRatesResponseSchema, timeZoneSchema, getPortsResponseSchema, guardTourSchema, ptzOverviewSchema, cameraPTZItemDataSchema,
|
|
2
|
+
import { sdCardWatchedStatuses, maxFpsResponseSchema, dateTimeinfoSchema, audioDeviceRequestSchema, audioSampleRatesResponseSchema, applicationSchema, timeZoneSchema, getPortsResponseSchema, guardTourSchema, ptzOverviewSchema, cameraPTZItemDataSchema, sdCardInfoSchema, ALL_APP_IDS, allDateTimeInfoSchema, } from './types/VapixAPI';
|
|
3
3
|
import { ApplicationAPIError, MaxFPSError, NoDeviceInfoError, PtzNotSupportedError, ErrorWithResponse, SDCardActionError, SDCardJobError, SettingParameterError, TimezoneFetchError, } from './errors/errors';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { XMLParser } from 'fast-xml-parser';
|
|
@@ -90,7 +90,9 @@ export class VapixAPI extends BasicAPI {
|
|
|
90
90
|
};
|
|
91
91
|
await this._postJsonEncoded('/axis-cgi/opticscontrol.cgi', data, undefined, options);
|
|
92
92
|
}
|
|
93
|
-
catch {
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.warn('Failed to perform autofocus: ', error instanceof Error ? error.message : String(error));
|
|
95
|
+
console.warn('Falling back to deprecated optics setup API');
|
|
94
96
|
await this._postUrlEncoded('/axis-cgi/opticssetup.cgi', {
|
|
95
97
|
autofocus: 'perform',
|
|
96
98
|
source: '1',
|
|
@@ -141,7 +143,7 @@ export class VapixAPI extends BasicAPI {
|
|
|
141
143
|
return data.data.activeTimeZone;
|
|
142
144
|
}
|
|
143
145
|
catch (error) {
|
|
144
|
-
console.warn('Failed to fetch time zone data from time API v2:', error instanceof Error ? error.message :
|
|
146
|
+
console.warn('Failed to fetch time zone data from time API v2:', error instanceof Error ? error.message : String(error));
|
|
145
147
|
console.warn('Falling back to deprecated time API v1');
|
|
146
148
|
}
|
|
147
149
|
try {
|
|
@@ -560,17 +562,21 @@ export class VapixAPI extends BasicAPI {
|
|
|
560
562
|
allowBooleanAttributes: true,
|
|
561
563
|
});
|
|
562
564
|
const result = parser.parse(xml);
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
|
|
565
|
+
const rawApps = result.reply.application ?? [];
|
|
566
|
+
const apps = Array.isArray(rawApps) ? rawApps : [rawApps];
|
|
567
|
+
const appList = [];
|
|
568
|
+
for (const app of apps) {
|
|
569
|
+
const parsedApp = applicationSchema.safeParse(app);
|
|
570
|
+
if (!parsedApp.success) {
|
|
571
|
+
console.debug('Skipping invalid application entry:', app, parsedApp.error.issues);
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
appList.push({
|
|
575
|
+
...parsedApp.data,
|
|
576
|
+
appId: ALL_APP_IDS.find((id) => id.toLowerCase() === parsedApp.data.Name.toLowerCase()) ?? null,
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
return appList;
|
|
574
580
|
}
|
|
575
581
|
async startApplication(applicationId, options) {
|
|
576
582
|
const agent = this.getClient(options?.proxyParams);
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { VapixAPI } from './VapixAPI';
|
|
2
|
+
import { describe, test, expect, jest, afterEach } from '@jest/globals';
|
|
3
|
+
const createApi = (xml) => {
|
|
4
|
+
const client = {
|
|
5
|
+
get: () => Promise.resolve(new Response(xml)),
|
|
6
|
+
post: () => Promise.reject(new Error('unused')),
|
|
7
|
+
};
|
|
8
|
+
return new VapixAPI(client);
|
|
9
|
+
};
|
|
10
|
+
describe('VapixAPI', () => {
|
|
11
|
+
describe('getApplicationList', () => {
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
jest.restoreAllMocks();
|
|
14
|
+
});
|
|
15
|
+
test('skips the nameless entry of the live camera list', async () => {
|
|
16
|
+
const debugSpy = jest.spyOn(console, 'debug').mockImplementation(() => { });
|
|
17
|
+
const api = createApi(`<reply result="ok">
|
|
18
|
+
<application Name="camstreamer" NiceName="CamStreamer App" Vendor="CamStreamer" Version="5.0-15" ApplicationID="413135" License="None" Status="Running" ConfigurationPage="local/camstreamer/settings.html" />
|
|
19
|
+
<application Name="" License="None" Status="Stopped" />
|
|
20
|
+
<application Name="vmd" NiceName="AXIS Video Motion Detection" Vendor="Axis Communications" Version="4.4-5" ApplicationID="143440" License="None" Status="Stopped" ConfigurationPage="local/vmd/config.html" VendorHomePage="http://www.axis.com" LicenseName="Proprietary" />
|
|
21
|
+
</reply>`);
|
|
22
|
+
await expect(api.getApplicationList()).resolves.toEqual([
|
|
23
|
+
{
|
|
24
|
+
Name: 'camstreamer',
|
|
25
|
+
NiceName: 'CamStreamer App',
|
|
26
|
+
Vendor: 'CamStreamer',
|
|
27
|
+
Version: '5.0-15',
|
|
28
|
+
ApplicationID: '413135',
|
|
29
|
+
License: 'None',
|
|
30
|
+
Status: 'Running',
|
|
31
|
+
ConfigurationPage: 'local/camstreamer/settings.html',
|
|
32
|
+
appId: 'CamStreamer',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
Name: 'vmd',
|
|
36
|
+
NiceName: 'AXIS Video Motion Detection',
|
|
37
|
+
Vendor: 'Axis Communications',
|
|
38
|
+
Version: '4.4-5',
|
|
39
|
+
ApplicationID: '143440',
|
|
40
|
+
License: 'None',
|
|
41
|
+
Status: 'Stopped',
|
|
42
|
+
ConfigurationPage: 'local/vmd/config.html',
|
|
43
|
+
VendorHomePage: 'http://www.axis.com',
|
|
44
|
+
LicenseName: 'Proprietary',
|
|
45
|
+
appId: null,
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
expect(debugSpy).toHaveBeenCalledTimes(1);
|
|
49
|
+
expect(debugSpy.mock.calls[0]).toContainEqual({ Name: '', License: 'None', Status: 'Stopped' });
|
|
50
|
+
});
|
|
51
|
+
test.each([
|
|
52
|
+
{
|
|
53
|
+
name: 'an entry without a name',
|
|
54
|
+
xml: '<reply result="ok"><application Name="vmd" NiceName="AXIS Video Motion Detection" Vendor="Axis Communications" Version="4.4-5" License="None" Status="Stopped" /><application License="None" Status="Stopped" /></reply>',
|
|
55
|
+
expected: [
|
|
56
|
+
{
|
|
57
|
+
Name: 'vmd',
|
|
58
|
+
NiceName: 'AXIS Video Motion Detection',
|
|
59
|
+
Vendor: 'Axis Communications',
|
|
60
|
+
Version: '4.4-5',
|
|
61
|
+
License: 'None',
|
|
62
|
+
Status: 'Stopped',
|
|
63
|
+
appId: null,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'a named entry missing informational fields',
|
|
69
|
+
xml: '<reply result="ok"><application Name="vmd" NiceName="AXIS Video Motion Detection" Vendor="Axis Communications" Version="4.4-5" License="None" Status="Stopped" /><application Name="broken" License="None" Status="Stopped" /></reply>',
|
|
70
|
+
expected: [
|
|
71
|
+
{
|
|
72
|
+
Name: 'vmd',
|
|
73
|
+
NiceName: 'AXIS Video Motion Detection',
|
|
74
|
+
Vendor: 'Axis Communications',
|
|
75
|
+
Version: '4.4-5',
|
|
76
|
+
License: 'None',
|
|
77
|
+
Status: 'Stopped',
|
|
78
|
+
appId: null,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
])('skips invalid entries individually: $name', async ({ xml, expected }) => {
|
|
83
|
+
const debugSpy = jest.spyOn(console, 'debug').mockImplementation(() => { });
|
|
84
|
+
await expect(createApi(xml).getApplicationList()).resolves.toEqual(expected);
|
|
85
|
+
expect(debugSpy).toHaveBeenCalledTimes(1);
|
|
86
|
+
});
|
|
87
|
+
test.each([
|
|
88
|
+
{
|
|
89
|
+
name: 'drops attributes outside the schema',
|
|
90
|
+
xml: '<reply result="ok"><application Name="camoverlay" NiceName="CamOverlay App" Vendor="CamStreamer" Version="3.0-1" License="None" Status="Running" Unexpected="value" /></reply>',
|
|
91
|
+
expected: [
|
|
92
|
+
{
|
|
93
|
+
Name: 'camoverlay',
|
|
94
|
+
NiceName: 'CamOverlay App',
|
|
95
|
+
Vendor: 'CamStreamer',
|
|
96
|
+
Version: '3.0-1',
|
|
97
|
+
License: 'None',
|
|
98
|
+
Status: 'Running',
|
|
99
|
+
appId: 'CamOverlay',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'maps an application outside the core CamStreamer apps to its appId',
|
|
105
|
+
xml: '<reply result="ok"><application Name="sporttracker" NiceName="SportTracker App" Vendor="CamStreamer" Version="1.0-1" License="None" Status="Running" /></reply>',
|
|
106
|
+
expected: [
|
|
107
|
+
{
|
|
108
|
+
Name: 'sporttracker',
|
|
109
|
+
NiceName: 'SportTracker App',
|
|
110
|
+
Vendor: 'CamStreamer',
|
|
111
|
+
Version: '1.0-1',
|
|
112
|
+
License: 'None',
|
|
113
|
+
Status: 'Running',
|
|
114
|
+
appId: 'SportTracker',
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'maps a capitalised application name to its appId',
|
|
120
|
+
xml: '<reply result="ok"><application Name="CamOverlay" NiceName="CamOverlay App" Vendor="CamStreamer" Version="3.0-1" License="None" Status="Running" /></reply>',
|
|
121
|
+
expected: [
|
|
122
|
+
{
|
|
123
|
+
Name: 'CamOverlay',
|
|
124
|
+
NiceName: 'CamOverlay App',
|
|
125
|
+
Vendor: 'CamStreamer',
|
|
126
|
+
Version: '3.0-1',
|
|
127
|
+
License: 'None',
|
|
128
|
+
Status: 'Running',
|
|
129
|
+
appId: 'CamOverlay',
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: 'returns an empty list when the camera has no applications',
|
|
135
|
+
xml: '<reply result="ok"></reply>',
|
|
136
|
+
expected: [],
|
|
137
|
+
},
|
|
138
|
+
])('returns every valid entry with its appId and logs nothing: $name', async ({ xml, expected }) => {
|
|
139
|
+
const debugSpy = jest.spyOn(console, 'debug').mockImplementation(() => { });
|
|
140
|
+
await expect(createApi(xml).getApplicationList()).resolves.toEqual(expected);
|
|
141
|
+
expect(debugSpy).not.toHaveBeenCalled();
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
package/esm/errors/errors.js
CHANGED
|
@@ -20,7 +20,7 @@ export class ServiceNotFoundError extends Error {
|
|
|
20
20
|
}
|
|
21
21
|
export class ParsingBlobError extends Error {
|
|
22
22
|
constructor(err) {
|
|
23
|
-
super('Error parsing response as Blob: ' + err);
|
|
23
|
+
super('Error parsing response as Blob: ' + String(err));
|
|
24
24
|
this.name = 'ParsingBlobError';
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -84,7 +84,7 @@ export class NoDeviceInfoError extends Error {
|
|
|
84
84
|
}
|
|
85
85
|
export class FetchDeviceInfoError extends Error {
|
|
86
86
|
constructor(err) {
|
|
87
|
-
super('Error fetching remote camera data: ' + err);
|
|
87
|
+
super('Error fetching remote camera data: ' + String(err));
|
|
88
88
|
this.name = 'NoDeviceInfoFromCameraError';
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -108,7 +108,7 @@ export class PtzNotSupportedError extends Error {
|
|
|
108
108
|
}
|
|
109
109
|
export class StorageDataFetchError extends Error {
|
|
110
110
|
constructor(err) {
|
|
111
|
-
super('Error fetching storage data: ' + err);
|
|
111
|
+
super('Error fetching storage data: ' + String(err));
|
|
112
112
|
this.name = 'StorageDataFetchError';
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -132,7 +132,7 @@ export class TimezoneNotSetupError extends Error {
|
|
|
132
132
|
}
|
|
133
133
|
export class TimezoneFetchError extends Error {
|
|
134
134
|
constructor(err) {
|
|
135
|
-
super('Error fetching time zone information: ' + err);
|
|
135
|
+
super('Error fetching time zone information: ' + String(err));
|
|
136
136
|
this.name = 'TimezoneFetchError';
|
|
137
137
|
}
|
|
138
138
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export const wsAliasResponseSchema = z.object({
|
|
3
|
-
alias: z.string(),
|
|
4
|
-
ws: z.string(),
|
|
5
|
-
ws_initial_message: z.string(),
|
|
6
|
-
});
|
|
7
2
|
export const connectionSchema = z.object({
|
|
8
3
|
protocol: z.union([z.literal('http'), z.literal('https'), z.literal('https_insecure')]),
|
|
9
4
|
ip: z.union([z.string().ip(), z.literal('')]),
|
|
@@ -37,13 +32,59 @@ const labelOptionsSchema = z.union([
|
|
|
37
32
|
z.literal('flight_number'),
|
|
38
33
|
z.literal('icao'),
|
|
39
34
|
]);
|
|
40
|
-
const
|
|
35
|
+
const aircraftIdentificationLabelSchema = z.object({
|
|
41
36
|
firstRow: labelOptionsSchema,
|
|
42
37
|
secondRow: labelOptionsSchema,
|
|
43
38
|
thirdRow: labelOptionsSchema,
|
|
44
39
|
fourthRow: labelOptionsSchema,
|
|
45
|
-
opacity: z.number().
|
|
40
|
+
opacity: z.number().nonnegative(),
|
|
41
|
+
});
|
|
42
|
+
const droneLabelOptionsSchema = z.union([z.literal('blank'), z.literal('remote_id')]);
|
|
43
|
+
const droneIdentificationLabelSchema = z.object({
|
|
44
|
+
firstRow: droneLabelOptionsSchema,
|
|
45
|
+
opacity: z.number().nonnegative(),
|
|
46
|
+
});
|
|
47
|
+
const DEFAULT_DRONE_IDENTIFICATION_LABEL = {
|
|
48
|
+
firstRow: 'remote_id',
|
|
49
|
+
opacity: 30,
|
|
50
|
+
};
|
|
51
|
+
const identificationLabelSchema = z.union([
|
|
52
|
+
z.object({
|
|
53
|
+
aircraft: aircraftIdentificationLabelSchema,
|
|
54
|
+
drone: droneIdentificationLabelSchema.default(DEFAULT_DRONE_IDENTIFICATION_LABEL),
|
|
55
|
+
}),
|
|
56
|
+
aircraftIdentificationLabelSchema.transform((aircraft) => ({
|
|
57
|
+
aircraft,
|
|
58
|
+
drone: { ...DEFAULT_DRONE_IDENTIFICATION_LABEL },
|
|
59
|
+
})),
|
|
60
|
+
]);
|
|
61
|
+
const captureConfigSchema = z.object({
|
|
62
|
+
defaultCaptureSizeMeters: z.number().positive(),
|
|
63
|
+
captureSizeExtensionMeters: z.number().positive(),
|
|
46
64
|
});
|
|
65
|
+
const DEFAULT_CAPTURE_CONFIG = {
|
|
66
|
+
defaultCaptureSizeMeters: 120,
|
|
67
|
+
captureSizeExtensionMeters: 80,
|
|
68
|
+
};
|
|
69
|
+
const cameraConfigSchema = z.union([
|
|
70
|
+
z.object({
|
|
71
|
+
aircraft: captureConfigSchema,
|
|
72
|
+
drone: captureConfigSchema.default(() => ({ ...DEFAULT_CAPTURE_CONFIG })),
|
|
73
|
+
}),
|
|
74
|
+
z
|
|
75
|
+
.object({
|
|
76
|
+
defaultCaptureSizeMeters: z.number().positive().default(DEFAULT_CAPTURE_CONFIG.defaultCaptureSizeMeters),
|
|
77
|
+
captureSizeExtensionMeters: z
|
|
78
|
+
.number()
|
|
79
|
+
.positive()
|
|
80
|
+
.default(DEFAULT_CAPTURE_CONFIG.captureSizeExtensionMeters),
|
|
81
|
+
})
|
|
82
|
+
.strict()
|
|
83
|
+
.transform((captureConfig) => ({
|
|
84
|
+
aircraft: captureConfig,
|
|
85
|
+
drone: { ...captureConfig },
|
|
86
|
+
})),
|
|
87
|
+
]);
|
|
47
88
|
export const cameraSettingsSchema = z.object({
|
|
48
89
|
units: z.union([z.literal('metric'), z.literal('imperial')]).default('imperial'),
|
|
49
90
|
adsbSource: z
|
|
@@ -81,15 +122,10 @@ export const cameraSettingsSchema = z.object({
|
|
|
81
122
|
nightSkyCalibrationFocusValue: 9000,
|
|
82
123
|
focusCalibrationPoints: '',
|
|
83
124
|
}),
|
|
84
|
-
cameraConfig:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
})
|
|
89
|
-
.default({
|
|
90
|
-
defaultCaptureSizeMeters: 120,
|
|
91
|
-
captureSizeExtensionMeters: 80,
|
|
92
|
-
}),
|
|
125
|
+
cameraConfig: cameraConfigSchema.default(() => ({
|
|
126
|
+
aircraft: { ...DEFAULT_CAPTURE_CONFIG },
|
|
127
|
+
drone: { ...DEFAULT_CAPTURE_CONFIG },
|
|
128
|
+
})),
|
|
93
129
|
stream: z
|
|
94
130
|
.object({
|
|
95
131
|
width: z.number().positive(),
|
|
@@ -200,11 +236,14 @@ export const cameraSettingsSchema = z.object({
|
|
|
200
236
|
port: 80,
|
|
201
237
|
}),
|
|
202
238
|
identificationLabel: identificationLabelSchema.default({
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
239
|
+
aircraft: {
|
|
240
|
+
firstRow: 'icao',
|
|
241
|
+
secondRow: 'call_sign',
|
|
242
|
+
thirdRow: 'blank',
|
|
243
|
+
fourthRow: 'blank',
|
|
244
|
+
opacity: 30,
|
|
245
|
+
},
|
|
246
|
+
drone: DEFAULT_DRONE_IDENTIFICATION_LABEL,
|
|
208
247
|
}),
|
|
209
248
|
acs: connectionSchema
|
|
210
249
|
.extend({
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { cameraSettingsSchema } from './PlaneTrackerAPI';
|
|
2
|
+
import { describe, test, expect } from '@jest/globals';
|
|
3
|
+
const AIRCRAFT_LABEL = {
|
|
4
|
+
firstRow: 'icao',
|
|
5
|
+
secondRow: 'call_sign',
|
|
6
|
+
thirdRow: 'blank',
|
|
7
|
+
fourthRow: 'registration',
|
|
8
|
+
opacity: 50,
|
|
9
|
+
};
|
|
10
|
+
const DEFAULT_DRONE_LABEL = { firstRow: 'remote_id', opacity: 30 };
|
|
11
|
+
describe('cameraSettingsSchema identificationLabel', () => {
|
|
12
|
+
test('defaults both aircraft and drone labels', () => {
|
|
13
|
+
expect(cameraSettingsSchema.parse({}).identificationLabel).toEqual({
|
|
14
|
+
aircraft: {
|
|
15
|
+
firstRow: 'icao',
|
|
16
|
+
secondRow: 'call_sign',
|
|
17
|
+
thirdRow: 'blank',
|
|
18
|
+
fourthRow: 'blank',
|
|
19
|
+
opacity: 30,
|
|
20
|
+
},
|
|
21
|
+
drone: DEFAULT_DRONE_LABEL,
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
test('parses the aircraft and drone label', () => {
|
|
25
|
+
const identificationLabel = { aircraft: AIRCRAFT_LABEL, drone: { firstRow: 'blank', opacity: 70 } };
|
|
26
|
+
expect(cameraSettingsSchema.parse({ identificationLabel }).identificationLabel).toEqual(identificationLabel);
|
|
27
|
+
});
|
|
28
|
+
test('defaults a missing drone label', () => {
|
|
29
|
+
expect(cameraSettingsSchema.parse({ identificationLabel: { aircraft: AIRCRAFT_LABEL } }).identificationLabel).toEqual({ aircraft: AIRCRAFT_LABEL, drone: DEFAULT_DRONE_LABEL });
|
|
30
|
+
});
|
|
31
|
+
test('converts the legacy flat label to the aircraft label', () => {
|
|
32
|
+
expect(cameraSettingsSchema.parse({ identificationLabel: AIRCRAFT_LABEL }).identificationLabel).toEqual({
|
|
33
|
+
aircraft: AIRCRAFT_LABEL,
|
|
34
|
+
drone: DEFAULT_DRONE_LABEL,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
test('returns an independent drone label for each legacy parse', () => {
|
|
38
|
+
const first = cameraSettingsSchema.parse({ identificationLabel: AIRCRAFT_LABEL });
|
|
39
|
+
first.identificationLabel.drone.opacity = 90;
|
|
40
|
+
const second = cameraSettingsSchema.parse({ identificationLabel: AIRCRAFT_LABEL });
|
|
41
|
+
expect(second.identificationLabel.drone).toEqual(DEFAULT_DRONE_LABEL);
|
|
42
|
+
});
|
|
43
|
+
test('rejects an unknown drone label row', () => {
|
|
44
|
+
const identificationLabel = { aircraft: AIRCRAFT_LABEL, drone: { firstRow: 'icao', opacity: 30 } };
|
|
45
|
+
expect(cameraSettingsSchema.safeParse({ identificationLabel }).success).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
const CAPTURE_CONFIG = { defaultCaptureSizeMeters: 50, captureSizeExtensionMeters: 20 };
|
|
49
|
+
const DEFAULT_CAPTURE_CONFIG = { defaultCaptureSizeMeters: 120, captureSizeExtensionMeters: 80 };
|
|
50
|
+
describe('cameraSettingsSchema cameraConfig', () => {
|
|
51
|
+
test('defaults both aircraft and drone capture config', () => {
|
|
52
|
+
expect(cameraSettingsSchema.parse({}).cameraConfig).toEqual({
|
|
53
|
+
aircraft: DEFAULT_CAPTURE_CONFIG,
|
|
54
|
+
drone: DEFAULT_CAPTURE_CONFIG,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
test('parses independent aircraft and drone capture config', () => {
|
|
58
|
+
const cameraConfig = {
|
|
59
|
+
aircraft: CAPTURE_CONFIG,
|
|
60
|
+
drone: { defaultCaptureSizeMeters: 5, captureSizeExtensionMeters: 3 },
|
|
61
|
+
};
|
|
62
|
+
expect(cameraSettingsSchema.parse({ cameraConfig }).cameraConfig).toEqual(cameraConfig);
|
|
63
|
+
});
|
|
64
|
+
test('defaults a missing drone capture config', () => {
|
|
65
|
+
expect(cameraSettingsSchema.parse({ cameraConfig: { aircraft: CAPTURE_CONFIG } }).cameraConfig).toEqual({
|
|
66
|
+
aircraft: CAPTURE_CONFIG,
|
|
67
|
+
drone: DEFAULT_CAPTURE_CONFIG,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
test('copies the legacy flat capture config to both aircraft and drone', () => {
|
|
71
|
+
expect(cameraSettingsSchema.parse({ cameraConfig: CAPTURE_CONFIG }).cameraConfig).toEqual({
|
|
72
|
+
aircraft: CAPTURE_CONFIG,
|
|
73
|
+
drone: CAPTURE_CONFIG,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
test('returns independent aircraft and drone objects', () => {
|
|
77
|
+
const legacy = cameraSettingsSchema.parse({ cameraConfig: CAPTURE_CONFIG }).cameraConfig;
|
|
78
|
+
legacy.drone.defaultCaptureSizeMeters = 1;
|
|
79
|
+
expect(legacy.aircraft).toEqual(CAPTURE_CONFIG);
|
|
80
|
+
const first = cameraSettingsSchema.parse({}).cameraConfig;
|
|
81
|
+
first.drone.defaultCaptureSizeMeters = 1;
|
|
82
|
+
expect(cameraSettingsSchema.parse({}).cameraConfig.drone).toEqual(DEFAULT_CAPTURE_CONFIG);
|
|
83
|
+
});
|
|
84
|
+
test('rejects a non-positive drone capture size', () => {
|
|
85
|
+
const cameraConfig = { aircraft: CAPTURE_CONFIG, drone: { ...CAPTURE_CONFIG, defaultCaptureSizeMeters: 0 } };
|
|
86
|
+
expect(cameraSettingsSchema.safeParse({ cameraConfig }).success).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
});
|
package/esm/types/common.js
CHANGED
|
@@ -12,6 +12,11 @@ export const networkCameraListSchema = z.array(z.object({
|
|
|
12
12
|
}));
|
|
13
13
|
export const keyboardShortcutSchema = z.string().nullable();
|
|
14
14
|
export const keyboardShortcutsSchema = z.record(keyboardShortcutSchema);
|
|
15
|
+
export const wsAliasResponseSchema = z.object({
|
|
16
|
+
alias: z.string(),
|
|
17
|
+
ws: z.string(),
|
|
18
|
+
ws_initial_message: z.string(),
|
|
19
|
+
});
|
|
15
20
|
export const bitrateModeSchema = z.union([z.literal('VBR'), z.literal('MBR'), z.literal('ABR')]);
|
|
16
21
|
export const bitrateVapixParamsSchema = z.object({
|
|
17
22
|
bitrateMode: bitrateModeSchema,
|