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.
@@ -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;
@@ -13,9 +13,11 @@ const constants_1 = require("./internal/constants");
13
13
  const baseUrl = '/local/camswitcher/api';
14
14
  class CamSwitcherAPI {
15
15
  client;
16
+ CustomFormData;
16
17
  vapixAgent;
17
- constructor(client) {
18
+ constructor(client, CustomFormData = FormData) {
18
19
  this.client = client;
20
+ this.CustomFormData = CustomFormData;
19
21
  this.vapixAgent = new VapixAPI_1.VapixAPI(client, () => '');
20
22
  }
21
23
  static getProxyUrlPath = () => `${baseUrl}/proxy.cgi`;
@@ -102,7 +104,7 @@ class CamSwitcherAPI {
102
104
  await this.get(`${baseUrl}/playlist_queue_play_next.cgi`);
103
105
  }
104
106
  async addNewClip(file, clipType, storage, id, fileName) {
105
- const formData = new FormData();
107
+ const formData = new this.CustomFormData();
106
108
  formData.append('clip_name', id);
107
109
  formData.append('clip_type', clipType);
108
110
  formData.append('file', file, fileName);
package/cjs/VapixAPI.js CHANGED
@@ -51,8 +51,8 @@ class VapixAPI {
51
51
  }
52
52
  async getSupportedAudioSampleRate(proxy = null) {
53
53
  const url = '/axis-cgi/audio/streamingcapabilities.cgi';
54
- const formData = { apiVersion: '1.0', method: 'list' };
55
- const res = await this.postJson(proxy, url, formData);
54
+ const jsonData = { apiVersion: '1.0', method: 'list' };
55
+ const res = await this.postJson(proxy, url, jsonData);
56
56
  const encoders = VapixAPI_1.audioSampleRatesResponseSchema.parse(await res.json()).data.encoders;
57
57
  const data = encoders.aac ?? encoders.AAC ?? [];
58
58
  return data.map((item) => {
@@ -78,7 +78,7 @@ class VapixAPI {
78
78
  await this.postJson(proxy, '/axis-cgi/opticscontrol.cgi', data);
79
79
  }
80
80
  catch (err) {
81
- await this.postJson(proxy, '/axis-cgi/opticssetup.cgi', {
81
+ await this.getUrlEncoded(proxy, '/axis-cgi/opticssetup.cgi', {
82
82
  autofocus: 'perform',
83
83
  source: '1',
84
84
  });
@@ -180,7 +180,7 @@ class VapixAPI {
180
180
  const data = { apiVersion: '1.0', method: 'getDevicesSettings' };
181
181
  const res = await this.postJson(proxy, '/axis-cgi/audiodevicecontrol.cgi', data);
182
182
  const result = VapixAPI_1.audioDeviceRequestSchema.parse(await res.json());
183
- return result.devices.map((device) => ({
183
+ return result.data.devices.map((device) => ({
184
184
  ...device,
185
185
  inputs: (device.inputs || []).sort((a, b) => a.id.localeCompare(b.id)),
186
186
  outputs: (device.outputs || []).sort((a, b) => a.id.localeCompare(b.id)),
@@ -292,14 +292,22 @@ class VapixAPI {
292
292
  query: 'presetposcamdata',
293
293
  format: 'json',
294
294
  });
295
- return parseCameraPtzResponse(await response.text())[camera] ?? [];
295
+ const text = await response.text();
296
+ if (text === '') {
297
+ throw new errors_1.PtzNotSupportedError();
298
+ }
299
+ return parseCameraPtzResponse(text)[camera] ?? [];
296
300
  }
297
301
  async listPtzVideoSourceOverview(proxy = null) {
298
302
  const response = await this.getUrlEncoded(proxy, '/axis-cgi/com/ptz.cgi', {
299
303
  query: 'presetposall',
300
304
  format: 'json',
301
305
  });
302
- const data = parseCameraPtzResponse(await response.text());
306
+ const text = await response.text();
307
+ if (text === '') {
308
+ throw new errors_1.PtzNotSupportedError();
309
+ }
310
+ const data = parseCameraPtzResponse(text);
303
311
  const res = {};
304
312
  Object.keys(data)
305
313
  .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 {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AddNewClipError = exports.FetchDeviceInfoError = exports.NoDeviceInfoError = exports.MaxFPSError = exports.SDCardJobError = exports.SDCardActionError = exports.ApplicationAPIError = exports.ParsingBlobError = exports.ServiceNotFoundError = exports.ServiceUnavailableError = void 0;
3
+ exports.PtzNotSupportedError = exports.AddNewClipError = exports.FetchDeviceInfoError = exports.NoDeviceInfoError = exports.MaxFPSError = exports.SDCardJobError = exports.SDCardActionError = exports.ApplicationAPIError = exports.ParsingBlobError = exports.ServiceNotFoundError = exports.ServiceUnavailableError = void 0;
4
4
  class ServiceUnavailableError extends Error {
5
5
  constructor() {
6
6
  super('Service is unavailable.');
@@ -77,3 +77,10 @@ class AddNewClipError extends Error {
77
77
  }
78
78
  }
79
79
  exports.AddNewClipError = AddNewClipError;
80
+ class PtzNotSupportedError extends Error {
81
+ constructor() {
82
+ super('Ptz not supported.');
83
+ this.name = 'PtzNotSupportedError';
84
+ }
85
+ }
86
+ exports.PtzNotSupportedError = PtzNotSupportedError;
@@ -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>;
@@ -19,6 +19,14 @@ const cswEventsDataSchema = zod_1.z.discriminatedUnion('type', [
19
19
  clip_name: zod_1.z.string().optional(),
20
20
  master_audio: zod_1.z.boolean(),
21
21
  }),
22
+ zod_1.z.object({
23
+ type: zod_1.z.literal('StreamSwitchVideoError'),
24
+ playlist_name: zod_1.z.string(),
25
+ playlist_active_stream: zod_1.z.number(),
26
+ stream_name: zod_1.z.string().optional(),
27
+ clip_name: zod_1.z.string().optional(),
28
+ info: zod_1.z.string(),
29
+ }),
22
30
  zod_1.z.object({
23
31
  type: zod_1.z.literal('StreamSwitchAudioError'),
24
32
  stream_name: zod_1.z.string().optional(),