camstreamerlib 4.0.0-beta.36 → 4.0.0-beta.38
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/CamOverlayAPI.js +52 -79
- package/cjs/CamScripterAPI.js +30 -24
- package/cjs/CamStreamerAPI.js +30 -33
- package/cjs/CamSwitcherAPI.js +57 -52
- package/cjs/PlaneTrackerAPI.js +55 -66
- package/cjs/VapixAPI.js +23 -22
- package/cjs/{CamOverlayDrawingAPI.js → node/CamOverlayDrawingAPI.js} +1 -1
- package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/Painter.js +4 -14
- package/cjs/{CamScripterAPICameraEventsGenerator.js → node/CamScripterAPICameraEventsGenerator.js} +1 -1
- package/cjs/{VapixEvents.js → node/VapixEvents.js} +1 -1
- package/cjs/node/events/GenetecAgent.js +5 -27
- package/cjs/node/index.js +17 -0
- package/cjs/types/CamOverlayAPI/CamOverlayAPI.js +18 -18
- package/cjs/types/CamOverlayAPI/accuweatherSchema.js +7 -7
- package/cjs/types/CamOverlayAPI/customGraphicsSchema.js +5 -5
- package/cjs/types/CamOverlayAPI/imagesSchema.js +4 -4
- package/cjs/types/CamOverlayAPI/index.js +1 -1
- package/cjs/types/CamOverlayAPI/infotickerSchema.js +6 -6
- package/cjs/types/CamOverlayAPI/pipSchema.js +4 -4
- package/cjs/types/CamOverlayAPI/ptzCompassSchema.js +4 -4
- package/cjs/types/CamOverlayAPI/ptzSchema.js +4 -4
- package/cjs/types/CamOverlayAPI/scoreBoardSchema.js +8 -8
- package/cjs/types/CamOverlayAPI/screenSharingSchema.js +3 -3
- package/cjs/types/CamOverlayAPI/{widgetCommonTypes.js → serviceCommonTypes.js} +8 -4
- package/cjs/types/CamOverlayAPI/webCameraSharingSchema.js +3 -3
- package/cjs/types/CamOverlayPainter.js +12 -0
- package/cjs/types/CamScripterAPICameraEventsGenerator.js +2 -0
- package/cjs/types/CamSwitcherAPI.js +38 -1
- package/cjs/types/GenetecAgent.js +31 -0
- package/cjs/types/PlaneTrackerAPI.js +277 -0
- package/cjs/types/VapixAPI.js +20 -2
- package/cjs/types/VapixEvents.js +2 -0
- package/esm/CamOverlayAPI.js +53 -80
- package/esm/CamScripterAPI.js +30 -24
- package/esm/CamStreamerAPI.js +30 -30
- package/esm/CamSwitcherAPI.js +58 -53
- package/esm/PlaneTrackerAPI.js +56 -67
- package/esm/VapixAPI.js +24 -23
- package/esm/{CamOverlayDrawingAPI.js → node/CamOverlayDrawingAPI.js} +1 -1
- package/esm/{CamOverlayPainter → node/CamOverlayPainter}/Painter.js +1 -11
- package/esm/{CamScripterAPICameraEventsGenerator.js → node/CamScripterAPICameraEventsGenerator.js} +1 -1
- package/esm/{VapixEvents.js → node/VapixEvents.js} +1 -1
- package/esm/node/events/GenetecAgent.js +1 -23
- package/esm/node/index.js +10 -0
- package/esm/types/CamOverlayAPI/CamOverlayAPI.js +17 -17
- package/esm/types/CamOverlayAPI/accuweatherSchema.js +3 -3
- package/esm/types/CamOverlayAPI/customGraphicsSchema.js +3 -3
- package/esm/types/CamOverlayAPI/imagesSchema.js +3 -3
- package/esm/types/CamOverlayAPI/index.js +1 -1
- package/esm/types/CamOverlayAPI/infotickerSchema.js +3 -3
- package/esm/types/CamOverlayAPI/pipSchema.js +3 -3
- package/esm/types/CamOverlayAPI/ptzCompassSchema.js +3 -3
- package/esm/types/CamOverlayAPI/ptzSchema.js +3 -3
- package/esm/types/CamOverlayAPI/scoreBoardSchema.js +5 -5
- package/esm/types/CamOverlayAPI/screenSharingSchema.js +2 -2
- package/esm/types/CamOverlayAPI/{widgetCommonTypes.js → serviceCommonTypes.js} +7 -3
- package/esm/types/CamOverlayAPI/webCameraSharingSchema.js +2 -2
- package/esm/types/CamOverlayPainter.js +11 -1
- package/esm/types/CamSwitcherAPI.js +38 -1
- package/esm/types/GenetecAgent.js +28 -0
- package/esm/types/PlaneTrackerAPI.js +276 -1
- package/esm/types/VapixAPI.js +19 -1
- package/esm/types/VapixEvents.js +1 -0
- package/package.json +1 -1
- package/types/CamOverlayAPI.d.ts +836 -10
- package/types/CamScripterAPI.d.ts +34 -9
- package/types/CamStreamerAPI.d.ts +27 -5
- package/types/CamSwitcherAPI.d.ts +136 -23
- package/types/PlaneTrackerAPI.d.ts +201 -20
- package/types/VapixAPI.d.ts +46 -12
- package/types/bin/CreatePackage.d.ts +1 -0
- package/types/{CamOverlayDrawingAPI.d.ts → node/CamOverlayDrawingAPI.d.ts} +1 -1
- package/types/{CamOverlayPainter → node/CamOverlayPainter}/Frame.d.ts +2 -2
- package/types/{CamOverlayPainter → node/CamOverlayPainter}/Painter.d.ts +2 -13
- package/types/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.d.ts +1 -1
- package/types/node/CamScripterAPICameraEventsGenerator.d.ts +31 -0
- package/types/node/VapixEvents.d.ts +16 -0
- package/types/node/events/GenetecAgent.d.ts +1 -144
- package/types/node/index.d.ts +10 -0
- package/types/types/CamOverlayAPI/CamOverlayAPI.d.ts +20 -20
- package/types/types/CamOverlayAPI/index.d.ts +1 -1
- package/types/types/CamOverlayAPI/{widgetCommonTypes.d.ts → serviceCommonTypes.d.ts} +6 -2
- package/types/types/CamOverlayDrawingAPI.d.ts +3 -13
- package/types/types/CamOverlayPainter.d.ts +12 -10
- package/types/types/CamScripterAPICameraEventsGenerator.d.ts +45 -0
- package/types/types/CamStreamerAPI.d.ts +2 -2
- package/types/types/CamSwitcherAPI.d.ts +111 -30
- package/types/types/GenetecAgent.d.ts +174 -0
- package/types/types/PlaneTrackerAPI.d.ts +859 -0
- package/types/types/VapixAPI.d.ts +54 -8
- package/types/types/VapixEvents.d.ts +15 -0
- package/types/types/common.d.ts +1 -0
- package/types/CamScripterAPICameraEventsGenerator.d.ts +0 -74
- package/types/VapixEvents.d.ts +0 -43
- /package/cjs/{CreatePackage.js → bin/CreatePackage.js} +0 -0
- /package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/Frame.js +0 -0
- /package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.js +0 -0
- /package/esm/{CreatePackage.js → bin/CreatePackage.js} +0 -0
- /package/esm/{CamOverlayPainter → node/CamOverlayPainter}/Frame.js +0 -0
- /package/esm/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.js +0 -0
- /package/{types/CreatePackage.d.ts → esm/types/CamScripterAPICameraEventsGenerator.js} +0 -0
package/cjs/types/VapixAPI.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.portSequenceStateSchema = exports.portSetSchema = exports.getPortsResponseSchema = exports.portStatusSchema = exports.audioSampleRatesResponseSchema = exports.timeZoneSchema = exports.dateTimeinfoSchema = exports.maxFpsResponseSchema = exports.audioDeviceRequestSchema = exports.audioDeviceSchema = exports.audioDeviceInputOutputSchema = exports.audioDeviceConnectionTypeSchema = exports.audioDeviceSignalingTypeSchema = exports.audioDeviceSignalingChannelTypeSchema = exports.cameraPTZItemSchema = exports.cameraPTZItemDataSchema = exports.
|
|
3
|
+
exports.portSequenceStateSchema = exports.portSetSchema = exports.getPortsResponseSchema = exports.portStatusSchema = exports.audioSampleRatesResponseSchema = exports.timeZoneSchema = exports.dateTimeinfoSchema = exports.maxFpsResponseSchema = exports.audioDeviceRequestSchema = exports.audioDeviceSchema = exports.audioDeviceInputOutputSchema = exports.audioDeviceConnectionTypeSchema = exports.audioDeviceSignalingTypeSchema = exports.audioDeviceSignalingChannelTypeSchema = exports.cameraPTZItemSchema = exports.cameraPTZItemDataSchema = exports.ptzOverviewSchema = exports.sdCardInfoSchema = exports.sdCardWatchedStatuses = exports.guardTourSchema = exports.APP_IDS = exports.applicationListSchema = exports.applicationSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const transformers_1 = require("../internal/transformers");
|
|
6
6
|
exports.applicationSchema = zod_1.z.object({
|
|
@@ -15,6 +15,19 @@ exports.applicationSchema = zod_1.z.object({
|
|
|
15
15
|
VendorHomePage: zod_1.z.string().optional(),
|
|
16
16
|
LicenseName: zod_1.z.string().optional(),
|
|
17
17
|
});
|
|
18
|
+
exports.applicationListSchema = zod_1.z.array(exports.applicationSchema.extend({
|
|
19
|
+
appId: zod_1.z
|
|
20
|
+
.union([
|
|
21
|
+
zod_1.z.literal('CamStreamer'),
|
|
22
|
+
zod_1.z.literal('CamSwitcher'),
|
|
23
|
+
zod_1.z.literal('CamOverlay'),
|
|
24
|
+
zod_1.z.literal('CamScripter'),
|
|
25
|
+
zod_1.z.literal('PlaneTracker'),
|
|
26
|
+
zod_1.z.literal('Ndihxplugin'),
|
|
27
|
+
zod_1.z.literal('SportTracker'),
|
|
28
|
+
])
|
|
29
|
+
.nullable(),
|
|
30
|
+
}));
|
|
18
31
|
exports.APP_IDS = [
|
|
19
32
|
'CamStreamer',
|
|
20
33
|
'CamSwitcher',
|
|
@@ -45,7 +58,12 @@ const audioSampleRatesSchema = zod_1.z.object({
|
|
|
45
58
|
});
|
|
46
59
|
const audioSampleRatesOutSchema = audioSampleRatesSchema.transform(transformers_1.toCamelCaseDeep);
|
|
47
60
|
exports.sdCardWatchedStatuses = ['OK', 'connected', 'disconnected'];
|
|
48
|
-
exports.
|
|
61
|
+
exports.sdCardInfoSchema = zod_1.z.object({
|
|
62
|
+
status: zod_1.z.enum(exports.sdCardWatchedStatuses),
|
|
63
|
+
totalSize: zod_1.z.number(),
|
|
64
|
+
freeSize: zod_1.z.number(),
|
|
65
|
+
});
|
|
66
|
+
exports.ptzOverviewSchema = zod_1.z.record(zod_1.z.number(), zod_1.z.array(zod_1.z.object({ id: zod_1.z.number(), name: zod_1.z.string() })));
|
|
49
67
|
exports.cameraPTZItemDataSchema = zod_1.z.object({
|
|
50
68
|
pan: zod_1.z.number().optional(),
|
|
51
69
|
tilt: zod_1.z.number().optional(),
|
package/esm/CamOverlayAPI.js
CHANGED
|
@@ -3,7 +3,7 @@ import { ParsingBlobError, ServiceNotFoundError } from './errors/errors';
|
|
|
3
3
|
import { networkCameraListSchema } from './types/common';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { ProxyClient } from './internal/ProxyClient';
|
|
6
|
-
import { fileListSchema, ImageType, storageDataListSchema,
|
|
6
|
+
import { fileListSchema, ImageType, storageDataListSchema, serviceListSchema, servicesSchema, wsResponseSchema, } from './types/CamOverlayAPI';
|
|
7
7
|
const BASE_PATH = '/local/camoverlay/api';
|
|
8
8
|
export class CamOverlayAPI {
|
|
9
9
|
client;
|
|
@@ -17,68 +17,51 @@ export class CamOverlayAPI {
|
|
|
17
17
|
return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
|
|
18
18
|
}
|
|
19
19
|
async checkCameraTime(options) {
|
|
20
|
-
const
|
|
21
|
-
return z.boolean().parse(
|
|
20
|
+
const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
|
|
21
|
+
return z.boolean().parse(res.state);
|
|
22
22
|
}
|
|
23
23
|
async getNetworkCameraList(options) {
|
|
24
|
-
const
|
|
25
|
-
return networkCameraListSchema.parse(
|
|
24
|
+
const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
|
|
25
|
+
return networkCameraListSchema.parse(res.camera_list);
|
|
26
26
|
}
|
|
27
27
|
async wsAuthorization(options) {
|
|
28
|
-
const
|
|
29
|
-
return
|
|
28
|
+
const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
|
|
29
|
+
return wsResponseSchema.parse(res).message;
|
|
30
30
|
}
|
|
31
31
|
async getMjpegStreamImage(mjpegUrl, options) {
|
|
32
|
-
return await this._getBlob({
|
|
33
|
-
path: `${BASE_PATH}/fetch_mjpeg_image.cgi?mjpeg_url=${encodeURIComponent(decodeURIComponent(mjpegUrl))}`,
|
|
34
|
-
}, options);
|
|
32
|
+
return await this._getBlob(`${BASE_PATH}/fetch_mjpeg_image.cgi`, { mjpeg_url: decodeURIComponent(mjpegUrl) }, options);
|
|
35
33
|
}
|
|
36
34
|
async listFiles(fileType, options) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
parameters: {
|
|
40
|
-
action: 'list',
|
|
41
|
-
},
|
|
42
|
-
}, options);
|
|
43
|
-
return fileListSchema.parse(files.list);
|
|
35
|
+
const res = await this._getJson(`${BASE_PATH}/upload_${fileType}.cgi`, { action: 'list' }, options);
|
|
36
|
+
return fileListSchema.parse(res.list);
|
|
44
37
|
}
|
|
45
38
|
async uploadFile(fileType, formData, storage, options) {
|
|
46
|
-
await this._post({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
parameters: {
|
|
50
|
-
action: 'upload',
|
|
51
|
-
storage: storage,
|
|
52
|
-
},
|
|
39
|
+
await this._post(`${BASE_PATH}/upload_${fileType}.cgi`, formData, {
|
|
40
|
+
action: 'upload',
|
|
41
|
+
storage: storage,
|
|
53
42
|
}, options);
|
|
54
43
|
}
|
|
55
44
|
async removeFile(fileType, fileParams, options) {
|
|
56
|
-
|
|
57
|
-
await this._postUrlEncoded(path, {
|
|
45
|
+
await this._postUrlEncoded(`${BASE_PATH}/upload_${fileType}.cgi`, {
|
|
58
46
|
action: 'remove',
|
|
59
47
|
...fileParams,
|
|
60
|
-
},
|
|
48
|
+
}, options, undefined);
|
|
61
49
|
}
|
|
62
50
|
async getFileStorage(fileType, options) {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
parameters: {
|
|
66
|
-
action: 'get_storage',
|
|
67
|
-
},
|
|
68
|
-
}, options);
|
|
69
|
-
if (data.code !== 200) {
|
|
51
|
+
const res = await this._getJson(`${BASE_PATH}/upload_${fileType}.cgi`, { action: 'get_storage' }, options);
|
|
52
|
+
if (res.code !== 200) {
|
|
70
53
|
throw new Error('Error occured while fetching file storage data');
|
|
71
54
|
}
|
|
72
|
-
return storageDataListSchema.parse(
|
|
55
|
+
return storageDataListSchema.parse(res.list);
|
|
73
56
|
}
|
|
74
57
|
async getFilePreviewFromCamera(path, options) {
|
|
75
|
-
return await this._getBlob(
|
|
58
|
+
return await this._getBlob(CamOverlayAPI.getFilePreviewPath(path), undefined, options);
|
|
76
59
|
}
|
|
77
60
|
async updateInfoticker(serviceId, text, options) {
|
|
78
|
-
await this.
|
|
61
|
+
await this._getJson(`${BASE_PATH}/infoticker.cgi`, { service_id: serviceId, text: text }, options);
|
|
79
62
|
}
|
|
80
63
|
async setEnabled(serviceId, enabled, options) {
|
|
81
|
-
await this._post(
|
|
64
|
+
await this._post(`${BASE_PATH}/enabled.cgi`, '', { [`id_${serviceId}`]: enabled ? 1 : 0 }, options);
|
|
82
65
|
}
|
|
83
66
|
async isEnabled(serviceId, options) {
|
|
84
67
|
const agent = this.getClient(options?.proxyParams);
|
|
@@ -96,44 +79,34 @@ export class CamOverlayAPI {
|
|
|
96
79
|
throw new Error(await responseStringify(res));
|
|
97
80
|
}
|
|
98
81
|
}
|
|
99
|
-
async
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
action: 'get',
|
|
104
|
-
service_id: serviceId.toString(),
|
|
105
|
-
},
|
|
106
|
-
}, options);
|
|
107
|
-
return widgetsSchema.parse(data);
|
|
108
|
-
}
|
|
109
|
-
async getWidgets(options) {
|
|
110
|
-
const widgetList = await this._get({
|
|
111
|
-
path: `${BASE_PATH}/services.cgi`,
|
|
112
|
-
parameters: {
|
|
113
|
-
action: 'get',
|
|
114
|
-
},
|
|
82
|
+
async getSingleService(serviceId, options) {
|
|
83
|
+
const res = await this._getJson(`${BASE_PATH}/services.cgi`, {
|
|
84
|
+
action: 'get',
|
|
85
|
+
service_id: serviceId,
|
|
115
86
|
}, options);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
87
|
+
return servicesSchema.parse(res);
|
|
88
|
+
}
|
|
89
|
+
async getServices(options) {
|
|
90
|
+
const res = await this._getJson(`${BASE_PATH}/services.cgi`, { action: 'get' }, options);
|
|
91
|
+
const services = serviceListSchema.parse(res).services;
|
|
92
|
+
services.forEach((service) => {
|
|
93
|
+
const parsedService = servicesSchema.safeParse(service);
|
|
94
|
+
if (!parsedService.success) {
|
|
95
|
+
console.warn(`[SERVICE SCHEMA MISMATCH]: Service ${service.name} (${service.id}) does not match the current schema, or is a hidden service.`);
|
|
121
96
|
}
|
|
122
97
|
});
|
|
123
|
-
return
|
|
98
|
+
return services;
|
|
124
99
|
}
|
|
125
|
-
async
|
|
126
|
-
|
|
127
|
-
await this._postJsonEncoded(path, JSON.stringify(widget), {
|
|
100
|
+
async updateSingleService(service, options) {
|
|
101
|
+
await this._postJsonEncoded(`${BASE_PATH}/services.cgi`, JSON.stringify(service), {
|
|
128
102
|
action: 'set',
|
|
129
|
-
service_id:
|
|
130
|
-
},
|
|
103
|
+
service_id: service.id,
|
|
104
|
+
}, options, undefined);
|
|
131
105
|
}
|
|
132
|
-
async
|
|
133
|
-
|
|
134
|
-
await this._postJsonEncoded(path, JSON.stringify({ services: widgets }), {
|
|
106
|
+
async updateServices(services, options) {
|
|
107
|
+
await this._postJsonEncoded(`${BASE_PATH}/services.cgi`, JSON.stringify({ services: services }), {
|
|
135
108
|
action: 'set',
|
|
136
|
-
},
|
|
109
|
+
}, options, undefined);
|
|
137
110
|
}
|
|
138
111
|
updateCGText(serviceId, fields, options) {
|
|
139
112
|
const params = {};
|
|
@@ -194,9 +167,9 @@ export class CamOverlayAPI {
|
|
|
194
167
|
throw new Error(await responseStringify(res));
|
|
195
168
|
}
|
|
196
169
|
}
|
|
197
|
-
async
|
|
170
|
+
async _getJson(path, parameters, options) {
|
|
198
171
|
const agent = this.getClient(options?.proxyParams);
|
|
199
|
-
const res = await agent.get({
|
|
172
|
+
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
200
173
|
if (res.ok) {
|
|
201
174
|
return await res.json();
|
|
202
175
|
}
|
|
@@ -204,9 +177,9 @@ export class CamOverlayAPI {
|
|
|
204
177
|
throw new Error(await responseStringify(res));
|
|
205
178
|
}
|
|
206
179
|
}
|
|
207
|
-
async _post(
|
|
180
|
+
async _post(path, data, parameters, options, headers) {
|
|
208
181
|
const agent = this.getClient(options?.proxyParams);
|
|
209
|
-
const res = await agent.post({
|
|
182
|
+
const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
|
|
210
183
|
if (res.ok) {
|
|
211
184
|
return await res.json();
|
|
212
185
|
}
|
|
@@ -214,9 +187,9 @@ export class CamOverlayAPI {
|
|
|
214
187
|
throw new Error(await responseStringify(res));
|
|
215
188
|
}
|
|
216
189
|
}
|
|
217
|
-
async _getBlob(
|
|
190
|
+
async _getBlob(path, parameters, options) {
|
|
218
191
|
const agent = this.getClient(options?.proxyParams);
|
|
219
|
-
const res = await agent.get({
|
|
192
|
+
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
220
193
|
if (res.ok) {
|
|
221
194
|
return await this.parseBlobResponse(res);
|
|
222
195
|
}
|
|
@@ -232,13 +205,13 @@ export class CamOverlayAPI {
|
|
|
232
205
|
throw new ParsingBlobError(err);
|
|
233
206
|
}
|
|
234
207
|
}
|
|
235
|
-
async _postUrlEncoded(path,
|
|
236
|
-
const data = paramToUrl(
|
|
208
|
+
async _postUrlEncoded(path, parameters, options, headers) {
|
|
209
|
+
const data = paramToUrl(parameters);
|
|
237
210
|
const baseHeaders = { 'Content-Type': 'application/x-www-form-urlencoded' };
|
|
238
|
-
return this._post(
|
|
211
|
+
return this._post(path, data, undefined, options, { ...baseHeaders, ...headers });
|
|
239
212
|
}
|
|
240
|
-
async _postJsonEncoded(path, data, parameters,
|
|
213
|
+
async _postJsonEncoded(path, data, parameters, options, headers) {
|
|
241
214
|
const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
|
|
242
|
-
return this._post(
|
|
215
|
+
return this._post(path, data, parameters, options, { ...baseHeaders, ...headers });
|
|
243
216
|
}
|
|
244
217
|
}
|
package/esm/CamScripterAPI.js
CHANGED
|
@@ -8,51 +8,57 @@ export class CamScripterAPI {
|
|
|
8
8
|
constructor(client) {
|
|
9
9
|
this.client = client;
|
|
10
10
|
}
|
|
11
|
-
static
|
|
11
|
+
static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
|
|
12
12
|
getClient(proxyParams) {
|
|
13
13
|
return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
|
|
14
14
|
}
|
|
15
15
|
async checkCameraTime(options) {
|
|
16
|
-
const
|
|
17
|
-
return cameraTimeResponseSchema.parse(
|
|
16
|
+
const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
|
|
17
|
+
return cameraTimeResponseSchema.parse(res).state;
|
|
18
18
|
}
|
|
19
19
|
async getNetworkCameraList(options) {
|
|
20
|
-
const
|
|
21
|
-
return networkCameraListSchema.parse(
|
|
20
|
+
const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
|
|
21
|
+
return networkCameraListSchema.parse(res.camera_list);
|
|
22
22
|
}
|
|
23
23
|
async getStorageInfo(options) {
|
|
24
|
-
const
|
|
25
|
-
return storageSchema.parse(
|
|
24
|
+
const res = await this._getJson(`${BASE_PATH}/package/get_storage.cgi`, undefined, options);
|
|
25
|
+
return storageSchema.parse(res);
|
|
26
26
|
}
|
|
27
27
|
async getPackageList(options) {
|
|
28
|
-
const
|
|
29
|
-
return packageInfoListSchema.parse(
|
|
28
|
+
const res = await this._getJson(`${BASE_PATH}/package/list.cgi`, undefined, options);
|
|
29
|
+
return packageInfoListSchema.parse(res);
|
|
30
30
|
}
|
|
31
31
|
async installPackages(formData, storage, options) {
|
|
32
|
-
const
|
|
33
|
-
return camscripterApiResponseSchema.parse(
|
|
32
|
+
const res = await this._post(`${BASE_PATH}/package/install.cgi`, formData, { storage: storage }, options);
|
|
33
|
+
return camscripterApiResponseSchema.parse(res);
|
|
34
34
|
}
|
|
35
35
|
async uninstallPackage(packageId, options) {
|
|
36
|
-
const
|
|
37
|
-
return camscripterApiResponseSchema.parse(
|
|
36
|
+
const res = await this._getJson(`${BASE_PATH}/package/remove.cgi`, { package_name: packageId }, options);
|
|
37
|
+
return camscripterApiResponseSchema.parse(res);
|
|
38
38
|
}
|
|
39
39
|
async importSettings(packageId, formData, options) {
|
|
40
|
-
const
|
|
41
|
-
|
|
40
|
+
const res = await this._post(`${BASE_PATH}/package/data.cgi`, formData, {
|
|
41
|
+
action: 'IMPORT',
|
|
42
|
+
package_name: packageId,
|
|
43
|
+
}, options);
|
|
44
|
+
return camscripterApiResponseSchema.parse(res);
|
|
42
45
|
}
|
|
43
46
|
async exportSettings(packageId, formData, options) {
|
|
44
|
-
const
|
|
45
|
-
|
|
47
|
+
const res = await this._post(`${BASE_PATH}/package/data.cgi`, formData, {
|
|
48
|
+
action: 'EXPORT',
|
|
49
|
+
package_name: packageId,
|
|
50
|
+
}, options);
|
|
51
|
+
return camscripterApiResponseSchema.parse(res);
|
|
46
52
|
}
|
|
47
53
|
async getNodejsStatus(options) {
|
|
48
|
-
const
|
|
49
|
-
return nodeStateSchema.parse(
|
|
54
|
+
const res = await this._getJson(`${BASE_PATH}/diagnostics.cgi`, undefined, options);
|
|
55
|
+
return nodeStateSchema.parse(res);
|
|
50
56
|
}
|
|
51
57
|
async installNodejs(storage, options) {
|
|
52
|
-
const
|
|
53
|
-
return camscripterApiResponseSchema.parse(
|
|
58
|
+
const res = await this._getJson(`${BASE_PATH}/node_update.cgi`, { storage: storage }, options);
|
|
59
|
+
return camscripterApiResponseSchema.parse(res);
|
|
54
60
|
}
|
|
55
|
-
async
|
|
61
|
+
async _getJson(path, parameters, options) {
|
|
56
62
|
const agent = this.getClient(options?.proxyParams);
|
|
57
63
|
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
58
64
|
if (res.ok) {
|
|
@@ -62,9 +68,9 @@ export class CamScripterAPI {
|
|
|
62
68
|
throw new Error(await responseStringify(res));
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
|
-
async
|
|
71
|
+
async _post(path, data, parameters, options, headers) {
|
|
66
72
|
const agent = this.getClient(options?.proxyParams);
|
|
67
|
-
const res = await agent.post({ path, data, parameters, timeout: options?.timeout });
|
|
73
|
+
const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
|
|
68
74
|
if (res.ok) {
|
|
69
75
|
return await res.json();
|
|
70
76
|
}
|
package/esm/CamStreamerAPI.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import z from 'zod';
|
|
1
|
+
import { z } from 'zod';
|
|
2
2
|
import { ProxyClient } from './internal/ProxyClient';
|
|
3
3
|
import { responseStringify } from './internal/utils';
|
|
4
4
|
import { cameraStreamSchema } from './types/CamStreamerAPI';
|
|
@@ -11,28 +11,42 @@ export class CamStreamerAPI {
|
|
|
11
11
|
getClient(proxyParams) {
|
|
12
12
|
return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
|
|
13
13
|
}
|
|
14
|
+
async wsAuthorization(options) {
|
|
15
|
+
const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
|
|
16
|
+
if (res.status !== 200) {
|
|
17
|
+
throw new Error(`Server error on ws authorization: ${res.message}`);
|
|
18
|
+
}
|
|
19
|
+
return z.string().parse(res.data);
|
|
20
|
+
}
|
|
21
|
+
async getUtcTime(options) {
|
|
22
|
+
const res = await this._getJson(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
|
|
23
|
+
if (res.status !== 200) {
|
|
24
|
+
throw new Error(`Server error on get UTC time: ${res.message}`);
|
|
25
|
+
}
|
|
26
|
+
return z.number().parse(res.data);
|
|
27
|
+
}
|
|
14
28
|
async getStreamList(options) {
|
|
15
|
-
const
|
|
16
|
-
const list = z.record(z.string(), cameraStreamSchema).parse(
|
|
17
|
-
const
|
|
29
|
+
const res = await this._getJson(`${BASE_PATH}/stream/list.cgi`, undefined, options);
|
|
30
|
+
const list = z.record(z.string(), cameraStreamSchema).parse(res.data);
|
|
31
|
+
const streamList = {};
|
|
18
32
|
for (const [key, data] of Object.entries(list)) {
|
|
19
33
|
const streamId = parseInt(key);
|
|
20
|
-
|
|
34
|
+
streamList[streamId] = parseCameraStreamResponse(data);
|
|
21
35
|
}
|
|
22
|
-
return
|
|
36
|
+
return streamList;
|
|
23
37
|
}
|
|
24
38
|
async getStream(streamId, options) {
|
|
25
|
-
const
|
|
26
|
-
const cameraData = cameraStreamSchema.parse(
|
|
39
|
+
const res = await this._getJson(`${BASE_PATH}/stream/get.cgi`, { stream_id: streamId }, options);
|
|
40
|
+
const cameraData = cameraStreamSchema.parse(res.data);
|
|
27
41
|
return parseCameraStreamResponse(cameraData);
|
|
28
42
|
}
|
|
29
43
|
async getStreamParameter(streamId, paramName, options) {
|
|
30
|
-
const
|
|
31
|
-
return
|
|
44
|
+
const res = await this._getJson(`${BASE_PATH}/stream/get.cgi`, { stream_id: streamId }, options);
|
|
45
|
+
return z.string().parse(res.data[paramName]);
|
|
32
46
|
}
|
|
33
47
|
async setStream(streamId, params, options) {
|
|
34
48
|
const { streamDelay, startTime, stopTime, ...rest } = params;
|
|
35
|
-
return await this.
|
|
49
|
+
return await this._getJson(`${BASE_PATH}/stream/set.cgi`, {
|
|
36
50
|
stream_id: streamId,
|
|
37
51
|
streamDelay: streamDelay ?? '',
|
|
38
52
|
startTime: startTime ?? null,
|
|
@@ -41,31 +55,17 @@ export class CamStreamerAPI {
|
|
|
41
55
|
}, options);
|
|
42
56
|
}
|
|
43
57
|
async setStreamParameter(streamId, paramName, value, options) {
|
|
44
|
-
return await this.
|
|
58
|
+
return await this._getJson(`${BASE_PATH}/stream/set.cgi`, { stream_id: streamId, [paramName]: value }, options);
|
|
45
59
|
}
|
|
46
60
|
async isStreaming(streamId, options) {
|
|
47
|
-
const
|
|
48
|
-
return
|
|
61
|
+
const res = await this._getJson(`${BASE_PATH}/get_streamstat.cgi`, { stream_id: streamId }, options);
|
|
62
|
+
return res.data.is_streaming === 1;
|
|
49
63
|
}
|
|
50
64
|
async deleteStream(streamId, options) {
|
|
51
|
-
const res = await this.
|
|
65
|
+
const res = await this._getJson(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
|
|
52
66
|
return res.data.status === 200;
|
|
53
67
|
}
|
|
54
|
-
async
|
|
55
|
-
const res = await this.get(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
|
|
56
|
-
if (res.status !== 200) {
|
|
57
|
-
throw new Error(`Server error on ws authorization: ${res.message}`);
|
|
58
|
-
}
|
|
59
|
-
return res.data;
|
|
60
|
-
}
|
|
61
|
-
async getUtcTime(options) {
|
|
62
|
-
const res = await this.get(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
|
|
63
|
-
if (res.status !== 200) {
|
|
64
|
-
throw new Error(`Server error on get UTC time: ${res.message}`);
|
|
65
|
-
}
|
|
66
|
-
return res.data;
|
|
67
|
-
}
|
|
68
|
-
async get(path, parameters, options) {
|
|
68
|
+
async _getJson(path, parameters, options) {
|
|
69
69
|
const agent = this.getClient(options?.proxyParams);
|
|
70
70
|
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
71
71
|
if (res.ok) {
|