camstreamerlib 4.0.0-beta.81 → 4.0.0-beta.82

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.
@@ -1,6 +1,6 @@
1
1
  import { ProxyClient } from './internal/ProxyClient';
2
2
  import { IClient, TResponse } from './internal/types';
3
- import { TStream, TStreamList } from './types/CamStreamerAPI/CamStreamerAPI';
3
+ import { TAudioFile, TAudioFileStorageType, TStream, TStreamList } from './types/CamStreamerAPI/CamStreamerAPI';
4
4
  import { THttpRequestOptions, TProxyParams } from './types/common';
5
5
  import { TOldStream, TOldStringStream } from './types/CamStreamerAPI/oldStreamSchema';
6
6
  export declare class CamStreamerAPI<Client extends IClient<TResponse, any>> {
@@ -133,7 +133,22 @@ export declare class CamStreamerAPI<Client extends IClient<TResponse, any>> {
133
133
  }>;
134
134
  setStream(streamId: number, streamData: Partial<TStream>, options?: THttpRequestOptions): Promise<void>;
135
135
  isStreaming(streamId: number, options?: THttpRequestOptions): Promise<boolean>;
136
+ listFiles(options?: THttpRequestOptions): Promise<{
137
+ path: string;
138
+ name: string;
139
+ storage: "url" | "flash" | "SD0";
140
+ }[]>;
141
+ uploadFile(formData: Parameters<Client['post']>[0]['data'], storage: TAudioFileStorageType, options?: THttpRequestOptions): Promise<void>;
142
+ removeFile(fileParams: TAudioFile, options?: THttpRequestOptions): Promise<void>;
143
+ getFileStorage(options?: THttpRequestOptions): Promise<({
144
+ type: "flash";
145
+ flash: string;
146
+ } | {
147
+ type: "SD0";
148
+ SD0: string;
149
+ })[]>;
136
150
  private _getJson;
137
151
  private _postJsonEncoded;
152
+ private _post;
138
153
  }
139
154
  export declare const parseCameraStreamResponse: (cameraStreamData: TOldStringStream) => TOldStream;
@@ -87,6 +87,26 @@ class CamStreamerAPI {
87
87
  const res = await this._getJson(`${BASE_PATH}/get_streamstat.cgi`, { stream_id: streamId }, options);
88
88
  return res.data.is_streaming === 1;
89
89
  }
90
+ async listFiles(options) {
91
+ const res = await this._getJson(`${BASE_PATH}/upload_audio.cgi`, { action: 'list' }, options);
92
+ return CamStreamerAPI_1.audioFileListSchema.parse(res.data);
93
+ }
94
+ async uploadFile(formData, storage, options) {
95
+ await this._post(`${BASE_PATH}/upload_audio.cgi`, formData, {
96
+ action: 'upload',
97
+ storage: storage,
98
+ }, options);
99
+ }
100
+ async removeFile(fileParams, options) {
101
+ await this._getJson(`${BASE_PATH}/upload_audio.cgi`, {
102
+ action: 'remove',
103
+ ...fileParams,
104
+ }, options);
105
+ }
106
+ async getFileStorage(options) {
107
+ const res = await this._getJson(`${BASE_PATH}/upload_audio.cgi`, { action: 'get_storage' }, options);
108
+ return CamStreamerAPI_1.storageListSchema.parse(res.data);
109
+ }
90
110
  async _getJson(path, parameters, options) {
91
111
  const agent = this.getClient(options?.proxyParams);
92
112
  const res = await agent.get({ path, parameters, timeout: options?.timeout });
@@ -108,6 +128,16 @@ class CamStreamerAPI {
108
128
  headers: { ...baseHeaders, ...headers },
109
129
  });
110
130
  }
131
+ async _post(path, data, parameters, options, headers) {
132
+ const agent = this.getClient(options?.proxyParams);
133
+ const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
134
+ if (res.ok) {
135
+ return await res.json();
136
+ }
137
+ else {
138
+ throw new errors_1.ErrorWithResponse(res);
139
+ }
140
+ }
111
141
  }
112
142
  exports.CamStreamerAPI = CamStreamerAPI;
