camstreamerlib 4.0.0-beta.80 → 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.
Files changed (33) hide show
  1. package/cjs/CamStreamerAPI.d.ts +85 -3
  2. package/cjs/CamStreamerAPI.js +82 -35
  3. package/cjs/errors/errors.d.ts +7 -3
  4. package/cjs/types/CamStreamerAPI/CamStreamerAPI.d.ts +424 -0
  5. package/cjs/types/CamStreamerAPI/CamStreamerAPI.js +28 -1
  6. package/cjs/types/CamStreamerAPI/facebookSchema.d.ts +3 -0
  7. package/cjs/types/CamStreamerAPI/hlsSchema.d.ts +3 -0
  8. package/cjs/types/CamStreamerAPI/mpegDvbSchema.d.ts +3 -0
  9. package/cjs/types/CamStreamerAPI/oldStreamSchema.d.ts +71 -0
  10. package/cjs/types/CamStreamerAPI/oldStreamSchema.js +4 -1
  11. package/cjs/types/CamStreamerAPI/rtmpSchema.d.ts +3 -0
  12. package/cjs/types/CamStreamerAPI/sdCardSchema.d.ts +3 -0
  13. package/cjs/types/CamStreamerAPI/streamCommonTypes.d.ts +3 -0
  14. package/cjs/types/CamStreamerAPI/streamCommonTypes.js +1 -0
  15. package/cjs/types/CamStreamerAPI/windySchema.d.ts +3 -0
  16. package/cjs/types/CamStreamerAPI/youtubeSchema.d.ts +3 -0
  17. package/esm/CamStreamerAPI.js +84 -37
  18. package/esm/types/CamStreamerAPI/CamStreamerAPI.js +27 -0
  19. package/esm/types/CamStreamerAPI/oldStreamSchema.js +3 -0
  20. package/esm/types/CamStreamerAPI/streamCommonTypes.js +1 -0
  21. package/package.json +1 -1
  22. package/types/CamStreamerAPI.d.ts +85 -3
  23. package/types/errors/errors.d.ts +7 -3
  24. package/types/types/CamStreamerAPI/CamStreamerAPI.d.ts +424 -0
  25. package/types/types/CamStreamerAPI/facebookSchema.d.ts +3 -0
  26. package/types/types/CamStreamerAPI/hlsSchema.d.ts +3 -0
  27. package/types/types/CamStreamerAPI/mpegDvbSchema.d.ts +3 -0
  28. package/types/types/CamStreamerAPI/oldStreamSchema.d.ts +71 -0
  29. package/types/types/CamStreamerAPI/rtmpSchema.d.ts +3 -0
  30. package/types/types/CamStreamerAPI/sdCardSchema.d.ts +3 -0
  31. package/types/types/CamStreamerAPI/streamCommonTypes.d.ts +3 -0
  32. package/types/types/CamStreamerAPI/windySchema.d.ts +3 -0
  33. package/types/types/CamStreamerAPI/youtubeSchema.d.ts +3 -0
@@ -1,6 +1,6 @@
1
1
  import { ProxyClient } from './internal/ProxyClient';
2
2
  import { IClient, TResponse } from './internal/types';
