camstreamerlib 4.0.0-beta.6 → 4.0.0-beta.8

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.
@@ -22,6 +22,7 @@ exports.APP_IDS = [
22
22
  'CamScripter',
23
23
  'PlaneTracker',
24
24
  'Ndihxplugin',
25
+ 'SportTracker',
25
26
  ];
26
27
  exports.applicationListSchema = zod_1.z.object({
27
28
  reply: zod_1.z.object({
@@ -70,7 +71,7 @@ exports.audioDeviceSignalingChannelTypeSchema = zod_1.z.object({
70
71
  });
71
72
  exports.audioDeviceSignalingTypeSchema = zod_1.z.object({
72
73
  id: zod_1.z.string(),
73
- powerType: zod_1.z.string(),
74
+ powerType: zod_1.z.string().optional(),
74
75
  channels: zod_1.z.array(exports.audioDeviceSignalingChannelTypeSchema),
75
76
  });
76
77
  exports.audioDeviceConnectionTypeSchema = zod_1.z.object({
@@ -97,7 +98,9 @@ const audioDeviceFromRequestSchema = zod_1.z.object({
97
98
  inputs: zod_1.z.array(exports.audioDeviceInputOutputSchema).optional(),
98
99
  outputs: zod_1.z.array(exports.audioDeviceInputOutputSchema).optional(),
99
100
  });
100
- exports.audioDeviceRequestSchema = zod_1.z.object({ devices: zod_1.z.array(audioDeviceFromRequestSchema) });
101
+ exports.audioDeviceRequestSchema = zod_1.z.object({
102
+ data: zod_1.z.object({ devices: zod_1.z.array(audioDeviceFromRequestSchema) }),
103
+ });
101
104
  exports.maxFpsResponseSchema = zod_1.z.object({
102
105
  data: zod_1.z
103
106
  .array(zod_1.z.object({
@@ -3,8 +3,12 @@ import { TAudioPushInfo, TOutputInfo, TStorageInfo, TStreamSaveList, TClipList,
3
3
  import { TAudioChannel, TNetworkCamera, TStorageType } from './types/common';
4
4
  export declare class CamSwitcherAPI<Client extends IClient = IClient> {
5
5
  client: Client;
6
+ private CustomFormData;
6
7
  private vapixAgent;
7
- constructor(client: Client);
8
+ constructor(client: Client, CustomFormData?: {
9
+ new (form?: HTMLFormElement | undefined, submitter?: HTMLElement | null | undefined): FormData;
10
+ prototype: FormData;
11
+ });
8
12
  static getProxyUrlPath: () => string;
9
13
  static getWsEventsUrlPath: () => string;
10
14
  static getClipPreviewUrlPath: (id: string, storage: TStorageType) => string;
@@ -10,9 +10,11 @@ import { FIRMWARE_WITH_BITRATE_MODES_SUPPORT } from './internal/constants';
10
10
  const baseUrl = '/local/camswitcher/api';
11
11
  export class CamSwitcherAPI {
12
12
  client;
13
+ CustomFormData;
13
14
  vapixAgent;
14
- constructor(client) {
15
+ constructor(client, CustomFormData = FormData) {
15
16
  this.client = client;
17
+ this.CustomFormData = CustomFormData;
16
18
  this.vapixAgent = new VapixAPI(client, () => '');
17
19
  }
18
20
  static getProxyUrlPath = () => `${baseUrl}/proxy.cgi`;
@@ -99,7 +101,7 @@ export class CamSwitcherAPI {
99
101
  await this.get(`${baseUrl}/playlist_queue_play_next.cgi`);
100
102
  }
101
103
  async addNewClip(file, clipType, storage, id, fileName) {
102
- const formData = new FormData();
104
+ const formData = new this.CustomFormData();
103
105
  formData.append('clip_name', id);
104
106
  formData.append('clip_type', clipType);
105
107
  formData.append('file', file, fileName);
package/esm/VapixAPI.js CHANGED
@@ -2,7 +2,7 @@ import * as prettifyXml from 'prettify-xml';
2
2
  import { parseStringPromise } from 'xml2js';
3
3
  import { isNullish, responseStringify } from './internal/common';
4
4
  import { sdCardWatchedStatuses, APP_IDS, maxFpsResponseSchema, dateTimeinfoSchema, audioDeviceRequestSchema, audioSampleRatesResponseSchema, } from './types/VapixAPI';
5
- import { ApplicationAPIError, MaxFPSError, NoDeviceInfoError, SDCardActionError, SDCardJobError, } from './errors/errors';
5
+ import { ApplicationAPIError, MaxFPSError, NoDeviceInfoError, PtzNotSupportedError, SDCardActionError, SDCardJobError, } from './errors/errors';
6
6
  import { ProxyClient } from './internal/ProxyClient';
7
7
  import { arrayToUrl, paramToUrl } from './internal/utils';
8
8
  import { z } from 'zod';
@@ -48,8 +48,8 @@ export class VapixAPI {
48
48
  }
49
49
  async getSupportedAudioSampleRate(proxy = null) {
50
50
  const url = '/axis-cgi/audio/streamingcapabilities.cgi';
51
- const formData = { apiVersion: '1.0', method: 'list' };
52
- const res = await this.postJson(proxy, url, formData);
51
+ const jsonData = { apiVersion: '1.0', method: 'list' };
52
+ const res = await this.postJson(proxy, url, jsonData);
53
53
  const encoders = audioSampleRatesResponseSchema.parse(await res.json()).data.encoders;
54
54
  const data = encoders.aac ?? encoders.AAC ?? [];
55
55
  return data.map((item) => {
@@ -75,7 +75,7 @@ export class VapixAPI {
75
75
  await this.postJson(proxy, '/axis-cgi/opticscontrol.cgi', data);
76
76
  }
77
77
  catch (err) {
78
- await this.postJson(proxy, '/axis-cgi/opticssetup.cgi', {
78
+ await this.getUrlEncoded(proxy, '/axis-cgi/opticssetup.cgi', {
79
79
  autofocus: 'perform',
80
80
  source: '1',
81
81
  });
@@ -177,7 +177,7 @@ export class VapixAPI {
177
177
  const data = { apiVersion: '1.0', method: 'getDevicesSettings' };
178
178
  const res = await this.postJson(proxy, '/axis-cgi/audiodevicecontrol.cgi', data);
179
179
  const result = audioDeviceRequestSchema.parse(await res.json());
180
- return result.devices.map((device) => ({
180
+ return result.data.devices.map((device) => ({
181
181
  ...device,
182
182
  inputs: (device.inputs || []).sort((a, b) => a.id.localeCompare(b.id)),
183
183
  outputs: (device.outputs || []).sort((a, b) => a.id.localeCompare(b.id)),
@@ -289,14 +289,22 @@ export class VapixAPI {
289
289
  query: 'presetposcamdata',
290
290
  format: 'json',
291
291
  });
292
- return parseCameraPtzResponse(await response.text())[camera] ?? [];
292
+ const text = await response.text();
293
+ if (text === '') {
294
+ throw new PtzNotSupportedError();
295
+ }
296
+ return parseCameraPtzResponse(text)[camera] ?? [];
293
297
  }
294
298
  async listPtzVideoSourceOverview(proxy = null) {
295
299
  const response = await this.getUrlEncoded(proxy, '/axis-cgi/com/ptz.cgi', {
296
300
  query: 'presetposall',
297
301
  format: 'json',
298
302
  });
299
- const data = parseCameraPtzResponse(await response.text());
303
+ const text = await response.text();
304
+ if (text === '') {
305
+ throw new PtzNotSupportedError();
306
+ }
307
+ const data = parseCameraPtzResponse(text);
300
308
  const res = {};
301
309
  Object.keys(data)
302
310
  .map(Number)
@@ -31,4 +31,7 @@ export declare class FetchDeviceInfoError extends Error {
31
31
  export declare class AddNewClipError extends Error {
32
32
  constructor(message: string);
33
33
  }
34
+ export declare class PtzNotSupportedError extends Error {
35
+ constructor();
36
+ }
34
37
  export {};
@@ -64,3 +64,9 @@ export class AddNewClipError extends Error {
64
64
  this.name = 'AddNewClipError';
65
65
  }
66
66
  }
67
+ export class PtzNotSupportedError extends Error {
68
+ constructor() {
69
+ super('Ptz not supported.');
70
+ this.name = 'PtzNotSupportedError';
71
+ }
72
+ }
@@ -44,6 +44,27 @@ declare const cswEventsDataSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
44
44
  master_audio: boolean;
45
45
  stream_name?: string | undefined;
46
46
  clip_name?: string | undefined;
47
+ }>, z.ZodObject<{
48
+ type: z.ZodLiteral<"StreamSwitchVideoError">;
49
+ playlist_name: z.ZodString;
50
+ playlist_active_stream: z.ZodNumber;
51
+ stream_name: z.ZodOptional<z.ZodString>;
52
+ clip_name: z.ZodOptional<z.ZodString>;
53
+ info: z.ZodString;
54
+ }, "strip", z.ZodTypeAny, {
55
+ type: "StreamSwitchVideoError";
56
+ playlist_name: string;
57
+ playlist_active_stream: number;
58
+ info: string;
59
+ stream_name?: string | undefined;
60
+ clip_name?: string | undefined;
61
+ }, {
62
+ type: "StreamSwitchVideoError";
63
+ playlist_name: string;
64
+ playlist_active_stream: number;
65
+ info: string;
66
+ stream_name?: string | undefined;
67
+ clip_name?: string | undefined;
47
68
  }>, z.ZodObject<{
48
69
  type: z.ZodLiteral<"StreamSwitchAudioError">;
49
70
  stream_name: z.ZodOptional<z.ZodString>;
@@ -176,6 +197,27 @@ export declare const cswEventsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObje
176
197
  master_audio: boolean;
177
198
  stream_name?: string | undefined;
178
199
  clip_name?: string | undefined;
200
+ }>, z.ZodObject<{
201
+ type: z.ZodLiteral<"StreamSwitchVideoError">;
202
+ playlist_name: z.ZodString;
203
+ playlist_active_stream: z.ZodNumber;
204
+ stream_name: z.ZodOptional<z.ZodString>;
205
+ clip_name: z.ZodOptional<z.ZodString>;
206
+ info: z.ZodString;
207
+ }, "strip", z.ZodTypeAny, {
208
+ type: "StreamSwitchVideoError";
209
+ playlist_name: string;
210
+ playlist_active_stream: number;
211
+ info: string;
212
+ stream_name?: string | undefined;
213
+ clip_name?: string | undefined;
214
+ }, {
215
+ type: "StreamSwitchVideoError";
216
+ playlist_name: string;
217
+ playlist_active_stream: number;
218
+ info: string;
219
+ stream_name?: string | undefined;
220
+ clip_name?: string | undefined;
179
221
  }>, z.ZodObject<{
180
222
  type: z.ZodLiteral<"StreamSwitchAudioError">;
181
223
  stream_name: z.ZodOptional<z.ZodString>;
@@ -278,6 +320,13 @@ export declare const cswEventsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObje
278
320
  master_audio: boolean;
279
321
  stream_name?: string | undefined;
280
322
  clip_name?: string | undefined;
323
+ } | {
324
+ type: "StreamSwitchVideoError";
325
+ playlist_name: string;
326
+ playlist_active_stream: number;
327
+ info: string;
328
+ stream_name?: string | undefined;
329
+ clip_name?: string | undefined;
281
330
  } | {
282
331
  type: "StreamSwitchAudioError";
283
332
  master_audio: boolean;
@@ -324,6 +373,13 @@ export declare const cswEventsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObje
324
373
  master_audio: boolean;
325
374
  stream_name?: string | undefined;
326
375
  clip_name?: string | undefined;
376
+ } | {
377
+ type: "StreamSwitchVideoError";
378
+ playlist_name: string;
379
+ playlist_active_stream: number;
380
+ info: string;
381
+ stream_name?: string | undefined;
382
+ clip_name?: string | undefined;
327
383
  } | {
328
384
  type: "StreamSwitchAudioError";
329
385
  master_audio: boolean;
@@ -398,6 +454,27 @@ export declare const cswEventsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObje
398
454
  master_audio: boolean;
399
455
  stream_name?: string | undefined;
400
456
  clip_name?: string | undefined;
457
+ }>, z.ZodObject<{
458
+ type: z.ZodLiteral<"StreamSwitchVideoError">;
459
+ playlist_name: z.ZodString;
460
+ playlist_active_stream: z.ZodNumber;
461
+ stream_name: z.ZodOptional<z.ZodString>;
462
+ clip_name: z.ZodOptional<z.ZodString>;
463
+ info: z.ZodString;
464
+ }, "strip", z.ZodTypeAny, {
465
+ type: "StreamSwitchVideoError";
466
+ playlist_name: string;
467
+ playlist_active_stream: number;
468
+ info: string;
469
+ stream_name?: string | undefined;
470
+ clip_name?: string | undefined;
471
+ }, {
472
+ type: "StreamSwitchVideoError";
473
+ playlist_name: string;
474
+ playlist_active_stream: number;
475
+ info: string;
476
+ stream_name?: string | undefined;
477
+ clip_name?: string | undefined;
401
478
  }>, z.ZodObject<{
402
479
  type: z.ZodLiteral<"StreamSwitchAudioError">;
403
480
  stream_name: z.ZodOptional<z.ZodString>;
@@ -16,6 +16,14 @@ const cswEventsDataSchema = z.discriminatedUnion('type', [
16
16
  clip_name: z.string().optional(),
17
17
  master_audio: z.boolean(),
18
18
  }),
19
+ z.object({
20
+ type: z.literal('StreamSwitchVideoError'),
21
+ playlist_name: z.string(),
22
+ playlist_active_stream: z.number(),
23
+ stream_name: z.string().optional(),
24
+ clip_name: z.string().optional(),
25
+ info: z.string(),
26
+ }),
19
27
  z.object({
20
28
  type: z.literal('StreamSwitchAudioError'),
21
29
  stream_name: z.string().optional(),