camstreamerlib 4.0.0-beta.80 → 4.0.0-beta.81
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.
- package/cjs/CamStreamerAPI.d.ts +70 -3
- package/cjs/CamStreamerAPI.js +53 -36
- package/cjs/errors/errors.d.ts +7 -3
- package/cjs/types/CamStreamerAPI/CamStreamerAPI.d.ts +338 -0
- package/cjs/types/CamStreamerAPI/CamStreamerAPI.js +2 -1
- package/cjs/types/CamStreamerAPI/facebookSchema.d.ts +3 -0
- package/cjs/types/CamStreamerAPI/hlsSchema.d.ts +3 -0
- package/cjs/types/CamStreamerAPI/mpegDvbSchema.d.ts +3 -0
- package/cjs/types/CamStreamerAPI/oldStreamSchema.d.ts +71 -0
- package/cjs/types/CamStreamerAPI/oldStreamSchema.js +4 -1
- package/cjs/types/CamStreamerAPI/rtmpSchema.d.ts +3 -0
- package/cjs/types/CamStreamerAPI/sdCardSchema.d.ts +3 -0
- package/cjs/types/CamStreamerAPI/streamCommonTypes.d.ts +3 -0
- package/cjs/types/CamStreamerAPI/streamCommonTypes.js +1 -0
- package/cjs/types/CamStreamerAPI/windySchema.d.ts +3 -0
- package/cjs/types/CamStreamerAPI/youtubeSchema.d.ts +3 -0
- package/esm/CamStreamerAPI.js +54 -37
- package/esm/types/CamStreamerAPI/CamStreamerAPI.js +1 -0
- package/esm/types/CamStreamerAPI/oldStreamSchema.js +3 -0
- package/esm/types/CamStreamerAPI/streamCommonTypes.js +1 -0
- package/package.json +1 -1
- package/types/CamStreamerAPI.d.ts +70 -3
- package/types/errors/errors.d.ts +7 -3
- package/types/types/CamStreamerAPI/CamStreamerAPI.d.ts +338 -0
- package/types/types/CamStreamerAPI/facebookSchema.d.ts +3 -0
- package/types/types/CamStreamerAPI/hlsSchema.d.ts +3 -0
- package/types/types/CamStreamerAPI/mpegDvbSchema.d.ts +3 -0
- package/types/types/CamStreamerAPI/oldStreamSchema.d.ts +71 -0
- package/types/types/CamStreamerAPI/rtmpSchema.d.ts +3 -0
- package/types/types/CamStreamerAPI/sdCardSchema.d.ts +3 -0
- package/types/types/CamStreamerAPI/streamCommonTypes.d.ts +3 -0
- package/types/types/CamStreamerAPI/windySchema.d.ts +3 -0
- package/types/types/CamStreamerAPI/youtubeSchema.d.ts +3 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
export declare const sdCardSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodNumber;
|
|
3
4
|
enabled: z.ZodBoolean;
|
|
4
5
|
active: z.ZodBoolean;
|
|
5
6
|
title: z.ZodString;
|
|
@@ -8,11 +9,13 @@ export declare const sdCardSchema: z.ZodObject<{
|
|
|
8
9
|
}, "strip", z.ZodTypeAny, {
|
|
9
10
|
type: "sd_card";
|
|
10
11
|
enabled: boolean;
|
|
12
|
+
id: number;
|
|
11
13
|
active: boolean;
|
|
12
14
|
title: string;
|
|
13
15
|
}, {
|
|
14
16
|
type: "sd_card";
|
|
15
17
|
enabled: boolean;
|
|
18
|
+
id: number;
|
|
16
19
|
active: boolean;
|
|
17
20
|
title: string;
|
|
18
21
|
}>;
|
|
@@ -2,15 +2,18 @@ import { z } from 'zod';
|
|
|
2
2
|
export declare const streamTypeSchema: z.ZodUnion<[z.ZodLiteral<"youtube">, z.ZodLiteral<"facebook">, z.ZodLiteral<"sd_card">, z.ZodLiteral<"windy">, z.ZodLiteral<"mpeg_dvb">, z.ZodLiteral<"hls">, z.ZodLiteral<"rtmp">]>;
|
|
3
3
|
export type TStreamType = z.infer<typeof streamTypeSchema>;
|
|
4
4
|
export declare const streamCommonSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodNumber;
|
|
5
6
|
enabled: z.ZodBoolean;
|
|
6
7
|
active: z.ZodBoolean;
|
|
7
8
|
title: z.ZodString;
|
|
8
9
|
}, "strip", z.ZodTypeAny, {
|
|
9
10
|
enabled: boolean;
|
|
11
|
+
id: number;
|
|
10
12
|
active: boolean;
|
|
11
13
|
title: string;
|
|
12
14
|
}, {
|
|
13
15
|
enabled: boolean;
|
|
16
|
+
id: number;
|
|
14
17
|
active: boolean;
|
|
15
18
|
title: string;
|
|
16
19
|
}>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
export declare const windySchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodNumber;
|
|
3
4
|
enabled: z.ZodBoolean;
|
|
4
5
|
active: z.ZodBoolean;
|
|
5
6
|
title: z.ZodString;
|
|
@@ -8,11 +9,13 @@ export declare const windySchema: z.ZodObject<{
|
|
|
8
9
|
}, "strip", z.ZodTypeAny, {
|
|
9
10
|
type: "windy";
|
|
10
11
|
enabled: boolean;
|
|
12
|
+
id: number;
|
|
11
13
|
active: boolean;
|
|
12
14
|
title: string;
|
|
13
15
|
}, {
|
|
14
16
|
type: "windy";
|
|
15
17
|
enabled: boolean;
|
|
18
|
+
id: number;
|
|
16
19
|
active: boolean;
|
|
17
20
|
title: string;
|
|
18
21
|
}>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
export declare const youtubeSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodNumber;
|
|
3
4
|
enabled: z.ZodBoolean;
|
|
4
5
|
active: z.ZodBoolean;
|
|
5
6
|
title: z.ZodString;
|
|
@@ -8,11 +9,13 @@ export declare const youtubeSchema: z.ZodObject<{
|
|
|
8
9
|
}, "strip", z.ZodTypeAny, {
|
|
9
10
|
type: "youtube";
|
|
10
11
|
enabled: boolean;
|
|
12
|
+
id: number;
|
|
11
13
|
active: boolean;
|
|
12
14
|
title: string;
|
|
13
15
|
}, {
|
|
14
16
|
type: "youtube";
|
|
15
17
|
enabled: boolean;
|
|
18
|
+
id: number;
|
|
16
19
|
active: boolean;
|
|
17
20
|
title: string;
|
|
18
21
|
}>;
|
package/esm/CamStreamerAPI.js
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { ProxyClient } from './internal/ProxyClient';
|
|
3
3
|
import { streamSchema } from './types/CamStreamerAPI/CamStreamerAPI';
|
|
4
4
|
import { ErrorWithResponse, UtcTimeFetchError, WsAuthorizationError, MigrationError } from './errors/errors';
|
|
5
|
-
import { oldStringStreamSchema } from './types/CamStreamerAPI/oldStreamSchema';
|
|
5
|
+
import { oldStringStreamSchema, oldStringStreamSchemaWithId, } from './types/CamStreamerAPI/oldStreamSchema';
|
|
6
6
|
const BASE_PATH = '/local/camstreamer';
|
|
7
7
|
export class CamStreamerAPI {
|
|
8
8
|
client;
|
|
@@ -28,56 +28,62 @@ export class CamStreamerAPI {
|
|
|
28
28
|
return z.number().parse(res.data);
|
|
29
29
|
}
|
|
30
30
|
async getStreamList(options) {
|
|
31
|
-
const res = await this._getJson(`${BASE_PATH}/
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const res = await this._getJson(`${BASE_PATH}/stream_list.cgi`, { action: 'get' }, options);
|
|
32
|
+
const oldStreamListRecord = z.record(z.string(), oldStringStreamSchema).safeParse(res.data);
|
|
33
|
+
if (oldStreamListRecord.success) {
|
|
34
|
+
const data = Object.entries(oldStreamListRecord.data).map(([id, streamData]) => ({
|
|
35
|
+
id: parseInt(id),
|
|
36
|
+
...parseCameraStreamResponse(streamData),
|
|
37
|
+
}));
|
|
38
|
+
throw new MigrationError([], data);
|
|
39
|
+
}
|
|
40
|
+
const newStreamData = [];
|
|
41
|
+
const oldStreamData = [];
|
|
42
|
+
for (const streamData of res.data.streamList) {
|
|
43
|
+
const newStreamParse = streamSchema.safeParse(streamData);
|
|
44
|
+
if (newStreamParse.success) {
|
|
45
|
+
newStreamData.push(newStreamParse.data);
|
|
46
|
+
continue;
|
|
39
47
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
const oldStreamParse = oldStringStreamSchemaWithId.safeParse(streamData);
|
|
49
|
+
if (oldStreamParse.success) {
|
|
50
|
+
oldStreamData.push({
|
|
51
|
+
id: parseInt(oldStreamParse.data.id),
|
|
52
|
+
...parseCameraStreamResponse(oldStreamParse.data),
|
|
53
|
+
});
|
|
54
|
+
continue;
|
|
44
55
|
}
|
|
56
|
+
throw new Error('Failed to parse some stream entries');
|
|
45
57
|
}
|
|
46
|
-
if (
|
|
47
|
-
throw new MigrationError(
|
|
58
|
+
if (oldStreamData.length > 0) {
|
|
59
|
+
throw new MigrationError(newStreamData, oldStreamData);
|
|
48
60
|
}
|
|
49
|
-
return
|
|
61
|
+
return newStreamData;
|
|
62
|
+
}
|
|
63
|
+
async setStreamList(streamList, options) {
|
|
64
|
+
await this._postJsonEncoded(`${BASE_PATH}/stream_list.cgi`, JSON.stringify({ streamList }), {
|
|
65
|
+
action: 'set',
|
|
66
|
+
}, options);
|
|
50
67
|
}
|
|
51
68
|
async getStream(streamId, options) {
|
|
52
|
-
const res = await this._getJson(`${BASE_PATH}/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
catch (err) {
|
|
57
|
-
const oldStream = oldStringStreamSchema.parse(res.data);
|
|
58
|
-
const parsedOldStream = parseCameraStreamResponse(oldStream);
|
|
59
|
-
throw new MigrationError({}, { [streamId]: parsedOldStream });
|
|
69
|
+
const res = await this._getJson(`${BASE_PATH}/stream_list.cgi`, { action: 'get', stream_id: streamId }, options);
|
|
70
|
+
const newStream = streamSchema.safeParse(res.data);
|
|
71
|
+
if (newStream.success) {
|
|
72
|
+
return newStream.data;
|
|
60
73
|
}
|
|
74
|
+
const oldStream = oldStringStreamSchema.passthrough().parse(res.data);
|
|
75
|
+
throw new MigrationError([], [{ id: streamId, ...parseCameraStreamResponse(oldStream) }]);
|
|
61
76
|
}
|
|
62
77
|
async setStream(streamId, streamData, options) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
parameters: {
|
|
68
|
-
stream_id: streamId,
|
|
69
|
-
},
|
|
70
|
-
timeout: options?.timeout,
|
|
71
|
-
});
|
|
78
|
+
await this._postJsonEncoded(`${BASE_PATH}/stream_list.cgi`, JSON.stringify(streamData), {
|
|
79
|
+
action: 'set',
|
|
80
|
+
stream_id: streamId,
|
|
81
|
+
}, options);
|
|
72
82
|
}
|
|
73
83
|
async isStreaming(streamId, options) {
|
|
74
84
|
const res = await this._getJson(`${BASE_PATH}/get_streamstat.cgi`, { stream_id: streamId }, options);
|
|
75
85
|
return res.data.is_streaming === 1;
|
|
76
86
|
}
|
|
77
|
-
async deleteStream(streamId, options) {
|
|
78
|
-
const res = await this._getJson(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
|
|
79
|
-
return res.data.status === 200;
|
|
80
|
-
}
|
|
81
87
|
async _getJson(path, parameters, options) {
|
|
82
88
|
const agent = this.getClient(options?.proxyParams);
|
|
83
89
|
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
@@ -88,6 +94,17 @@ export class CamStreamerAPI {
|
|
|
88
94
|
throw new ErrorWithResponse(res);
|
|
89
95
|
}
|
|
90
96
|
}
|
|
97
|
+
async _postJsonEncoded(path, data, parameters, options, headers) {
|
|
98
|
+
const agent = this.getClient(options?.proxyParams);
|
|
99
|
+
const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
|
|
100
|
+
return agent.post({
|
|
101
|
+
path,
|
|
102
|
+
data,
|
|
103
|
+
parameters,
|
|
104
|
+
timeout: options?.timeout,
|
|
105
|
+
headers: { ...baseHeaders, ...headers },
|
|
106
|
+
});
|
|
107
|
+
}
|
|
91
108
|
}
|
|
92
109
|
export const parseCameraStreamResponse = (cameraStreamData) => {
|
|
93
110
|
return {
|
|
@@ -15,6 +15,7 @@ export const streamSchema = z.discriminatedUnion('type', [
|
|
|
15
15
|
windySchema,
|
|
16
16
|
youtubeSchema,
|
|
17
17
|
]);
|
|
18
|
+
export const streamListSchema = z.object({ streamList: z.array(streamSchema) });
|
|
18
19
|
export const isFacebookStream = (stream) => {
|
|
19
20
|
return stream.type === 'facebook';
|
|
20
21
|
};
|
|
@@ -22,6 +22,9 @@ export const oldStringStreamSchema = z.object({
|
|
|
22
22
|
startTime: z.string(),
|
|
23
23
|
stopTime: z.string(),
|
|
24
24
|
});
|
|
25
|
+
export const oldStringStreamSchemaWithId = oldStringStreamSchema.extend({
|
|
26
|
+
id: z.string(),
|
|
27
|
+
});
|
|
25
28
|
export const oldStreamSchema = z.object({
|
|
26
29
|
enabled: z.union([z.literal(0), z.literal(1)]),
|
|
27
30
|
active: z.union([z.literal(0), z.literal(1)]),
|
package/package.json
CHANGED
|
@@ -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 { 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<
|
|
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,31 @@ 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>;
|
|
70
136
|
private _getJson;
|
|
137
|
+
private _postJsonEncoded;
|
|
71
138
|
}
|
|
72
139
|
export declare const parseCameraStreamResponse: (cameraStreamData: TOldStringStream) => TOldStream;
|
package/types/errors/errors.d.ts
CHANGED
|
@@ -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:
|
|
95
|
-
readonly invalid:
|
|
96
|
-
|
|
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 {};
|