3
- import { TStream } 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>> {
@@ -10,21 +10,84 @@ export declare class CamStreamerAPI<Client extends IClient<TResponse, any>> {
10
10
  getClient(proxyParams?: TProxyParams): Client | ProxyClient<Client>;
11
11
  wsAuthorization(options?: THttpRequestOptions): Promise<string>;
12
12
  getUtcTime(options?: THttpRequestOptions): Promise<number>;
13
- getStreamList(options?: THttpRequestOptions): Promise<Record<number, TStream>>;
13
+ getStreamList(options?: THttpRequestOptions): Promise<({
14
+ type: "facebook";
15
+ enabled: boolean;
16
+ id: number;
17
+ active: boolean;
18
+ title: string;
19
+ } | {
20
+ type: "hls";
21
+ enabled: boolean;
22
+ id: number;
23
+ active: boolean;
24
+ title: string;
25
+ } | {
26
+ type: "mpeg_dvb";
27
+ port: number;
28
+ enabled: boolean;
29
+ id: number;
30
+ active: boolean;
31
+ title: string;
32
+ ipAddress: string;
33
+ standard: "DVB" | "ATSC";
34
+ nullPacketsPaddingEnabled: boolean;
35
+ nullPacketsPaddingKbps: number;
36
+ videoPid: number;
37
+ audioPid: number;
38
+ mpegtsStreamId: number;
39
+ pmtPid: number;
40
+ pcrPid: number;
41
+ pcrPeriodMs: number;
42
+ providerName: string;
43
+ serviceName: string;
44
+ triggerType: "manual" | "onetime" | "recurrent" | "io" | "nonstop";
45
+ statusCameraLed: boolean;
46
+ statusCameraOutput: string;
47
+ saveToSdCard: boolean;
48
+ } | {
49
+ type: "rtmp";
50
+ enabled: boolean;
51
+ id: number;
52
+ active: boolean;
53
+ title: string;
54
+ } | {
55
+ type: "sd_card";
56
+ enabled: boolean;
57
+ id: number;
58
+ active: boolean;
59
+ title: string;
60
+ } | {
61
+ type: "windy";
62
+ enabled: boolean;
63
+ id: number;
64
+ active: boolean;
65
+ title: string;
66
+ } | {
67
+ type: "youtube";
68
+ enabled: boolean;
69
+ id: number;
70
+ active: boolean;
71
+ title: string;
72
+ })[]>;
73
+ setStreamList(streamList: TStreamList['streamList'], options?: THttpRequestOptions): Promise<void>;
14
74
  getStream(streamId: number, options?: THttpRequestOptions): Promise<{
15
75
  type: "facebook";
16
76
  enabled: boolean;
77
+ id: number;
17
78
  active: boolean;
18
79
  title: string;
19
80
  } | {
20
81
  type: "hls";
21
82
  enabled: boolean;
83
+ id: number;
22
84
  active: boolean;
23
85
  title: string;
24
86
  } | {
25
87
  type: "mpeg_dvb";
26
88
  port: number;
27
89
  enabled: boolean;
90
+ id: number;
28
91
  active: boolean;
29
92
  title: string;
30
93
  ipAddress: string;
@@ -46,27 +109,46 @@ export declare class CamStreamerAPI<Client extends IClient<TResponse, any>> {
46
109
  } | {
47
110
  type: "rtmp";
48
111
  enabled: boolean;
112
+ id: number;
49
113
  active: boolean;
50
114
  title: string;
51
115
  } | {
52
116
  type: "sd_card";
53
117
  enabled: boolean;
118
+ id: number;
54
119
  active: boolean;
55
120
  title: string;
56
121
  } | {
57
122
  type: "windy";
58
123
  enabled: boolean;
124
+ id: number;
59
125
  active: boolean;
60
126
  title: string;
61
127
  } | {
62
128
  type: "youtube";
63
129
  enabled: boolean;
130
+ id: number;
64
131
  active: boolean;
65
132
  title: string;
66
133
  }>;
67
134
  setStream(streamId: number, streamData: Partial<TStream>, options?: THttpRequestOptions): Promise<void>;
68
135
  isStreaming(streamId: number, options?: THttpRequestOptions): Promise<boolean>;
69
- deleteStream(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
+ })[]>;
70
150
  private _getJson;
151
+ private _postJsonEncoded;
152
+ private _post;
71
153
  }
72
154
  export declare const parseCameraStreamResponse: (cameraStreamData: TOldStringStream) => TOldStream;
@@ -31,55 +31,81 @@ class CamStreamerAPI {
31
31
  return zod_1.z.number().parse(res.data);
32
32
  }
33
33
  async getStreamList(options) {
34
- const res = await this._getJson(`${BASE_PATH}/stream/list.cgi`, undefined, options);
35
- const streamList = {};
36
- const invalidList = {};
37
- for (const [key, value] of Object.entries(res.data)) {
38
- const id = parseInt(key);
39
- try {
40
- const parsed = CamStreamerAPI_1.streamSchema.parse(value);
41
- streamList[id] = parsed;
34
+ const res = await this._getJson(`${BASE_PATH}/stream_list.cgi`, { action: 'get' }, options);
35
+ const oldStreamListRecord = zod_1.z.record(zod_1.z.string(), oldStreamSchema_1.oldStringStreamSchema).safeParse(res.data);
36
+ if (oldStreamListRecord.success) {
37
+ const data = Object.entries(oldStreamListRecord.data).map(([id, streamData]) => ({
38
+ id: parseInt(id),
39
+ ...(0, exports.parseCameraStreamResponse)(streamData),
40
+ }));
41
+ throw new errors_1.MigrationError([], data);
42
+ }
43
+ const newStreamData = [];
44
+ const oldStreamData = [];
45
+ for (const streamData of res.data.streamList) {
46
+ const newStreamParse = CamStreamerAPI_1.streamSchema.safeParse(streamData);
47
+ if (newStreamParse.success) {
48
+ newStreamData.push(newStreamParse.data);
49
+ continue;
42
50
  }
43
- catch (err) {
44
- const oldStream = oldStreamSchema_1.oldStringStreamSchema.parse(value);
45
- const parsedOldStream = (0, exports.parseCameraStreamResponse)(oldStream);
46
- invalidList[id] = parsedOldStream;
51
+ const oldStreamParse = oldStreamSchema_1.oldStringStreamSchemaWithId.safeParse(streamData);
52
+ if (oldStreamParse.success) {
53
+ oldStreamData.push({
54
+ id: parseInt(oldStreamParse.data.id),
55
+ ...(0, exports.parseCameraStreamResponse)(oldStreamParse.data),
56
+ });
57
+ continue;
47
58
  }
59
+ throw new Error('Failed to parse some stream entries');
48
60
  }
49
- if (Object.keys(invalidList).length > 0) {
50
- throw new errors_1.MigrationError(streamList, invalidList);
61
+ if (oldStreamData.length > 0) {
62
+ throw new errors_1.MigrationError(newStreamData, oldStreamData);
51
63
  }
52
- return streamList;
64
+ return newStreamData;
65
+ }
66
+ async setStreamList(streamList, options) {
67
+ await this._postJsonEncoded(`${BASE_PATH}/stream_list.cgi`, JSON.stringify({ streamList }), {
68
+ action: 'set',
69
+ }, options);
53
70
  }
54
71
  async getStream(streamId, options) {
55
- const res = await this._getJson(`${BASE_PATH}/stream/get.cgi`, { stream_id: streamId }, options);
56
- try {
57
- return CamStreamerAPI_1.streamSchema.parse(res.data);
58
- }
59
- catch (err) {
60
- const oldStream = oldStreamSchema_1.oldStringStreamSchema.parse(res.data);
61
- const parsedOldStream = (0, exports.parseCameraStreamResponse)(oldStream);
62
- throw new errors_1.MigrationError({}, { [streamId]: parsedOldStream });
72
+ const res = await this._getJson(`${BASE_PATH}/stream_list.cgi`, { action: 'get', stream_id: streamId }, options);
73
+ const newStream = CamStreamerAPI_1.streamSchema.safeParse(res.data);
74
+ if (newStream.success) {
75
+ return newStream.data;
63
76
  }
77
+ const oldStream = oldStreamSchema_1.oldStringStreamSchema.passthrough().parse(res.data);
78
+ throw new errors_1.MigrationError([], [{ id: streamId, ...(0, exports.parseCameraStreamResponse)(oldStream) }]);
64
79
  }
65
80
  async setStream(streamId, streamData, options) {
66
- const agent = this.getClient(options?.proxyParams);
67
- await agent.post({
68
- path: `${BASE_PATH}/stream/set.cgi`,
69
- data: JSON.stringify(streamData),
70
- parameters: {
71
- stream_id: streamId,
72
- },
73
- timeout: options?.timeout,
74
- });
81
+ await this._postJsonEncoded(`${BASE_PATH}/stream_list.cgi`, JSON.stringify(streamData), {
82
+ action: 'set',
83
+ stream_id: streamId,
84
+ }, options);
75
85
  }
76
86
  async isStreaming(streamId, options) {
77
87
  const res = await this._getJson(`${BASE_PATH}/get_streamstat.cgi`, { stream_id: streamId }, options);
78
88
  return res.data.is_streaming === 1;
79
89
  }
80
- async deleteStream(streamId, options) {
81
- const res = await this._getJson(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
82
- return res.data.status === 200;
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);
83
109
  }
84
110
  async _getJson(path, parameters, options) {
85
111
  const agent = this.getClient(options?.proxyParams);
@@ -91,6 +117,27 @@ class CamStreamerAPI {
91
117
  throw new errors_1.ErrorWithResponse(res);
92
118
  }
93
119
  }
120
+ async _postJsonEncoded(path, data, parameters, options, headers) {
121
+ const agent = this.getClient(options?.proxyParams);
122
+ const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
123
+ return agent.post({
124
+ path,
125
+ data,
126
+ parameters,
127
+ timeout: options?.timeout,
128
+ headers: { ...baseHeaders, ...headers },
129
+ });
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
+ }
94
141
  }
95
142
  exports.CamStreamerAPI = CamStreamerAPI;
96
143
  const parseCameraStreamResponse = (cameraStreamData) => {
@@ -91,8 +91,12 @@ export declare class BadRequestError<T extends TResponse> extends ErrorWithRespo
91
91
  constructor(res: T);
92
92
  }
93
93
  export declare class MigrationError extends Error {
94
- readonly valid: Record<number, TStream>;
95
- readonly invalid: Record<number, TOldStream>;
96
- constructor(valid: Record<number, TStream>, invalid: Record<number, TOldStream>);
94
+ readonly valid: TStream[];
95
+ readonly invalid: (TOldStream & {
96
+ id: number;
97
+ })[];
98
+ constructor(valid: TStream[], invalid: (TOldStream & {
99
+ id: number;
100
+ })[]);
97
101
  }
98
102
  export {};