113
143
  const parseCameraStreamResponse = (cameraStreamData) => {
@@ -575,3 +575,89 @@ export declare const isYouTubeStream: (stream: TStream) => stream is {
575
575
  active: boolean;
576
576
  title: string;
577
577
  };
578
+ export declare enum AudioType {
579
+ MP3 = 0,
580
+ AAC = 1
581
+ }
582
+ export declare const audioFileStorageTypeSchema: z.ZodUnion<[z.ZodLiteral<"flash">, z.ZodLiteral<"SD0">, z.ZodLiteral<"url">]>;
583
+ export type TAudioFileStorageType = z.infer<typeof audioFileStorageTypeSchema>;
584
+ export type TLocalStorageType = 'local' | 'url';
585
+ export declare const storageListSchema: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
586
+ type: z.ZodLiteral<"flash">;
587
+ flash: z.ZodString;
588
+ }, "strip", z.ZodTypeAny, {
589
+ type: "flash";
590
+ flash: string;
591
+ }, {
592
+ type: "flash";
593
+ flash: string;
594
+ }>, z.ZodObject<{
595
+ type: z.ZodLiteral<"SD0">;
596
+ SD0: z.ZodString;
597
+ }, "strip", z.ZodTypeAny, {
598
+ type: "SD0";
599
+ SD0: string;
600
+ }, {
601
+ type: "SD0";
602
+ SD0: string;
603
+ }>]>, "many">;
604
+ export type TStorageList = z.infer<typeof storageListSchema>;
605
+ export declare const audioFileSchema: z.ZodObject<{
606
+ name: z.ZodString;
607
+ path: z.ZodString;
608
+ storage: z.ZodUnion<[z.ZodLiteral<"flash">, z.ZodLiteral<"SD0">, z.ZodLiteral<"url">]>;
609
+ }, "strip", z.ZodTypeAny, {
610
+ path: string;
611
+ name: string;
612
+ storage: "url" | "flash" | "SD0";
613
+ }, {
614
+ path: string;
615
+ name: string;
616
+ storage: "url" | "flash" | "SD0";
617
+ }>;
618
+ export type TAudioFile = z.infer<typeof audioFileSchema>;
619
+ export declare const audioFileListSchema: z.ZodArray<z.ZodObject<{
620
+ name: z.ZodString;
621
+ path: z.ZodString;
622
+ storage: z.ZodUnion<[z.ZodLiteral<"flash">, z.ZodLiteral<"SD0">, z.ZodLiteral<"url">]>;
623
+ }, "strip", z.ZodTypeAny, {
624
+ path: string;
625
+ name: string;
626
+ storage: "url" | "flash" | "SD0";
627
+ }, {
628
+ path: string;
629
+ name: string;
630
+ storage: "url" | "flash" | "SD0";
631
+ }>, "many">;
632
+ export type TAudioFileList = z.infer<typeof audioFileListSchema>;
633
+ export declare const audioFileDataSchema: z.ZodObject<{
634
+ code: z.ZodNumber;
635
+ list: z.ZodArray<z.ZodObject<{
636
+ name: z.ZodString;
637
+ path: z.ZodString;
638
+ storage: z.ZodUnion<[z.ZodLiteral<"flash">, z.ZodLiteral<"SD0">, z.ZodLiteral<"url">]>;
639
+ }, "strip", z.ZodTypeAny, {
640
+ path: string;
641
+ name: string;
642
+ storage: "url" | "flash" | "SD0";
643
+ }, {
644
+ path: string;
645
+ name: string;
646
+ storage: "url" | "flash" | "SD0";
647
+ }>, "many">;
648
+ }, "strip", z.ZodTypeAny, {
649
+ code: number;
650
+ list: {
651
+ path: string;
652
+ name: string;
653
+ storage: "url" | "flash" | "SD0";
654
+ }[];
655
+ }, {
656
+ code: number;
657
+ list: {
658
+ path: string;
659
+ name: string;
660
+ storage: "url" | "flash" | "SD0";
661
+ }[];
662
+ }>;
663
+ export type TAudioFileData = z.infer<typeof audioFileDataSchema>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isYouTubeStream = exports.isWindyStream = exports.isSdCardStream = exports.isRtmpStream = exports.isMpegDvbStream = exports.isHlsStream = exports.isFacebookStream = exports.streamListSchema = exports.streamSchema = void 0;
3
+ exports.audioFileDataSchema = exports.audioFileListSchema = exports.audioFileSchema = exports.storageListSchema = exports.audioFileStorageTypeSchema = exports.AudioType = exports.isYouTubeStream = exports.isWindyStream = exports.isSdCardStream = exports.isRtmpStream = exports.isMpegDvbStream = exports.isHlsStream = exports.isFacebookStream = exports.streamListSchema = exports.streamSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const facebookSchema_1 = require("./facebookSchema");
6
6
  const hlsSchema_1 = require("./hlsSchema");
