camstreamerlib 4.0.0-beta.4 → 4.0.0-beta.40
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/README.md +112 -0
- package/cjs/CamOverlayAPI.js +135 -92
- package/cjs/CamScripterAPI.js +52 -42
- package/cjs/CamStreamerAPI.js +83 -39
- package/cjs/CamSwitcherAPI.js +141 -123
- package/cjs/CamSwitcherEvents.js +4 -60
- package/cjs/PlaneTrackerAPI.js +200 -0
- package/cjs/VapixAPI.js +323 -233
- package/cjs/{CreatePackage.js → bin/CreatePackage.js} +22 -19
- package/cjs/errors/errors.js +64 -1
- package/cjs/index.js +17 -4
- package/cjs/internal/ProxyClient.js +28 -32
- package/cjs/internal/WsEvents.js +72 -0
- package/cjs/internal/types.js +2 -0
- package/cjs/internal/utils.js +22 -3
- package/cjs/{CamOverlayDrawingAPI.js → node/CamOverlayDrawingAPI.js} +7 -4
- package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/Frame.js +33 -0
- package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/Painter.js +5 -17
- package/cjs/node/CamOverlayPainter/ResourceManager.js +72 -0
- package/cjs/{CamScripterAPICameraEventsGenerator.js → node/CamScripterAPICameraEventsGenerator.js} +7 -4
- package/cjs/node/DefaultClient.js +10 -12
- package/cjs/{internal → node}/Digest.js +8 -5
- package/cjs/node/HttpRequestSender.js +14 -4
- package/cjs/node/HttpServer.js +15 -12
- package/cjs/{VapixEvents.js → node/VapixEvents.js} +1 -1
- package/cjs/node/WsClient.js +12 -9
- package/cjs/node/events/AxisCameraStationEvents.js +53 -0
- package/cjs/node/events/GenetecAgent.js +123 -0
- package/cjs/node/index.js +38 -5
- package/cjs/types/CamOverlayAPI/CamOverlayAPI.js +92 -0
- package/cjs/types/CamOverlayAPI/accuweatherSchema.js +47 -0
- package/cjs/types/CamOverlayAPI/customGraphicsSchema.js +72 -0
- package/cjs/types/CamOverlayAPI/imagesSchema.js +9 -0
- package/cjs/types/CamOverlayAPI/index.js +27 -0
- package/cjs/types/CamOverlayAPI/infotickerSchema.js +26 -0
- package/cjs/types/CamOverlayAPI/pipSchema.js +39 -0
- package/cjs/types/CamOverlayAPI/ptzCompassSchema.js +25 -0
- package/cjs/types/CamOverlayAPI/ptzSchema.js +12 -0
- package/cjs/types/CamOverlayAPI/scoreBoardSchema.js +132 -0
- package/cjs/types/CamOverlayAPI/screenSharingSchema.js +8 -0
- package/cjs/types/CamOverlayAPI/serviceCommonTypes.js +91 -0
- package/cjs/types/CamOverlayAPI/webCameraSharingSchema.js +8 -0
- package/cjs/types/CamOverlayDrawingAPI.js +2 -0
- package/cjs/types/CamOverlayPainter.js +14 -0
- package/cjs/types/CamScripterAPI.js +22 -7
- package/cjs/types/CamScripterAPICameraEventsGenerator.js +2 -0
- package/cjs/types/CamStreamerAPI.js +34 -3
- package/cjs/types/CamSwitcherAPI.js +38 -1
- package/cjs/types/CamSwitcherEvents.js +8 -0
- package/cjs/types/GenetecAgent.js +31 -0
- package/cjs/types/PlaneTrackerAPI.js +281 -0
- package/cjs/types/VapixAPI.js +71 -13
- package/cjs/types/VapixEvents.js +2 -0
- package/cjs/web/DefaultClient.js +22 -10
- package/cjs/web/WsClient.js +3 -3
- package/esm/CamOverlayAPI.js +131 -88
- package/esm/CamScripterAPI.js +48 -38
- package/esm/CamStreamerAPI.js +81 -38
- package/esm/CamSwitcherAPI.js +137 -119
- package/esm/CamSwitcherEvents.js +5 -61
- package/esm/PlaneTrackerAPI.js +196 -0
- package/esm/VapixAPI.js +315 -225
- package/esm/{CreatePackage.js → bin/CreatePackage.js} +3 -3
- package/esm/errors/errors.js +54 -0
- package/esm/index.js +12 -3
- package/esm/internal/ProxyClient.js +28 -32
- package/esm/internal/WsEvents.js +68 -0
- package/esm/internal/utils.js +17 -1
- package/esm/{CamOverlayDrawingAPI.js → node/CamOverlayDrawingAPI.js} +2 -2
- package/esm/{CamOverlayPainter → node/CamOverlayPainter}/Frame.js +33 -0
- package/esm/{CamOverlayPainter → node/CamOverlayPainter}/Painter.js +2 -13
- package/esm/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.js +7 -5
- package/esm/{CamScripterAPICameraEventsGenerator.js → node/CamScripterAPICameraEventsGenerator.js} +2 -2
- package/esm/node/DefaultClient.js +10 -12
- package/esm/{internal → node}/Digest.js +1 -1
- package/esm/node/HttpRequestSender.js +14 -4
- package/esm/node/HttpServer.js +5 -5
- package/esm/{VapixEvents.js → node/VapixEvents.js} +1 -1
- package/esm/node/WsClient.js +3 -3
- package/esm/{events → node/events}/AxisCameraStationEvents.js +18 -13
- package/esm/node/events/GenetecAgent.js +119 -0
- package/esm/node/index.js +17 -2
- package/esm/types/CamOverlayAPI/CamOverlayAPI.js +76 -0
- package/esm/types/CamOverlayAPI/accuweatherSchema.js +44 -0
- package/esm/types/CamOverlayAPI/customGraphicsSchema.js +69 -0
- package/esm/types/CamOverlayAPI/imagesSchema.js +6 -0
- package/esm/types/CamOverlayAPI/index.js +11 -0
- package/esm/types/CamOverlayAPI/infotickerSchema.js +23 -0
- package/esm/types/CamOverlayAPI/pipSchema.js +36 -0
- package/esm/types/CamOverlayAPI/ptzCompassSchema.js +22 -0
- package/esm/types/CamOverlayAPI/ptzSchema.js +9 -0
- package/esm/types/CamOverlayAPI/scoreBoardSchema.js +129 -0
- package/esm/types/CamOverlayAPI/screenSharingSchema.js +5 -0
- package/esm/types/CamOverlayAPI/serviceCommonTypes.js +88 -0
- package/esm/types/CamOverlayAPI/webCameraSharingSchema.js +5 -0
- package/esm/types/CamOverlayPainter.js +11 -0
- package/esm/types/CamScripterAPI.js +21 -6
- package/esm/types/CamScripterAPICameraEventsGenerator.js +1 -0
- package/esm/types/CamStreamerAPI.js +33 -2
- package/esm/types/CamSwitcherAPI.js +38 -1
- package/esm/types/CamSwitcherEvents.js +8 -0
- package/esm/types/GenetecAgent.js +28 -0
- package/esm/types/PlaneTrackerAPI.js +278 -0
- package/esm/types/VapixAPI.js +70 -12
- package/esm/types/VapixEvents.js +1 -0
- package/esm/web/DefaultClient.js +22 -10
- package/esm/web/WsClient.js +3 -3
- package/package.json +30 -12
- package/types/CamOverlayAPI.d.ts +865 -0
- package/types/CamScripterAPI.d.ts +47 -0
- package/types/CamStreamerAPI.d.ts +64 -0
- package/types/CamSwitcherAPI.d.ts +167 -0
- package/types/CamSwitcherEvents.d.ts +8 -0
- package/types/PlaneTrackerAPI.d.ts +226 -0
- package/types/VapixAPI.d.ts +118 -0
- package/types/bin/CreatePackage.d.ts +1 -0
- package/{esm → types}/errors/errors.d.ts +28 -1
- package/types/index.d.ts +20 -0
- package/types/internal/ProxyClient.d.ts +10 -0
- package/types/internal/WsEvents.d.ts +41 -0
- package/types/internal/types.d.ts +45 -0
- package/{cjs → types}/internal/utils.d.ts +4 -1
- package/{cjs → types}/internal/versionCompare.d.ts +2 -2
- package/types/node/CamOverlayDrawingAPI.d.ts +41 -0
- package/{esm → types/node}/CamOverlayPainter/Frame.d.ts +8 -37
- package/{cjs → types/node}/CamOverlayPainter/Painter.d.ts +5 -21
- package/types/node/CamOverlayPainter/ResourceManager.d.ts +15 -0
- package/types/node/CamScripterAPICameraEventsGenerator.d.ts +31 -0
- package/types/node/DefaultClient.d.ts +16 -0
- package/{esm → types}/node/HttpRequestSender.d.ts +1 -0
- package/{cjs → types}/node/HttpServer.d.ts +2 -2
- package/types/node/VapixEvents.d.ts +16 -0
- package/{cjs → types}/node/WsClient.d.ts +3 -2
- package/types/node/events/AxisCameraStationEvents.d.ts +12 -0
- package/types/node/events/GenetecAgent.d.ts +16 -0
- package/types/node/index.d.ts +17 -0
- package/types/types/CamOverlayAPI/CamOverlayAPI.d.ts +4321 -0
- package/types/types/CamOverlayAPI/accuweatherSchema.d.ts +84 -0
- package/types/types/CamOverlayAPI/customGraphicsSchema.d.ts +700 -0
- package/types/types/CamOverlayAPI/imagesSchema.d.ts +95 -0
- package/types/types/CamOverlayAPI/index.d.ts +11 -0
- package/types/types/CamOverlayAPI/infotickerSchema.d.ts +96 -0
- package/types/types/CamOverlayAPI/pipSchema.d.ts +125 -0
- package/types/types/CamOverlayAPI/ptzCompassSchema.d.ts +93 -0
- package/types/types/CamOverlayAPI/ptzSchema.d.ts +118 -0
- package/types/types/CamOverlayAPI/scoreBoardSchema.d.ts +357 -0
- package/types/types/CamOverlayAPI/screenSharingSchema.d.ts +58 -0
- package/types/types/CamOverlayAPI/serviceCommonTypes.d.ts +145 -0
- package/types/types/CamOverlayAPI/webCameraSharingSchema.d.ts +58 -0
- package/types/types/CamOverlayDrawingAPI.d.ts +48 -0
- package/types/types/CamOverlayPainter.d.ts +76 -0
- package/types/types/CamScripterAPI.d.ts +130 -0
- package/types/types/CamScripterAPICameraEventsGenerator.d.ts +45 -0
- package/types/types/CamStreamerAPI.d.ts +272 -0
- package/{esm → types}/types/CamSwitcherAPI.d.ts +115 -36
- package/{cjs → types}/types/CamSwitcherEvents.d.ts +77 -0
- package/{esm/events → types/types}/GenetecAgent.d.ts +47 -47
- package/types/types/PlaneTrackerAPI.d.ts +877 -0
- package/{cjs → types}/types/VapixAPI.d.ts +647 -465
- package/types/types/VapixEvents.d.ts +15 -0
- package/{esm → types}/types/common.d.ts +15 -5
- package/types/web/DefaultClient.d.ts +6 -0
- package/cjs/CamOverlayAPI.d.ts +0 -31
- package/cjs/CamOverlayDrawingAPI.d.ts +0 -86
- package/cjs/CamOverlayPainter/Frame.d.ts +0 -96
- package/cjs/CamOverlayPainter/ResourceManager.d.ts +0 -14
- package/cjs/CamOverlayPainter/ResourceManager.js +0 -46
- package/cjs/CamScripterAPI.d.ts +0 -19
- package/cjs/CamScripterAPICameraEventsGenerator.d.ts +0 -74
- package/cjs/CamStreamerAPI.d.ts +0 -16
- package/cjs/CamSwitcherAPI.d.ts +0 -48
- package/cjs/CamSwitcherEvents.d.ts +0 -18
- package/cjs/VapixAPI.d.ts +0 -66
- package/cjs/VapixEvents.d.ts +0 -43
- package/cjs/errors/errors.d.ts +0 -34
- package/cjs/events/AxisCameraStationEvents.d.ts +0 -9
- package/cjs/events/AxisCameraStationEvents.js +0 -48
- package/cjs/events/GenetecAgent.d.ts +0 -174
- package/cjs/events/GenetecAgent.js +0 -123
- package/cjs/index.d.ts +0 -11
- package/cjs/internal/ProxyClient.d.ts +0 -11
- package/cjs/internal/common.d.ts +0 -39
- package/cjs/internal/common.js +0 -27
- package/cjs/node/DefaultClient.d.ts +0 -15
- package/cjs/node/HttpRequestSender.d.ts +0 -28
- package/cjs/node/WsEventClient.d.ts +0 -13
- package/cjs/node/WsEventClient.js +0 -22
- package/cjs/types/CamOverlayAPI.d.ts +0 -188
- package/cjs/types/CamOverlayAPI.js +0 -47
- package/cjs/types/CamScripterAPI.d.ts +0 -67
- package/cjs/types/CamStreamerAPI.d.ts +0 -139
- package/cjs/types/CamSwitcherAPI.d.ts +0 -814
- package/cjs/types/common.d.ts +0 -37
- package/cjs/web/DefaultClient.d.ts +0 -6
- package/cjs/web/index.d.ts +0 -2
- package/esm/CamOverlayAPI.d.ts +0 -31
- package/esm/CamOverlayDrawingAPI.d.ts +0 -86
- package/esm/CamOverlayPainter/Painter.d.ts +0 -48
- package/esm/CamOverlayPainter/ResourceManager.d.ts +0 -14
- package/esm/CamScripterAPI.d.ts +0 -19
- package/esm/CamScripterAPICameraEventsGenerator.d.ts +0 -74
- package/esm/CamStreamerAPI.d.ts +0 -16
- package/esm/CamSwitcherAPI.d.ts +0 -48
- package/esm/CamSwitcherEvents.d.ts +0 -18
- package/esm/VapixAPI.d.ts +0 -66
- package/esm/VapixEvents.d.ts +0 -43
- package/esm/events/AxisCameraStationEvents.d.ts +0 -9
- package/esm/events/GenetecAgent.js +0 -119
- package/esm/index.d.ts +0 -11
- package/esm/internal/Digest.d.ts +0 -4
- package/esm/internal/ProxyClient.d.ts +0 -11
- package/esm/internal/common.d.ts +0 -39
- package/esm/internal/common.js +0 -20
- package/esm/internal/constants.d.ts +0 -1
- package/esm/internal/transformers.d.ts +0 -5
- package/esm/internal/utils.d.ts +0 -11
- package/esm/internal/versionCompare.d.ts +0 -6
- package/esm/node/DefaultClient.d.ts +0 -15
- package/esm/node/HttpServer.d.ts +0 -21
- package/esm/node/WsClient.d.ts +0 -39
- package/esm/node/WsEventClient.d.ts +0 -13
- package/esm/node/WsEventClient.js +0 -18
- package/esm/node/index.d.ts +0 -2
- package/esm/types/CamOverlayAPI.d.ts +0 -188
- package/esm/types/CamOverlayAPI.js +0 -44
- package/esm/types/CamScripterAPI.d.ts +0 -67
- package/esm/types/CamStreamerAPI.d.ts +0 -139
- package/esm/types/CamSwitcherEvents.d.ts +0 -491
- package/esm/types/VapixAPI.d.ts +0 -1683
- package/esm/web/DefaultClient.d.ts +0 -6
- package/esm/web/WsClient.d.ts +0 -13
- package/esm/web/index.d.ts +0 -2
- /package/{cjs/CreatePackage.d.ts → esm/internal/types.js} +0 -0
- /package/esm/{CreatePackage.d.ts → types/CamOverlayDrawingAPI.js} +0 -0
- /package/{cjs → types}/internal/constants.d.ts +0 -0
- /package/{cjs → types}/internal/transformers.d.ts +0 -0
- /package/{cjs/internal → types/node}/Digest.d.ts +0 -0
- /package/{cjs → types}/web/WsClient.d.ts +0 -0
- /package/{cjs/node → types/web}/index.d.ts +0 -0
package/esm/CamOverlayAPI.js
CHANGED
|
@@ -1,65 +1,79 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { fileListSchema, ImageType, serviceSchema, storageSchema, } from './types/CamOverlayAPI';
|
|
4
|
-
import { ParsingBlobError, ServiceNotFoundError } from './errors/errors';
|
|
1
|
+
import { paramToUrl, responseStringify } from './internal/utils';
|
|
2
|
+
import { ParsingBlobError, ServiceNotFoundError, StorageDataFetchError } from './errors/errors';
|
|
5
3
|
import { networkCameraListSchema } from './types/common';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { ProxyClient } from './internal/ProxyClient';
|
|
6
|
+
import { fileListSchema, ImageType, storageDataListSchema, serviceListSchema, servicesSchema, wsResponseSchema, } from './types/CamOverlayAPI';
|
|
7
|
+
const BASE_PATH = '/local/camoverlay/api';
|
|
6
8
|
export class CamOverlayAPI {
|
|
7
9
|
client;
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
constructor(client) {
|
|
11
|
+
this.client = client;
|
|
12
|
+
}
|
|
13
|
+
static getBasePath = () => BASE_PATH;
|
|
14
|
+
static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
|
|
15
|
+
static getFilePreviewPath = (path) => `${BASE_PATH}/image.cgi?path=${encodeURIComponent(path)}`;
|
|
16
|
+
getClient(proxyParams) {
|
|
17
|
+
return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
|
|
18
|
+
}
|
|
19
|
+
async checkCameraTime(options) {
|
|
20
|
+
const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
|
|
21
|
+
return z.boolean().parse(res.state);
|
|
22
|
+
}
|
|
23
|
+
async getNetworkCameraList(options) {
|
|
24
|
+
const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
|
|
25
|
+
return networkCameraListSchema.parse(res.camera_list);
|
|
26
|
+
}
|
|
27
|
+
async wsAuthorization(options) {
|
|
28
|
+
const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
|
|
29
|
+
return wsResponseSchema.parse(res).message;
|
|
30
|
+
}
|
|
31
|
+
async getMjpegStreamImage(mjpegUrl, options) {
|
|
32
|
+
return await this._getBlob(`${BASE_PATH}/fetch_mjpeg_image.cgi`, { mjpeg_url: decodeURIComponent(mjpegUrl) }, options);
|
|
33
|
+
}
|
|
34
|
+
async listFiles(fileType, options) {
|
|
35
|
+
const res = await this._getJson(`${BASE_PATH}/upload_${fileType}.cgi`, { action: 'list' }, options);
|
|
36
|
+
return fileListSchema.parse(res.list);
|
|
37
|
+
}
|
|
38
|
+
async uploadFile(fileType, formData, storage, options) {
|
|
39
|
+
await this._post(`${BASE_PATH}/upload_${fileType}.cgi`, formData, {
|
|
40
|
+
action: 'upload',
|
|
41
|
+
storage: storage,
|
|
42
|
+
}, options);
|
|
43
|
+
}
|
|
44
|
+
async removeFile(fileType, fileParams, options) {
|
|
45
|
+
await this._postUrlEncoded(`${BASE_PATH}/upload_${fileType}.cgi`, {
|
|
46
|
+
action: 'remove',
|
|
47
|
+
...fileParams,
|
|
48
|
+
}, options, undefined);
|
|
49
|
+
}
|
|
50
|
+
async getFileStorage(fileType, options) {
|
|
51
|
+
const res = await this._getJson(`${BASE_PATH}/upload_${fileType}.cgi`, { action: 'get_storage' }, options);
|
|
52
|
+
if (res.code !== 200) {
|
|
53
|
+
throw new StorageDataFetchError(res);
|
|
11
54
|
}
|
|
12
|
-
|
|
13
|
-
this.client = new DefaultClient(options);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async checkCameraTime() {
|
|
17
|
-
const cameraTime = await this.get('/local/camoverlay/api/camera_time.cgi');
|
|
18
|
-
return cameraTime.state;
|
|
19
|
-
}
|
|
20
|
-
async getNetworkCameraList() {
|
|
21
|
-
const response = await this.get('/local/camoverlay/api/network_camera_list.cgi');
|
|
22
|
-
return networkCameraListSchema.parse(response.camera_list);
|
|
23
|
-
}
|
|
24
|
-
async wsAutoratization() {
|
|
25
|
-
const response = await this.get(`/local/camoverlay/api/ws_authorization.cgi`);
|
|
26
|
-
return response.data;
|
|
27
|
-
}
|
|
28
|
-
async getMjpegStreamImage(mjpegUrl) {
|
|
29
|
-
const res = await this.get(`/local/camoverlay/api/fetch_mjpeg_image.cgi?mjpeg_url=${encodeURIComponent(decodeURIComponent(mjpegUrl))}`);
|
|
30
|
-
return await this.parseBlobResponse(res);
|
|
55
|
+
return storageDataListSchema.parse(res.list);
|
|
31
56
|
}
|
|
32
|
-
async
|
|
33
|
-
|
|
34
|
-
return fileListSchema.parse(files.list);
|
|
57
|
+
async getFilePreviewFromCamera(path, options) {
|
|
58
|
+
return await this._getBlob(CamOverlayAPI.getFilePreviewPath(path), undefined, options);
|
|
35
59
|
}
|
|
36
|
-
async
|
|
37
|
-
|
|
38
|
-
formData.append('target', 'SD0');
|
|
39
|
-
formData.append('uploadedFile[]', file, fileName);
|
|
40
|
-
const path = `/local/camoverlay/api/upload_${fileType}.cgi?action=upload`;
|
|
41
|
-
await this.post(path, formData);
|
|
60
|
+
async updateInfoticker(serviceId, text, options) {
|
|
61
|
+
await this._getJson(`${BASE_PATH}/infoticker.cgi`, { service_id: serviceId, text: text }, options);
|
|
42
62
|
}
|
|
43
|
-
async
|
|
44
|
-
|
|
45
|
-
await this.post(path, JSON.stringify(file));
|
|
63
|
+
async setEnabled(serviceId, enabled, options) {
|
|
64
|
+
await this._post(`${BASE_PATH}/enabled.cgi`, '', { [`id_${serviceId}`]: enabled ? 1 : 0 }, options);
|
|
46
65
|
}
|
|
47
|
-
async
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
async setEnabled(serviceID, enabled) {
|
|
55
|
-
await this.post(`/local/camoverlay/api/enabled.cgi?id_${serviceID}=${enabled ? 1 : 0}`, '');
|
|
56
|
-
}
|
|
57
|
-
async isEnabled(serviceID) {
|
|
58
|
-
const res = await this.client.get('/local/camoverlay/api/services.cgi?action=get');
|
|
66
|
+
async isEnabled(serviceId, options) {
|
|
67
|
+
const agent = this.getClient(options?.proxyParams);
|
|
68
|
+
const res = await agent.get({
|
|
69
|
+
path: `${BASE_PATH}/services.cgi`,
|
|
70
|
+
parameters: { action: 'get' },
|
|
71
|
+
timeout: options?.timeout,
|
|
72
|
+
});
|
|
59
73
|
if (res.ok) {
|
|
60
74
|
const data = JSON.parse(await res.text());
|
|
61
75
|
for (const service of data.services) {
|
|
62
|
-
if (service.id ===
|
|
76
|
+
if (service.id === serviceId) {
|
|
63
77
|
return service.enabled === 1;
|
|
64
78
|
}
|
|
65
79
|
}
|
|
@@ -69,29 +83,30 @@ export class CamOverlayAPI {
|
|
|
69
83
|
throw new Error(await responseStringify(res));
|
|
70
84
|
}
|
|
71
85
|
}
|
|
72
|
-
async getSingleService(serviceId) {
|
|
73
|
-
const
|
|
86
|
+
async getSingleService(serviceId, options) {
|
|
87
|
+
const res = await this._getJson(`${BASE_PATH}/services.cgi`, {
|
|
74
88
|
action: 'get',
|
|
75
|
-
service_id: serviceId
|
|
76
|
-
});
|
|
77
|
-
return
|
|
89
|
+
service_id: serviceId,
|
|
90
|
+
}, options);
|
|
91
|
+
return servicesSchema.parse(res);
|
|
78
92
|
}
|
|
79
|
-
async getServices() {
|
|
80
|
-
const
|
|
81
|
-
|
|
93
|
+
async getServices(options) {
|
|
94
|
+
const res = await this._getJson(`${BASE_PATH}/services.cgi`, { action: 'get' }, options);
|
|
95
|
+
const services = serviceListSchema.parse(res).services;
|
|
96
|
+
return services;
|
|
82
97
|
}
|
|
83
|
-
async updateSingleService(
|
|
84
|
-
|
|
85
|
-
await this.post(path, JSON.stringify(serviceJson), {
|
|
98
|
+
async updateSingleService(service, options) {
|
|
99
|
+
await this._postJsonEncoded(`${BASE_PATH}/services.cgi`, JSON.stringify(service), {
|
|
86
100
|
action: 'set',
|
|
87
|
-
service_id:
|
|
88
|
-
});
|
|
101
|
+
service_id: service.id,
|
|
102
|
+
}, options, undefined);
|
|
89
103
|
}
|
|
90
|
-
async updateServices(
|
|
91
|
-
|
|
92
|
-
|
|
104
|
+
async updateServices(services, options) {
|
|
105
|
+
await this._postJsonEncoded(`${BASE_PATH}/services.cgi`, JSON.stringify({ services: services }), {
|
|
106
|
+
action: 'set',
|
|
107
|
+
}, options, undefined);
|
|
93
108
|
}
|
|
94
|
-
updateCGText(
|
|
109
|
+
updateCGText(serviceId, fields, options) {
|
|
95
110
|
const params = {};
|
|
96
111
|
for (const field of fields) {
|
|
97
112
|
const name = field.field_name;
|
|
@@ -100,51 +115,59 @@ export class CamOverlayAPI {
|
|
|
100
115
|
params[`${name}_color`] = field.color;
|
|
101
116
|
}
|
|
102
117
|
}
|
|
103
|
-
return this.promiseCGUpdate(
|
|
118
|
+
return this.promiseCGUpdate(serviceId, 'update_text', params, undefined, undefined, options);
|
|
104
119
|
}
|
|
105
|
-
updateCGImagePos(
|
|
120
|
+
updateCGImagePos(serviceId, coordinates = '', x = 0, y = 0, options) {
|
|
106
121
|
const params = {
|
|
107
122
|
coord_system: coordinates,
|
|
108
123
|
pos_x: x,
|
|
109
124
|
pos_y: y,
|
|
110
125
|
};
|
|
111
|
-
return this.promiseCGUpdate(
|
|
126
|
+
return this.promiseCGUpdate(serviceId, 'update_image', params, undefined, undefined, options);
|
|
112
127
|
}
|
|
113
|
-
updateCGImage(
|
|
128
|
+
updateCGImage(serviceId, path, coordinates = '', x = 0, y = 0, options) {
|
|
114
129
|
const params = {
|
|
115
130
|
coord_system: coordinates,
|
|
116
131
|
pos_x: x,
|
|
117
132
|
pos_y: y,
|
|
118
133
|
image: path,
|
|
119
134
|
};
|
|
120
|
-
return this.promiseCGUpdate(
|
|
135
|
+
return this.promiseCGUpdate(serviceId, 'update_image', params, undefined, undefined, options);
|
|
121
136
|
}
|
|
122
|
-
updateCGImageFromData(
|
|
137
|
+
updateCGImageFromData(serviceId, imageType, imageData, coordinates = '', x = 0, y = 0, options) {
|
|
123
138
|
const contentType = imageType === ImageType.PNG ? 'image/png' : 'image/jpeg';
|
|
124
139
|
const params = {
|
|
125
140
|
coord_system: coordinates,
|
|
126
141
|
pos_x: x,
|
|
127
142
|
pos_y: y,
|
|
128
143
|
};
|
|
129
|
-
return this.promiseCGUpdate(
|
|
144
|
+
return this.promiseCGUpdate(serviceId, 'update_image', params, contentType, imageData, options);
|
|
130
145
|
}
|
|
131
|
-
async promiseCGUpdate(
|
|
132
|
-
const path =
|
|
146
|
+
async promiseCGUpdate(serviceId, action, params = {}, contentType, data, options) {
|
|
147
|
+
const path = `${BASE_PATH}/customGraphics.cgi`;
|
|
133
148
|
let headers = {};
|
|
134
|
-
if (contentType !== undefined && data) {
|
|
149
|
+
if (contentType !== undefined && data !== undefined) {
|
|
135
150
|
headers = { 'Content-Type': contentType };
|
|
136
151
|
}
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
152
|
+
const agent = this.getClient(options?.proxyParams);
|
|
153
|
+
const res = await agent.post({
|
|
154
|
+
path,
|
|
155
|
+
data: data ?? '',
|
|
156
|
+
parameters: {
|
|
157
|
+
action: action,
|
|
158
|
+
service_id: serviceId.toString(),
|
|
159
|
+
...params,
|
|
160
|
+
},
|
|
161
|
+
headers,
|
|
162
|
+
timeout: options?.timeout,
|
|
163
|
+
});
|
|
142
164
|
if (!res.ok) {
|
|
143
165
|
throw new Error(await responseStringify(res));
|
|
144
166
|
}
|
|
145
167
|
}
|
|
146
|
-
async
|
|
147
|
-
const
|
|
168
|
+
async _getJson(path, parameters, options) {
|
|
169
|
+
const agent = this.getClient(options?.proxyParams);
|
|
170
|
+
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
148
171
|
if (res.ok) {
|
|
149
172
|
return await res.json();
|
|
150
173
|
}
|
|
@@ -152,8 +175,9 @@ export class CamOverlayAPI {
|
|
|
152
175
|
throw new Error(await responseStringify(res));
|
|
153
176
|
}
|
|
154
177
|
}
|
|
155
|
-
async
|
|
156
|
-
const
|
|
178
|
+
async _post(path, data, parameters, options, headers) {
|
|
179
|
+
const agent = this.getClient(options?.proxyParams);
|
|
180
|
+
const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
|
|
157
181
|
if (res.ok) {
|
|
158
182
|
return await res.json();
|
|
159
183
|
}
|
|
@@ -161,12 +185,31 @@ export class CamOverlayAPI {
|
|
|
161
185
|
throw new Error(await responseStringify(res));
|
|
162
186
|
}
|
|
163
187
|
}
|
|
188
|
+
async _getBlob(path, parameters, options) {
|
|
189
|
+
const agent = this.getClient(options?.proxyParams);
|
|
190
|
+
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
191
|
+
if (res.ok) {
|
|
192
|
+
return await this.parseBlobResponse(res);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
throw new Error(await responseStringify(res));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
164
198
|
async parseBlobResponse(response) {
|
|
165
199
|
try {
|
|
166
|
-
return await response.blob();
|
|
200
|
+
return (await response.blob());
|
|
167
201
|
}
|
|
168
202
|
catch (err) {
|
|
169
203
|
throw new ParsingBlobError(err);
|
|
170
204
|
}
|
|
171
205
|
}
|
|
206
|
+
async _postUrlEncoded(path, parameters, options, headers) {
|
|
207
|
+
const data = paramToUrl(parameters);
|
|
208
|
+
const baseHeaders = { 'Content-Type': 'application/x-www-form-urlencoded' };
|
|
209
|
+
return this._post(path, data, undefined, options, { ...baseHeaders, ...headers });
|
|
210
|
+
}
|
|
211
|
+
async _postJsonEncoded(path, data, parameters, options, headers) {
|
|
212
|
+
const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
|
|
213
|
+
return this._post(path, data, parameters, options, { ...baseHeaders, ...headers });
|
|
214
|
+
}
|
|
172
215
|
}
|
package/esm/CamScripterAPI.js
CHANGED
|
@@ -1,52 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { packageInfoListSchema,
|
|
1
|
+
import { ProxyClient } from './internal/ProxyClient';
|
|
2
|
+
import { responseStringify } from './internal/utils';
|
|
3
|
+
import { cameraTimeResponseSchema, nodeStateSchema, packageInfoListSchema, cameraStorageSchema, } from './types/CamScripterAPI';
|
|
4
4
|
import { networkCameraListSchema } from './types/common';
|
|
5
|
-
|
|
5
|
+
const BASE_PATH = '/local/camscripter';
|
|
6
|
+
export class CamScripterAPI {
|
|
6
7
|
client;
|
|
7
|
-
constructor(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
|
|
12
|
+
getClient(proxyParams) {
|
|
13
|
+
return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
|
|
14
14
|
}
|
|
15
|
-
async checkCameraTime() {
|
|
16
|
-
|
|
15
|
+
async checkCameraTime(options) {
|
|
16
|
+
const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
|
|
17
|
+
return cameraTimeResponseSchema.parse(res).state;
|
|
17
18
|
}
|
|
18
|
-
async
|
|
19
|
-
const
|
|
20
|
-
return
|
|
19
|
+
async getNetworkCameraList(options) {
|
|
20
|
+
const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
|
|
21
|
+
return networkCameraListSchema.parse(res.camera_list);
|
|
21
22
|
}
|
|
22
|
-
async
|
|
23
|
-
const
|
|
24
|
-
return
|
|
23
|
+
async getStorageInfo(options) {
|
|
24
|
+
const res = await this._getJson(`${BASE_PATH}/package/get_storage.cgi`, undefined, options);
|
|
25
|
+
return cameraStorageSchema.parse(res);
|
|
25
26
|
}
|
|
26
|
-
async getPackageList() {
|
|
27
|
-
const
|
|
28
|
-
return packageInfoListSchema.parse(
|
|
27
|
+
async getPackageList(options) {
|
|
28
|
+
const res = await this._getJson(`${BASE_PATH}/package/list.cgi`, undefined, options);
|
|
29
|
+
return packageInfoListSchema.parse(res);
|
|
29
30
|
}
|
|
30
|
-
async installPackages(formData, storage) {
|
|
31
|
-
await this.
|
|
31
|
+
async installPackages(formData, storage, options) {
|
|
32
|
+
await this._post(`${BASE_PATH}/package/install.cgi`, formData, { storage: storage }, options);
|
|
32
33
|
}
|
|
33
|
-
async uninstallPackage(packageId) {
|
|
34
|
-
await this.
|
|
34
|
+
async uninstallPackage(packageId, options) {
|
|
35
|
+
await this._getJson(`${BASE_PATH}/package/remove.cgi`, { package_name: packageId }, options);
|
|
35
36
|
}
|
|
36
|
-
async importSettings(packageId, formData) {
|
|
37
|
-
await this.
|
|
37
|
+
async importSettings(packageId, formData, options) {
|
|
38
|
+
await this._post(`${BASE_PATH}/package/data.cgi`, formData, {
|
|
39
|
+
action: 'IMPORT',
|
|
40
|
+
package_name: packageId,
|
|
41
|
+
}, options);
|
|
38
42
|
}
|
|
39
|
-
async exportSettings(packageId, formData) {
|
|
40
|
-
await this.
|
|
43
|
+
async exportSettings(packageId, formData, options) {
|
|
44
|
+
await this._post(`${BASE_PATH}/package/data.cgi`, formData, {
|
|
45
|
+
action: 'EXPORT',
|
|
46
|
+
package_name: packageId,
|
|
47
|
+
}, options);
|
|
41
48
|
}
|
|
42
|
-
async getNodejsStatus() {
|
|
43
|
-
|
|
49
|
+
async getNodejsStatus(options) {
|
|
50
|
+
const res = await this._getJson(`${BASE_PATH}/diagnostics.cgi`, undefined, options);
|
|
51
|
+
return nodeStateSchema.parse(res);
|
|
44
52
|
}
|
|
45
|
-
async installNodejs(storage) {
|
|
46
|
-
await this.
|
|
53
|
+
async installNodejs(storage, options) {
|
|
54
|
+
await this._getJson(`${BASE_PATH}/node_update.cgi`, { storage: storage }, options);
|
|
47
55
|
}
|
|
48
|
-
async
|
|
49
|
-
const
|
|
56
|
+
async _getJson(path, parameters, options) {
|
|
57
|
+
const agent = this.getClient(options?.proxyParams);
|
|
58
|
+
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
50
59
|
if (res.ok) {
|
|
51
60
|
return await res.json();
|
|
52
61
|
}
|
|
@@ -54,8 +63,9 @@ export class CamOverlayAPI {
|
|
|
54
63
|
throw new Error(await responseStringify(res));
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
|
-
async
|
|
58
|
-
const
|
|
66
|
+
async _post(path, data, parameters, options, headers) {
|
|
67
|
+
const agent = this.getClient(options?.proxyParams);
|
|
68
|
+
const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
|
|
59
69
|
if (res.ok) {
|
|
60
70
|
return await res.json();
|
|
61
71
|
}
|
package/esm/CamStreamerAPI.js
CHANGED
|
@@ -1,56 +1,74 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ProxyClient } from './internal/ProxyClient';
|
|
3
|
+
import { responseStringify } from './internal/utils';
|
|
4
|
+
import { cameraStreamSchema } from './types/CamStreamerAPI';
|
|
5
|
+
import { UtcTimeFetchError, WsAuthorizationError } from './errors/errors';
|
|
6
|
+
const BASE_PATH = '/local/camstreamer';
|
|
4
7
|
export class CamStreamerAPI {
|
|
5
8
|
client;
|
|
6
|
-
constructor(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
constructor(client) {
|
|
10
|
+
this.client = client;
|
|
11
|
+
}
|
|
12
|
+
getClient(proxyParams) {
|
|
13
|
+
return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
|
|
14
|
+
}
|
|
15
|
+
async wsAuthorization(options) {
|
|
16
|
+
const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
|
|
17
|
+
if (res.status !== 200) {
|
|
18
|
+
throw new WsAuthorizationError(res.message);
|
|
9
19
|
}
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
return z.string().parse(res.data);
|
|
21
|
+
}
|
|
22
|
+
async getUtcTime(options) {
|
|
23
|
+
const res = await this._getJson(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
|
|
24
|
+
if (res.status !== 200) {
|
|
25
|
+
throw new UtcTimeFetchError(res.message);
|
|
12
26
|
}
|
|
27
|
+
return z.number().parse(res.data);
|
|
13
28
|
}
|
|
14
|
-
async getStreamList() {
|
|
15
|
-
const
|
|
16
|
-
|
|
29
|
+
async getStreamList(options) {
|
|
30
|
+
const res = await this._getJson(`${BASE_PATH}/stream/list.cgi`, undefined, options);
|
|
31
|
+
const list = z.record(z.string(), cameraStreamSchema).parse(res.data);
|
|
32
|
+
const streamList = {};
|
|
33
|
+
for (const [key, data] of Object.entries(list)) {
|
|
34
|
+
const streamId = parseInt(key);
|
|
35
|
+
streamList[streamId] = parseCameraStreamResponse(data);
|
|
36
|
+
}
|
|
37
|
+
return streamList;
|
|
17
38
|
}
|
|
18
|
-
async getStream(
|
|
19
|
-
const
|
|
20
|
-
|
|
39
|
+
async getStream(streamId, options) {
|
|
40
|
+
const res = await this._getJson(`${BASE_PATH}/stream/get.cgi`, { stream_id: streamId }, options);
|
|
41
|
+
const cameraData = cameraStreamSchema.parse(res.data);
|
|
42
|
+
return parseCameraStreamResponse(cameraData);
|
|
21
43
|
}
|
|
22
|
-
async getStreamParameter(
|
|
23
|
-
const
|
|
24
|
-
return
|
|
44
|
+
async getStreamParameter(streamId, paramName, options) {
|
|
45
|
+
const res = await this._getJson(`${BASE_PATH}/stream/get.cgi`, { stream_id: streamId }, options);
|
|
46
|
+
return z.string().parse(res.data[paramName]);
|
|
25
47
|
}
|
|
26
|
-
async setStream(
|
|
48
|
+
async setStream(streamId, params, options) {
|
|
27
49
|
const { streamDelay, startTime, stopTime, ...rest } = params;
|
|
28
|
-
await this.
|
|
29
|
-
stream_id:
|
|
50
|
+
await this._getJson(`${BASE_PATH}/stream/set.cgi`, {
|
|
51
|
+
stream_id: streamId,
|
|
30
52
|
streamDelay: streamDelay ?? '',
|
|
31
|
-
startTime: startTime ??
|
|
32
|
-
stopTime: stopTime ??
|
|
53
|
+
startTime: startTime ?? null,
|
|
54
|
+
stopTime: stopTime ?? null,
|
|
33
55
|
...rest,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
async setStreamParameter(streamID, paramName, value) {
|
|
37
|
-
await this.get(`/local/camstreamer/stream/set.cgi?stream_id=${streamID}&${paramName}=${value}`);
|
|
38
|
-
}
|
|
39
|
-
async isStreaming(streamID) {
|
|
40
|
-
const response = await this.get(`/local/camstreamer/get_streamstat.cgi?stream_id=${streamID}`);
|
|
41
|
-
return response.data.is_streaming === 1;
|
|
56
|
+
}, options);
|
|
42
57
|
}
|
|
43
|
-
async
|
|
44
|
-
await this.
|
|
58
|
+
async setStreamParameter(streamId, paramName, value, options) {
|
|
59
|
+
await this._getJson(`${BASE_PATH}/stream/set.cgi`, { stream_id: streamId, [paramName]: value }, options);
|
|
45
60
|
}
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
async isStreaming(streamId, options) {
|
|
62
|
+
const res = await this._getJson(`${BASE_PATH}/get_streamstat.cgi`, { stream_id: streamId }, options);
|
|
63
|
+
return res.data.is_streaming === 1;
|
|
48
64
|
}
|
|
49
|
-
async
|
|
50
|
-
|
|
65
|
+
async deleteStream(streamId, options) {
|
|
66
|
+
const res = await this._getJson(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
|
|
67
|
+
return res.data.status === 200;
|
|
51
68
|
}
|
|
52
|
-
async
|
|
53
|
-
const
|
|
69
|
+
async _getJson(path, parameters, options) {
|
|
70
|
+
const agent = this.getClient(options?.proxyParams);
|
|
71
|
+
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
54
72
|
if (res.ok) {
|
|
55
73
|
return await res.json();
|
|
56
74
|
}
|
|
@@ -59,3 +77,28 @@ export class CamStreamerAPI {
|
|
|
59
77
|
}
|
|
60
78
|
}
|
|
61
79
|
}
|
|
80
|
+
export const parseCameraStreamResponse = (cameraStreamData) => {
|
|
81
|
+
return {
|
|
82
|
+
enabled: parseInt(cameraStreamData.enabled),
|
|
83
|
+
active: parseInt(cameraStreamData.active),
|
|
84
|
+
audioSource: cameraStreamData.audioSource,
|
|
85
|
+
avSyncMsec: parseInt(cameraStreamData.avSyncMsec),
|
|
86
|
+
internalVapixParameters: cameraStreamData.internalVapixParameters,
|
|
87
|
+
userVapixParameters: cameraStreamData.userVapixParameters,
|
|
88
|
+
outputParameters: cameraStreamData.outputParameters,
|
|
89
|
+
outputType: cameraStreamData.outputType,
|
|
90
|
+
mediaServerUrl: cameraStreamData.mediaServerUrl,
|
|
91
|
+
inputType: cameraStreamData.inputType,
|
|
92
|
+
inputUrl: cameraStreamData.inputUrl,
|
|
93
|
+
forceStereo: parseInt(cameraStreamData.forceStereo),
|
|
94
|
+
streamDelay: isNaN(parseInt(cameraStreamData.streamDelay)) ? null : parseInt(cameraStreamData.streamDelay),
|
|
95
|
+
statusLed: parseInt(cameraStreamData.statusLed),
|
|
96
|
+
statusPort: cameraStreamData.statusPort,
|
|
97
|
+
callApi: parseInt(cameraStreamData.callApi),
|
|
98
|
+
trigger: cameraStreamData.trigger,
|
|
99
|
+
schedule: cameraStreamData.schedule,
|
|
100
|
+
prepareAhead: parseInt(cameraStreamData.prepareAhead),
|
|
101
|
+
startTime: isNaN(parseInt(cameraStreamData.startTime)) ? null : parseInt(cameraStreamData.startTime),
|
|
102
|
+
stopTime: isNaN(parseInt(cameraStreamData.stopTime)) ? null : parseInt(cameraStreamData.stopTime),
|
|
103
|
+
};
|
|
104
|
+
};
|