camstreamerlib 4.0.35 → 4.0.36-05711a0
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.d.ts +45 -9
- package/cjs/VapixAPI.js +15 -11
- package/cjs/VapixAPI.test.d.ts +1 -0
- package/cjs/VapixAPI.test.js +146 -0
- package/cjs/types/PlaneTrackerAPI.d.ts +223 -26
- package/cjs/types/PlaneTrackerAPI.js +71 -17
- package/cjs/types/PlaneTrackerAPI.test.d.ts +1 -0
- package/cjs/types/PlaneTrackerAPI.test.js +117 -0
- package/cjs/types/ws/CamSwitcherEvents.d.ts +8 -8
- package/esm/VapixAPI.js +16 -12
- package/esm/VapixAPI.test.js +144 -0
- package/esm/types/PlaneTrackerAPI.js +71 -17
- package/esm/types/PlaneTrackerAPI.test.js +115 -0
- package/package.json +107 -107
- package/types/PlaneTrackerAPI.d.ts +45 -9
- package/types/VapixAPI.test.d.ts +1 -0
- package/types/types/PlaneTrackerAPI.d.ts +223 -26
- package/types/types/PlaneTrackerAPI.test.d.ts +1 -0
- package/types/types/ws/CamSwitcherEvents.d.ts +8 -8
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const PlaneTrackerAPI_1 = require("./PlaneTrackerAPI");
|
|
4
|
+
const globals_1 = require("@jest/globals");
|
|
5
|
+
const AIRCRAFT_LABEL = {
|
|
6
|
+
firstRow: 'icao',
|
|
7
|
+
secondRow: 'call_sign',
|
|
8
|
+
thirdRow: 'blank',
|
|
9
|
+
fourthRow: 'registration',
|
|
10
|
+
opacity: 50,
|
|
11
|
+
};
|
|
12
|
+
const DEFAULT_DRONE_LABEL = { firstRow: 'remote_id', opacity: 30 };
|
|
13
|
+
(0, globals_1.describe)('cameraSettingsSchema identificationLabel', () => {
|
|
14
|
+
(0, globals_1.test)('defaults both aircraft and drone labels', () => {
|
|
15
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.parse({}).identificationLabel).toEqual({
|
|
16
|
+
aircraft: {
|
|
17
|
+
firstRow: 'icao',
|
|
18
|
+
secondRow: 'call_sign',
|
|
19
|
+
thirdRow: 'blank',
|
|
20
|
+
fourthRow: 'blank',
|
|
21
|
+
opacity: 30,
|
|
22
|
+
},
|
|
23
|
+
drone: DEFAULT_DRONE_LABEL,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
(0, globals_1.test)('parses the aircraft and drone label', () => {
|
|
27
|
+
const identificationLabel = { aircraft: AIRCRAFT_LABEL, drone: { firstRow: 'blank', opacity: 70 } };
|
|
28
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.parse({ identificationLabel }).identificationLabel).toEqual(identificationLabel);
|
|
29
|
+
});
|
|
30
|
+
(0, globals_1.test)('defaults a missing drone label', () => {
|
|
31
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.parse({ identificationLabel: { aircraft: AIRCRAFT_LABEL } }).identificationLabel).toEqual({ aircraft: AIRCRAFT_LABEL, drone: DEFAULT_DRONE_LABEL });
|
|
32
|
+
});
|
|
33
|
+
(0, globals_1.test)('converts the legacy flat label to the aircraft label', () => {
|
|
34
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.parse({ identificationLabel: AIRCRAFT_LABEL }).identificationLabel).toEqual({
|
|
35
|
+
aircraft: AIRCRAFT_LABEL,
|
|
36
|
+
drone: DEFAULT_DRONE_LABEL,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
(0, globals_1.test)('returns an independent drone label for each legacy parse', () => {
|
|
40
|
+
const first = PlaneTrackerAPI_1.cameraSettingsSchema.parse({ identificationLabel: AIRCRAFT_LABEL });
|
|
41
|
+
first.identificationLabel.drone.opacity = 90;
|
|
42
|
+
const second = PlaneTrackerAPI_1.cameraSettingsSchema.parse({ identificationLabel: AIRCRAFT_LABEL });
|
|
43
|
+
(0, globals_1.expect)(second.identificationLabel.drone).toEqual(DEFAULT_DRONE_LABEL);
|
|
44
|
+
});
|
|
45
|
+
(0, globals_1.test)('rejects an unknown drone label row', () => {
|
|
46
|
+
const identificationLabel = { aircraft: AIRCRAFT_LABEL, drone: { firstRow: 'icao', opacity: 30 } };
|
|
47
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.safeParse({ identificationLabel }).success).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
const CAPTURE_CONFIG = { defaultCaptureSizeMeters: 50, captureSizeExtensionMeters: 20 };
|
|
51
|
+
const DEFAULT_CAPTURE_CONFIG = { defaultCaptureSizeMeters: 120, captureSizeExtensionMeters: 80 };
|
|
52
|
+
(0, globals_1.describe)('cameraSettingsSchema cameraConfig', () => {
|
|
53
|
+
(0, globals_1.test)('defaults both aircraft and drone capture config', () => {
|
|
54
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.parse({}).cameraConfig).toEqual({
|
|
55
|
+
aircraft: DEFAULT_CAPTURE_CONFIG,
|
|
56
|
+
drone: DEFAULT_CAPTURE_CONFIG,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
(0, globals_1.test)('parses independent aircraft and drone capture config', () => {
|
|
60
|
+
const cameraConfig = {
|
|
61
|
+
aircraft: CAPTURE_CONFIG,
|
|
62
|
+
drone: { defaultCaptureSizeMeters: 5, captureSizeExtensionMeters: 3 },
|
|
63
|
+
};
|
|
64
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.parse({ cameraConfig }).cameraConfig).toEqual(cameraConfig);
|
|
65
|
+
});
|
|
66
|
+
(0, globals_1.test)('defaults a missing drone capture config', () => {
|
|
67
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.parse({ cameraConfig: { aircraft: CAPTURE_CONFIG } }).cameraConfig).toEqual({
|
|
68
|
+
aircraft: CAPTURE_CONFIG,
|
|
69
|
+
drone: DEFAULT_CAPTURE_CONFIG,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
(0, globals_1.test)('copies the legacy flat capture config to both aircraft and drone', () => {
|
|
73
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.parse({ cameraConfig: CAPTURE_CONFIG }).cameraConfig).toEqual({
|
|
74
|
+
aircraft: CAPTURE_CONFIG,
|
|
75
|
+
drone: CAPTURE_CONFIG,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
(0, globals_1.test)('returns independent aircraft and drone objects', () => {
|
|
79
|
+
const legacy = PlaneTrackerAPI_1.cameraSettingsSchema.parse({ cameraConfig: CAPTURE_CONFIG }).cameraConfig;
|
|
80
|
+
legacy.drone.defaultCaptureSizeMeters = 1;
|
|
81
|
+
(0, globals_1.expect)(legacy.aircraft).toEqual(CAPTURE_CONFIG);
|
|
82
|
+
const first = PlaneTrackerAPI_1.cameraSettingsSchema.parse({}).cameraConfig;
|
|
83
|
+
first.drone.defaultCaptureSizeMeters = 1;
|
|
84
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.parse({}).cameraConfig.drone).toEqual(DEFAULT_CAPTURE_CONFIG);
|
|
85
|
+
});
|
|
86
|
+
(0, globals_1.test)('rejects a non-positive drone capture size', () => {
|
|
87
|
+
const cameraConfig = { aircraft: CAPTURE_CONFIG, drone: { ...CAPTURE_CONFIG, defaultCaptureSizeMeters: 0 } };
|
|
88
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.safeParse({ cameraConfig }).success).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
(0, globals_1.describe)('cameraSettingsSchema widget units', () => {
|
|
92
|
+
const WIDGET = { coord: 'top_left', posX: 10, posY: 10, scale: 100 };
|
|
93
|
+
(0, globals_1.test)('defaults all widget units to rotate', () => {
|
|
94
|
+
const settings = PlaneTrackerAPI_1.cameraSettingsSchema.parse({});
|
|
95
|
+
(0, globals_1.expect)(settings.widget.units).toBe('rotate');
|
|
96
|
+
(0, globals_1.expect)(settings.airportWidget.windSpeedUnits).toBe('rotate');
|
|
97
|
+
(0, globals_1.expect)(settings.airportWidget.temperatureUnits).toBe('rotate');
|
|
98
|
+
});
|
|
99
|
+
(0, globals_1.test)('defaults missing units of saved widgets to rotate', () => {
|
|
100
|
+
const settings = PlaneTrackerAPI_1.cameraSettingsSchema.parse({ widget: WIDGET, airportWidget: WIDGET });
|
|
101
|
+
(0, globals_1.expect)(settings.widget.units).toBe('rotate');
|
|
102
|
+
(0, globals_1.expect)(settings.airportWidget.windSpeedUnits).toBe('rotate');
|
|
103
|
+
(0, globals_1.expect)(settings.airportWidget.temperatureUnits).toBe('rotate');
|
|
104
|
+
});
|
|
105
|
+
(0, globals_1.test)('parses independent widget units', () => {
|
|
106
|
+
const settings = PlaneTrackerAPI_1.cameraSettingsSchema.parse({
|
|
107
|
+
widget: { ...WIDGET, units: 'imperial' },
|
|
108
|
+
airportWidget: { ...WIDGET, windSpeedUnits: 'rotate', temperatureUnits: 'metric' },
|
|
109
|
+
});
|
|
110
|
+
(0, globals_1.expect)(settings.widget.units).toBe('imperial');
|
|
111
|
+
(0, globals_1.expect)(settings.airportWidget.windSpeedUnits).toBe('rotate');
|
|
112
|
+
(0, globals_1.expect)(settings.airportWidget.temperatureUnits).toBe('metric');
|
|
113
|
+
});
|
|
114
|
+
(0, globals_1.test)('rejects an unknown widget unit', () => {
|
|
115
|
+
(0, globals_1.expect)(PlaneTrackerAPI_1.cameraSettingsSchema.safeParse({ widget: { ...WIDGET, units: 'kelvin' } }).success).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -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/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';
|
|
@@ -562,17 +562,21 @@ export class VapixAPI extends BasicAPI {
|
|
|
562
562
|
allowBooleanAttributes: true,
|
|
563
563
|
});
|
|
564
564
|
const result = parser.parse(xml);
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
|
|
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;
|
|
576
580
|
}
|
|
577
581
|
async startApplication(applicationId, options) {
|
|
578
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
|
+
});
|
|
@@ -25,6 +25,7 @@ export const widgetSchema = z.object({
|
|
|
25
25
|
posY: z.number().nonnegative(),
|
|
26
26
|
scale: z.number().positive(),
|
|
27
27
|
});
|
|
28
|
+
const widgetUnitsSchema = z.union([z.literal('metric'), z.literal('imperial'), z.literal('rotate')]);
|
|
28
29
|
const labelOptionsSchema = z.union([
|
|
29
30
|
z.literal('blank'),
|
|
30
31
|
z.literal('registration'),
|
|
@@ -32,13 +33,59 @@ const labelOptionsSchema = z.union([
|
|
|
32
33
|
z.literal('flight_number'),
|
|
33
34
|
z.literal('icao'),
|
|
34
35
|
]);
|
|
35
|
-
const
|
|
36
|
+
const aircraftIdentificationLabelSchema = z.object({
|
|
36
37
|
firstRow: labelOptionsSchema,
|
|
37
38
|
secondRow: labelOptionsSchema,
|
|
38
39
|
thirdRow: labelOptionsSchema,
|
|
39
40
|
fourthRow: labelOptionsSchema,
|
|
40
|
-
opacity: z.number().
|
|
41
|
+
opacity: z.number().nonnegative(),
|
|
41
42
|
});
|
|
43
|
+
const droneLabelOptionsSchema = z.union([z.literal('blank'), z.literal('remote_id')]);
|
|
44
|
+
const droneIdentificationLabelSchema = z.object({
|
|
45
|
+
firstRow: droneLabelOptionsSchema,
|
|
46
|
+
opacity: z.number().nonnegative(),
|
|
47
|
+
});
|
|
48
|
+
const DEFAULT_DRONE_IDENTIFICATION_LABEL = {
|
|
49
|
+
firstRow: 'remote_id',
|
|
50
|
+
opacity: 30,
|
|
51
|
+
};
|
|
52
|
+
const identificationLabelSchema = z.union([
|
|
53
|
+
z.object({
|
|
54
|
+
aircraft: aircraftIdentificationLabelSchema,
|
|
55
|
+
drone: droneIdentificationLabelSchema.default(DEFAULT_DRONE_IDENTIFICATION_LABEL),
|
|
56
|
+
}),
|
|
57
|
+
aircraftIdentificationLabelSchema.transform((aircraft) => ({
|
|
58
|
+
aircraft,
|
|
59
|
+
drone: { ...DEFAULT_DRONE_IDENTIFICATION_LABEL },
|
|
60
|
+
})),
|
|
61
|
+
]);
|
|
62
|
+
const captureConfigSchema = z.object({
|
|
63
|
+
defaultCaptureSizeMeters: z.number().positive(),
|
|
64
|
+
captureSizeExtensionMeters: z.number().positive(),
|
|
65
|
+
});
|
|
66
|
+
const DEFAULT_CAPTURE_CONFIG = {
|
|
67
|
+
defaultCaptureSizeMeters: 120,
|
|
68
|
+
captureSizeExtensionMeters: 80,
|
|
69
|
+
};
|
|
70
|
+
const cameraConfigSchema = z.union([
|
|
71
|
+
z.object({
|
|
72
|
+
aircraft: captureConfigSchema,
|
|
73
|
+
drone: captureConfigSchema.default(() => ({ ...DEFAULT_CAPTURE_CONFIG })),
|
|
74
|
+
}),
|
|
75
|
+
z
|
|
76
|
+
.object({
|
|
77
|
+
defaultCaptureSizeMeters: z.number().positive().default(DEFAULT_CAPTURE_CONFIG.defaultCaptureSizeMeters),
|
|
78
|
+
captureSizeExtensionMeters: z
|
|
79
|
+
.number()
|
|
80
|
+
.positive()
|
|
81
|
+
.default(DEFAULT_CAPTURE_CONFIG.captureSizeExtensionMeters),
|
|
82
|
+
})
|
|
83
|
+
.strict()
|
|
84
|
+
.transform((captureConfig) => ({
|
|
85
|
+
aircraft: captureConfig,
|
|
86
|
+
drone: { ...captureConfig },
|
|
87
|
+
})),
|
|
88
|
+
]);
|
|
42
89
|
export const cameraSettingsSchema = z.object({
|
|
43
90
|
units: z.union([z.literal('metric'), z.literal('imperial')]).default('imperial'),
|
|
44
91
|
adsbSource: z
|
|
@@ -76,15 +123,10 @@ export const cameraSettingsSchema = z.object({
|
|
|
76
123
|
nightSkyCalibrationFocusValue: 9000,
|
|
77
124
|
focusCalibrationPoints: '',
|
|
78
125
|
}),
|
|
79
|
-
cameraConfig:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
})
|
|
84
|
-
.default({
|
|
85
|
-
defaultCaptureSizeMeters: 120,
|
|
86
|
-
captureSizeExtensionMeters: 80,
|
|
87
|
-
}),
|
|
126
|
+
cameraConfig: cameraConfigSchema.default(() => ({
|
|
127
|
+
aircraft: { ...DEFAULT_CAPTURE_CONFIG },
|
|
128
|
+
drone: { ...DEFAULT_CAPTURE_CONFIG },
|
|
129
|
+
})),
|
|
88
130
|
stream: z
|
|
89
131
|
.object({
|
|
90
132
|
width: z.number().positive(),
|
|
@@ -145,18 +187,25 @@ export const cameraSettingsSchema = z.object({
|
|
|
145
187
|
displaySystemInfo: z.boolean().optional(),
|
|
146
188
|
})
|
|
147
189
|
.optional(),
|
|
148
|
-
widget: widgetSchema
|
|
190
|
+
widget: widgetSchema
|
|
191
|
+
.extend({
|
|
192
|
+
units: widgetUnitsSchema.default('rotate'),
|
|
193
|
+
})
|
|
194
|
+
.default({
|
|
149
195
|
enabled: true,
|
|
150
196
|
coord: 'top_right',
|
|
151
197
|
posX: 10,
|
|
152
198
|
posY: 10,
|
|
153
199
|
scale: 100,
|
|
200
|
+
units: 'rotate',
|
|
154
201
|
}),
|
|
155
202
|
airportWidget: widgetSchema
|
|
156
203
|
.extend({
|
|
157
204
|
showWeather: z.boolean().default(false),
|
|
158
205
|
weatherLocationKey: z.string().default(''),
|
|
159
206
|
weatherLocationName: z.string().default(''),
|
|
207
|
+
windSpeedUnits: widgetUnitsSchema.default('rotate'),
|
|
208
|
+
temperatureUnits: widgetUnitsSchema.default('rotate'),
|
|
160
209
|
})
|
|
161
210
|
.default({
|
|
162
211
|
enabled: true,
|
|
@@ -167,6 +216,8 @@ export const cameraSettingsSchema = z.object({
|
|
|
167
216
|
showWeather: false,
|
|
168
217
|
weatherLocationKey: '',
|
|
169
218
|
weatherLocationName: '',
|
|
219
|
+
windSpeedUnits: 'rotate',
|
|
220
|
+
temperatureUnits: 'rotate',
|
|
170
221
|
}),
|
|
171
222
|
fr24FlightInfoSource: z
|
|
172
223
|
.object({
|
|
@@ -195,11 +246,14 @@ export const cameraSettingsSchema = z.object({
|
|
|
195
246
|
port: 80,
|
|
196
247
|
}),
|
|
197
248
|
identificationLabel: identificationLabelSchema.default({
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
249
|
+
aircraft: {
|
|
250
|
+
firstRow: 'icao',
|
|
251
|
+
secondRow: 'call_sign',
|
|
252
|
+
thirdRow: 'blank',
|
|
253
|
+
fourthRow: 'blank',
|
|
254
|
+
opacity: 30,
|
|
255
|
+
},
|
|
256
|
+
drone: DEFAULT_DRONE_IDENTIFICATION_LABEL,
|
|
203
257
|
}),
|
|
204
258
|
acs: connectionSchema
|
|
205
259
|
.extend({
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
});
|
|
89
|
+
describe('cameraSettingsSchema widget units', () => {
|
|
90
|
+
const WIDGET = { coord: 'top_left', posX: 10, posY: 10, scale: 100 };
|
|
91
|
+
test('defaults all widget units to rotate', () => {
|
|
92
|
+
const settings = cameraSettingsSchema.parse({});
|
|
93
|
+
expect(settings.widget.units).toBe('rotate');
|
|
94
|
+
expect(settings.airportWidget.windSpeedUnits).toBe('rotate');
|
|
95
|
+
expect(settings.airportWidget.temperatureUnits).toBe('rotate');
|
|
96
|
+
});
|
|
97
|
+
test('defaults missing units of saved widgets to rotate', () => {
|
|
98
|
+
const settings = cameraSettingsSchema.parse({ widget: WIDGET, airportWidget: WIDGET });
|
|
99
|
+
expect(settings.widget.units).toBe('rotate');
|
|
100
|
+
expect(settings.airportWidget.windSpeedUnits).toBe('rotate');
|
|
101
|
+
expect(settings.airportWidget.temperatureUnits).toBe('rotate');
|
|
102
|
+
});
|
|
103
|
+
test('parses independent widget units', () => {
|
|
104
|
+
const settings = cameraSettingsSchema.parse({
|
|
105
|
+
widget: { ...WIDGET, units: 'imperial' },
|
|
106
|
+
airportWidget: { ...WIDGET, windSpeedUnits: 'rotate', temperatureUnits: 'metric' },
|
|
107
|
+
});
|
|
108
|
+
expect(settings.widget.units).toBe('imperial');
|
|
109
|
+
expect(settings.airportWidget.windSpeedUnits).toBe('rotate');
|
|
110
|
+
expect(settings.airportWidget.temperatureUnits).toBe('metric');
|
|
111
|
+
});
|
|
112
|
+
test('rejects an unknown widget unit', () => {
|
|
113
|
+
expect(cameraSettingsSchema.safeParse({ widget: { ...WIDGET, units: 'kelvin' } }).success).toBe(false);
|
|
114
|
+
});
|
|
115
|
+
});
|