@@ -47,3 +47,29 @@ const isYouTubeStream = (stream) => {
47
47
  return stream.type === 'youtube';
48
48
  };
49
49
  exports.isYouTubeStream = isYouTubeStream;
50
+ var AudioType;
51
+ (function (AudioType) {
52
+ AudioType[AudioType["MP3"] = 0] = "MP3";
53
+ AudioType[AudioType["AAC"] = 1] = "AAC";
54
+ })(AudioType || (exports.AudioType = AudioType = {}));
55
+ exports.audioFileStorageTypeSchema = zod_1.z.union([zod_1.z.literal('flash'), zod_1.z.literal('SD0'), zod_1.z.literal('url')]);
56
+ exports.storageListSchema = zod_1.z.array(zod_1.z.discriminatedUnion('type', [
57
+ zod_1.z.object({
58
+ type: zod_1.z.literal('flash'),
59
+ flash: zod_1.z.string(),
60
+ }),
61
+ zod_1.z.object({
62
+ type: zod_1.z.literal('SD0'),
63
+ SD0: zod_1.z.string(),
64
+ }),
65
+ ]));
66
+ exports.audioFileSchema = zod_1.z.object({
67
+ name: zod_1.z.string(),
68
+ path: zod_1.z.string(),
69
+ storage: exports.audioFileStorageTypeSchema,
70
+ });
71
+ exports.audioFileListSchema = zod_1.z.array(exports.audioFileSchema);
72
+ exports.audioFileDataSchema = zod_1.z.object({
73
+ code: zod_1.z.number(),
74
+ list: exports.audioFileListSchema,
75
+ });
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { ProxyClient } from './internal/ProxyClient';
3
- import { streamSchema } from './types/CamStreamerAPI/CamStreamerAPI';
3
+ import { audioFileListSchema, storageListSchema, streamSchema, } from './types/CamStreamerAPI/CamStreamerAPI';
4
4
  import { ErrorWithResponse, UtcTimeFetchError, WsAuthorizationError, MigrationError } from './errors/errors';
5
5
  import { oldStringStreamSchema, oldStringStreamSchemaWithId, } from './types/CamStreamerAPI/oldStreamSchema';
6
6
  const BASE_PATH = '/local/camstreamer';
@@ -84,6 +84,26 @@ export class CamStreamerAPI {
84
84
  const res = await this._getJson(`${BASE_PATH}/get_streamstat.cgi`, { stream_id: streamId }, options);
85
85
  return res.data.is_streaming === 1;
86
86
  }
87
+ async listFiles(options) {
88
+ const res = await this._getJson(`${BASE_PATH}/upload_audio.cgi`, { action: 'list' }, options);
89
+ return audioFileListSchema.parse(res.data);
90
+ }
91
+ async uploadFile(formData, storage, options) {
92
+ await this._post(`${BASE_PATH}/upload_audio.cgi`, formData, {
93
+ action: 'upload',
94
+ storage: storage,
95
+ }, options);
96
+ }
97
+ async removeFile(fileParams, options) {
98
+ await this._getJson(`${BASE_PATH}/upload_audio.cgi`, {
99
+ action: 'remove',
100
+ ...fileParams,
101
+ }, options);
102
+ }
103
+ async getFileStorage(options) {
104
+ const res = await this._getJson(`${BASE_PATH}/upload_audio.cgi`, { action: 'get_storage' }, options);
105
+ return storageListSchema.parse(res.data);
106
+ }
87
107
  async _getJson(path, parameters, options) {
88
108
  const agent = this.getClient(options?.proxyParams);
89
109
  const res = await agent.get({ path, parameters, timeout: options?.timeout });
@@ -105,6 +125,16 @@ export class CamStreamerAPI {
105
125
  headers: { ...baseHeaders, ...headers },
106
126
  });
