camstreamerlib 4.0.35 → 4.0.36

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.
@@ -35,13 +35,59 @@ const labelOptionsSchema = zod_1.z.union([
35
35
  zod_1.z.literal('flight_number'),
36
36
  zod_1.z.literal('icao'),
37
37
  ]);
38
- const identificationLabelSchema = zod_1.z.object({
38
+ const aircraftIdentificationLabelSchema = zod_1.z.object({
39
39
  firstRow: labelOptionsSchema,
40
40
  secondRow: labelOptionsSchema,
41
41
  thirdRow: labelOptionsSchema,
42
42
  fourthRow: labelOptionsSchema,
43
- opacity: zod_1.z.number().positive(),
43
+ opacity: zod_1.z.number().nonnegative(),
44
44
  });
45
+ const droneLabelOptionsSchema = zod_1.z.union([zod_1.z.literal('blank'), zod_1.z.literal('remote_id')]);
46
+ const droneIdentificationLabelSchema = zod_1.z.object({
47
+ firstRow: droneLabelOptionsSchema,
48
+ opacity: zod_1.z.number().nonnegative(),
49
+ });
50
+ const DEFAULT_DRONE_IDENTIFICATION_LABEL = {
51
+ firstRow: 'remote_id',
52
+ opacity: 30,
53
+ };
54
+ const identificationLabelSchema = zod_1.z.union([
55
+ zod_1.z.object({
56
+ aircraft: aircraftIdentificationLabelSchema,
57
+ drone: droneIdentificationLabelSchema.default(DEFAULT_DRONE_IDENTIFICATION_LABEL),
58
+ }),
59
+ aircraftIdentificationLabelSchema.transform((aircraft) => ({
60
+ aircraft,
61
+ drone: { ...DEFAULT_DRONE_IDENTIFICATION_LABEL },
62
+ })),
63
+ ]);
64
+ const captureConfigSchema = zod_1.z.object({
65
+ defaultCaptureSizeMeters: zod_1.z.number().positive(),
66
+ captureSizeExtensionMeters: zod_1.z.number().positive(),
67
+ });
68
+ const DEFAULT_CAPTURE_CONFIG = {
69
+ defaultCaptureSizeMeters: 120,
70
+ captureSizeExtensionMeters: 80,
71
+ };
72
+ const cameraConfigSchema = zod_1.z.union([
73
+ zod_1.z.object({
74
+ aircraft: captureConfigSchema,
75
+ drone: captureConfigSchema.default(() => ({ ...DEFAULT_CAPTURE_CONFIG })),
76
+ }),
77
+ zod_1.z
78
+ .object({
79
+ defaultCaptureSizeMeters: zod_1.z.number().positive().default(DEFAULT_CAPTURE_CONFIG.defaultCaptureSizeMeters),
80
+ captureSizeExtensionMeters: zod_1.z
81
+ .number()
82
+ .positive()
83
+ .default(DEFAULT_CAPTURE_CONFIG.captureSizeExtensionMeters),
84
+ })
85
+ .strict()
86
+ .transform((captureConfig) => ({
87
+ aircraft: captureConfig,
88
+ drone: { ...captureConfig },
89
+ })),
90
+ ]);
45
91
  exports.cameraSettingsSchema = zod_1.z.object({
46
92
  units: zod_1.z.union([zod_1.z.literal('metric'), zod_1.z.literal('imperial')]).default('imperial'),
47
93
  adsbSource: zod_1.z
@@ -79,15 +125,10 @@ exports.cameraSettingsSchema = zod_1.z.object({
79
125
  nightSkyCalibrationFocusValue: 9000,
80
126
  focusCalibrationPoints: '',
81
127
  }),
82
- cameraConfig: zod_1.z
83
- .object({
84
- defaultCaptureSizeMeters: zod_1.z.number().positive().default(120),
85
- captureSizeExtensionMeters: zod_1.z.number().positive().default(80),
86
- })
87
- .default({
88
- defaultCaptureSizeMeters: 120,
89
- captureSizeExtensionMeters: 80,
90
- }),
128
+ cameraConfig: cameraConfigSchema.default(() => ({
129
+ aircraft: { ...DEFAULT_CAPTURE_CONFIG },
130
+ drone: { ...DEFAULT_CAPTURE_CONFIG },
131
+ })),
91
132
  stream: zod_1.z
92
133
  .object({
93
134
  width: zod_1.z.number().positive(),
@@ -198,11 +239,14 @@ exports.cameraSettingsSchema = zod_1.z.object({
198
239
  port: 80,
199
240
  }),
200
241
  identificationLabel: identificationLabelSchema.default({
201
- firstRow: 'registration',
202
- secondRow: 'blank',
203
- thirdRow: 'blank',
204
- fourthRow: 'blank',
205
- opacity: 30,
242
+ aircraft: {
243
+ firstRow: 'icao',
244
+ secondRow: 'call_sign',
245
+ thirdRow: 'blank',
246
+ fourthRow: 'blank',
247
+ opacity: 30,
248
+ },
249
+ drone: DEFAULT_DRONE_IDENTIFICATION_LABEL,
206
250
  }),
207
251
  acs: exports.connectionSchema
208
252
  .extend({
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,90 @@
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
+ });
@@ -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, applicationListSchema, sdCardInfoSchema, ALL_APP_IDS, allDateTimeInfoSchema, } from './types/VapixAPI';
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
- let apps = result.reply.application ?? [];
566
- if (!Array.isArray(apps)) {
567
- apps = [apps];
568
- }
569
- const appList = apps.map((app) => {
570
- return {
571
- ...app,
572
- appId: ALL_APP_IDS.find((id) => id.toLowerCase() === app.Name.toLowerCase()) ?? null,
573
- };
574
- });
575
- return applicationListSchema.parse(appList);
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
+ });
@@ -32,13 +32,59 @@ const labelOptionsSchema = z.union([
32
32
  z.literal('flight_number'),
33
33
  z.literal('icao'),
34
34
  ]);
35
- const identificationLabelSchema = z.object({
35
+ const aircraftIdentificationLabelSchema = z.object({
36
36
  firstRow: labelOptionsSchema,
37
37
  secondRow: labelOptionsSchema,
38
38
  thirdRow: labelOptionsSchema,
39
39
  fourthRow: labelOptionsSchema,
40
- opacity: z.number().positive(),
40
+ opacity: z.number().nonnegative(),
41
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(),
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
+ ]);
42
88
  export const cameraSettingsSchema = z.object({
43
89
  units: z.union([z.literal('metric'), z.literal('imperial')]).default('imperial'),
44
90
  adsbSource: z
@@ -76,15 +122,10 @@ export const cameraSettingsSchema = z.object({
76
122
  nightSkyCalibrationFocusValue: 9000,
77
123
  focusCalibrationPoints: '',
78
124
  }),
79
- cameraConfig: z
80
- .object({
81
- defaultCaptureSizeMeters: z.number().positive().default(120),
82
- captureSizeExtensionMeters: z.number().positive().default(80),
83
- })
84
- .default({
85
- defaultCaptureSizeMeters: 120,
86
- captureSizeExtensionMeters: 80,
87
- }),
125
+ cameraConfig: cameraConfigSchema.default(() => ({
126
+ aircraft: { ...DEFAULT_CAPTURE_CONFIG },
127
+ drone: { ...DEFAULT_CAPTURE_CONFIG },
128
+ })),
88
129
  stream: z
89
130
  .object({
90
131
  width: z.number().positive(),
@@ -195,11 +236,14 @@ export const cameraSettingsSchema = z.object({
195
236
  port: 80,
196
237
  }),
197
238
  identificationLabel: identificationLabelSchema.default({
198
- firstRow: 'registration',
199
- secondRow: 'blank',
200
- thirdRow: 'blank',
201
- fourthRow: 'blank',
202
- opacity: 30,
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,
203
247
  }),
204
248
  acs: connectionSchema
205
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camstreamerlib",
3
- "version": "4.0.35",
3
+ "version": "4.0.36",
4
4
  "description": "Helper library for CamStreamer ACAP applications.",
5
5
  "prettier": "@camstreamer/prettier-config",
6
6
  "engine": {