107
127
  }
128
+ async _post(path, data, parameters, options, headers) {
129
+ const agent = this.getClient(options?.proxyParams);
130
+ const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
131
+ if (res.ok) {
132
+ return await res.json();
133
+ }
134
+ else {
135
+ throw new ErrorWithResponse(res);
136
+ }
137
+ }
108
138
  }
109
139
  export const parseCameraStreamResponse = (cameraStreamData) => {
110
140
  return {
@@ -37,3 +37,29 @@ export const isWindyStream = (stream) => {
37
37
  export const isYouTubeStream = (stream) => {
38
38
  return stream.type === 'youtube';
39
39
  };
40
+ export var AudioType;
41
+ (function (AudioType) {
42
+ AudioType[AudioType["MP3"] = 0] = "MP3";
43
+ AudioType[AudioType["AAC"] = 1] = "AAC";
44
+ })(AudioType || (AudioType = {}));
45
+ export const audioFileStorageTypeSchema = z.union([z.literal('flash'), z.literal('SD0'), z.literal('url')]);
46
+ export const storageListSchema = z.array(z.discriminatedUnion('type', [
47
+ z.object({
48
+ type: z.literal('flash'),
49
+ flash: z.string(),
50
+ }),
51
+ z.object({
52
+ type: z.literal('SD0'),
53
+ SD0: z.string(),
54
+ }),
55
+ ]));
56
+ export const audioFileSchema = z.object({
57
+ name: z.string(),
58
+ path: z.string(),
59
+ storage: audioFileStorageTypeSchema,
60
+ });
61
+ export const audioFileListSchema = z.array(audioFileSchema);
62
+ export const audioFileDataSchema = z.object({
63
+ code: z.number(),
64
+ list: audioFileListSchema,
65
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camstreamerlib",
3
- "version": "4.0.0-beta.81",
3
+ "version": "4.0.0-beta.82",
4
4
  "description": "Helper library for CamStreamer ACAP applications.",
5
5
  "prettier": "@camstreamer/prettier-config",
6
6
  "engine": {
@@ -1,6 +1,6 @@
1
1
  import { ProxyClient } from './internal/ProxyClient';
2
2
  import { IClient, TResponse } from './internal/types';
3
- import { TStream, TStreamList } from './types/CamStreamerAPI/CamStreamerAPI';
3
+ import { TAudioFile, TAudioFileStorageType, TStream, TStreamList } from './types/CamStreamerAPI/CamStreamerAPI';
4
4
  import { THttpRequestOptions, TProxyParams } from './types/common';
5
5
  import { TOldStream, TOldStringStream } from './types/CamStreamerAPI/oldStreamSchema';
6
6
  export declare class CamStreamerAPI<Client extends IClient<TResponse, any>> {
@@ -133,7 +133,22 @@ export declare class CamStreamerAPI<Client extends IClient<TResponse, any>> {
133
133
  }>;
134
134
  setStream(streamId: number, streamData: Partial<TStream>, options?: THttpRequestOptions): Promise<void>;
135
135
  isStreaming(streamId: number, options?: THttpRequestOptions): Promise<boolean>;
136
+ listFiles(options?: THttpRequestOptions): Promise<{
137
+ path: string;
138
+ name: string;
139
+ storage: "url" | "flash" | "SD0";
140
+ }[]>;
141
+ uploadFile(formData: Parameters<Client['post']>[0]['data'], storage: TAudioFileStorageType, options?: THttpRequestOptions): Promise<void>;
142
+ removeFile(fileParams: TAudioFile, options?: THttpRequestOptions): Promise<void>;
143
+ getFileStorage(options?: THttpRequestOptions): Promise<({
144
+ type: "flash";
145
+ flash: string;
146
+ } | {
147
+ type: "SD0";
148
+ SD0: string;
149
+ })[]>;
136
150
  private _getJson;
137
151
  private _postJsonEncoded;
152
+ private _post;
138
153
  }
139
154
  export declare const parseCameraStreamResponse: (cameraStreamData: TOldStringStream) => TOldStream;
@@ -575,3 +575,89 @@ export declare const isYouTubeStream: (stream: TStream) => stream is {
575
575
  active: boolean;
576
576
  title: string;
577
577
  };
578
+ export declare enum AudioType {
579
+ MP3 = 0,
580
+ AAC = 1
581
+ }
582
+ export declare const audioFileStorageTypeSchema: z.ZodUnion<[z.ZodLiteral<"flash">, z.ZodLiteral<"SD0">, z.ZodLiteral<"url">]>;
583
+ export type TAudioFileStorageType = z.infer<typeof audioFileStorageTypeSchema>;
584
+ export type TLocalStorageType = 'local' | 'url';
585
+ export declare const storageListSchema: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
586
+ type: z.ZodLiteral<"flash">;
587
+ flash: z.ZodString;
588
+ }, "strip", z.ZodTypeAny, {
589
+ type: "flash";
590
+ flash: string;
591
+ }, {
592
+ type: "flash";
593
+ flash: string;
594
+ }>, z.ZodObject<{
595
+ type: z.ZodLiteral<"SD0">;
596
+ SD0: z.ZodString;
597
+ }, "strip", z.ZodTypeAny, {
598
+ type: "SD0";
599
+ SD0: string;
600
+ }, {
601
+ type: "SD0";
602
+ SD0: string;
603
+ }>]>, "many">;
604
+ export type TStorageList = z.infer<typeof storageListSchema>;
605
+ export declare const audioFileSchema: z.ZodObject<{
606
+ name: z.ZodString;
607
+ path: z.ZodString;
608
+ storage: z.ZodUnion<[z.ZodLiteral<"flash">, z.ZodLiteral<"SD0">, z.ZodLiteral<"url">]>;
609
+ }, "strip", z.ZodTypeAny, {
610
+ path: string;
611
+ name: string;
612
+ storage: "url" | "flash" | "SD0";
613
+ }, {
614
+ path: string;
615
+ name: string;
616
+ storage: "url" | "flash" | "SD0";
617
+ }>;
618
+ export type TAudioFile = z.infer<typeof audioFileSchema>;
619
+ export declare const audioFileListSchema: z.ZodArray<z.ZodObject<{
620
+ name: z.ZodString;
621
+ path: z.ZodString;
622
+ storage: z.ZodUnion<[z.ZodLiteral<"flash">, z.ZodLiteral<"SD0">, z.ZodLiteral<"url">]>;
623
+ }, "strip", z.ZodTypeAny, {
624
+ path: string;
625
+ name: string;
626
+ storage: "url" | "flash" | "SD0";
627
+ }, {
628
+ path: string;
629
+ name: string;
630
+ storage: "url" | "flash" | "SD0";
631
+ }>, "many">;
632
+ export type TAudioFileList = z.infer<typeof audioFileListSchema>;
633
+ export declare const audioFileDataSchema: z.ZodObject<{
634
+ code: z.ZodNumber;
635
+ list: z.ZodArray<z.ZodObject<{
636
+ name: z.ZodString;
637
+ path: z.ZodString;
638
+ storage: z.ZodUnion<[z.ZodLiteral<"flash">, z.ZodLiteral<"SD0">, z.ZodLiteral<"url">]>;
639
+ }, "strip", z.ZodTypeAny, {
640
+ path: string;
641
+ name: string;
642
+ storage: "url" | "flash" | "SD0";
643
+ }, {
644
+ path: string;
645
+ name: string;
646
+ storage: "url" | "flash" | "SD0";
647
+ }>, "many">;
648
+ }, "strip", z.ZodTypeAny, {
649
+ code: number;
650
+ list: {
651
+ path: string;
652
+ name: string;
653
+ storage: "url" | "flash" | "SD0";
654
+ }[];
655
+ }, {
656
+ code: number;
657
+ list: {
658
+ path: string;
659
+ name: string;
660
+ storage: "url" | "flash" | "SD0";
661
+ }[];
662
+ }>;
663
+ export type TAudioFileData = z.infer<typeof audioFileDataSchema>;