camstreamerlib 4.0.0-beta.2 → 4.0.0-beta.20
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 +5 -1
- package/cjs/CamOverlayAPI.d.ts +629 -0
- package/cjs/CamOverlayAPI.js +255 -0
- package/{CamOverlayDrawingAPI.d.ts → cjs/CamOverlayDrawingAPI.d.ts} +1 -1
- package/cjs/CamOverlayDrawingAPI.js +235 -0
- package/cjs/CamOverlayPainter/Frame.js +301 -0
- package/{CamOverlayPainter → cjs/CamOverlayPainter}/Painter.d.ts +14 -3
- package/cjs/CamOverlayPainter/Painter.js +171 -0
- package/cjs/CamOverlayPainter/ResourceManager.js +46 -0
- package/{CamScripterAPI.d.ts → cjs/CamScripterAPI.d.ts} +5 -5
- package/cjs/CamScripterAPI.js +64 -0
- package/{CamScripterAPICameraEventsGenerator.d.ts → cjs/CamScripterAPICameraEventsGenerator.d.ts} +1 -1
- package/cjs/CamScripterAPICameraEventsGenerator.js +162 -0
- package/{CamStreamerAPI.d.ts → cjs/CamStreamerAPI.d.ts} +5 -5
- package/cjs/CamStreamerAPI.js +59 -0
- package/{CamSwitcherAPI.d.ts → cjs/CamSwitcherAPI.d.ts} +10 -6
- package/cjs/CamSwitcherAPI.js +351 -0
- package/{CamSwitcherEvents.d.ts → cjs/CamSwitcherEvents.d.ts} +2 -2
- package/cjs/CamSwitcherEvents.js +67 -0
- package/cjs/CreatePackage.js +106 -0
- package/cjs/PlaneTrackerAPI.d.ts +47 -0
- package/cjs/PlaneTrackerAPI.js +176 -0
- package/{VapixAPI.d.ts → cjs/VapixAPI.d.ts} +19 -7
- package/cjs/VapixAPI.js +491 -0
- package/{VapixEvents.d.ts → cjs/VapixEvents.d.ts} +1 -1
- package/cjs/VapixEvents.js +88 -0
- package/{errors → cjs/errors}/errors.d.ts +3 -0
- package/cjs/errors/errors.js +86 -0
- package/{events → cjs/events}/AxisCameraStationEvents.d.ts +3 -2
- package/cjs/events/AxisCameraStationEvents.js +48 -0
- package/{events → cjs/events}/GenetecAgent.d.ts +4 -3
- package/cjs/events/GenetecAgent.js +123 -0
- package/cjs/index.d.ts +18 -0
- package/cjs/index.js +42 -0
- package/cjs/internal/Digest.js +42 -0
- package/cjs/internal/ProxyClient.d.ts +11 -0
- package/cjs/internal/ProxyClient.js +46 -0
- package/cjs/internal/constants.js +4 -0
- package/cjs/internal/transformers.js +32 -0
- package/cjs/internal/types.d.ts +35 -0
- package/cjs/internal/types.js +2 -0
- package/{internal → cjs/internal}/utils.d.ts +5 -1
- package/cjs/internal/utils.js +69 -0
- package/{internal → cjs/internal}/versionCompare.d.ts +2 -2
- package/cjs/internal/versionCompare.js +53 -0
- package/cjs/models/CamOverlayAPI/accuweatherSchema.d.ts +84 -0
- package/cjs/models/CamOverlayAPI/accuweatherSchema.js +48 -0
- package/cjs/models/CamOverlayAPI/constants.d.ts +11 -0
- package/cjs/models/CamOverlayAPI/constants.js +14 -0
- package/cjs/models/CamOverlayAPI/customGraphicsSchema.d.ts +699 -0
- package/cjs/models/CamOverlayAPI/customGraphicsSchema.js +73 -0
- package/cjs/models/CamOverlayAPI/fileSchema.d.ts +28 -0
- package/cjs/models/CamOverlayAPI/fileSchema.js +17 -0
- package/cjs/models/CamOverlayAPI/imagesSchema.d.ts +95 -0
- package/cjs/models/CamOverlayAPI/imagesSchema.js +10 -0
- package/cjs/models/CamOverlayAPI/index.d.ts +13 -0
- package/cjs/models/CamOverlayAPI/index.js +29 -0
- package/cjs/models/CamOverlayAPI/infotickerSchema.d.ts +96 -0
- package/cjs/models/CamOverlayAPI/infotickerSchema.js +27 -0
- package/cjs/models/CamOverlayAPI/pipSchema.d.ts +125 -0
- package/cjs/models/CamOverlayAPI/pipSchema.js +40 -0
- package/cjs/models/CamOverlayAPI/ptzCompassSchema.d.ts +93 -0
- package/cjs/models/CamOverlayAPI/ptzCompassSchema.js +26 -0
- package/cjs/models/CamOverlayAPI/ptzSchema.d.ts +118 -0
- package/cjs/models/CamOverlayAPI/ptzSchema.js +13 -0
- package/cjs/models/CamOverlayAPI/screenSharingSchema.d.ts +58 -0
- package/cjs/models/CamOverlayAPI/screenSharingSchema.js +9 -0
- package/cjs/models/CamOverlayAPI/webCameraSharingSchema.d.ts +58 -0
- package/cjs/models/CamOverlayAPI/webCameraSharingSchema.js +9 -0
- package/cjs/models/CamOverlayAPI/widgetCommonSchema.d.ts +126 -0
- package/cjs/models/CamOverlayAPI/widgetCommonSchema.js +76 -0
- package/cjs/models/CamOverlayAPI/widgetsSchema.d.ts +2823 -0
- package/cjs/models/CamOverlayAPI/widgetsSchema.js +27 -0
- package/cjs/node/DefaultClient.d.ts +16 -0
- package/cjs/node/DefaultClient.js +56 -0
- package/cjs/node/HttpRequestSender.js +89 -0
- package/cjs/node/HttpServer.js +96 -0
- package/{node → cjs/node}/WsClient.d.ts +1 -1
- package/cjs/node/WsClient.js +149 -0
- package/{node → cjs/node}/WsEventClient.d.ts +1 -1
- package/cjs/node/WsEventClient.js +22 -0
- package/cjs/node/index.d.ts +2 -0
- package/cjs/node/index.js +7 -0
- package/cjs/types/CamOverlayAPI.d.ts +328 -0
- package/cjs/types/CamOverlayAPI.js +26 -0
- package/{types → cjs/types}/CamScripterAPI.d.ts +55 -7
- package/cjs/types/CamScripterAPI.js +31 -0
- package/{types → cjs/types}/CamStreamerAPI.d.ts +16 -5
- package/cjs/types/CamStreamerAPI.js +32 -0
- package/{types → cjs/types}/CamSwitcherAPI.d.ts +5 -5
- package/cjs/types/CamSwitcherAPI.js +137 -0
- package/{types/CamswitcherEvents.d.ts → cjs/types/CamSwitcherEvents.d.ts} +77 -0
- package/cjs/types/CamSwitcherEvents.js +70 -0
- package/cjs/types/PlaneTrackerAPI.d.ts +2 -0
- package/cjs/types/PlaneTrackerAPI.js +2 -0
- package/{types → cjs/types}/VapixAPI.d.ts +479 -519
- package/cjs/types/VapixAPI.js +139 -0
- package/cjs/types/common.js +14 -0
- package/cjs/web/DefaultClient.d.ts +6 -0
- package/cjs/web/DefaultClient.js +22 -0
- package/cjs/web/WsClient.js +62 -0
- package/cjs/web/index.d.ts +2 -0
- package/cjs/web/index.js +7 -0
- package/esm/CamOverlayAPI.d.ts +629 -0
- package/esm/CamOverlayAPI.js +251 -0
- package/esm/CamOverlayDrawingAPI.d.ts +86 -0
- package/{CamOverlayDrawingAPI.js → esm/CamOverlayDrawingAPI.js} +6 -3
- package/esm/CamOverlayPainter/Frame.d.ts +96 -0
- package/esm/CamOverlayPainter/Painter.d.ts +48 -0
- package/{CamOverlayPainter → esm/CamOverlayPainter}/Painter.js +4 -1
- package/esm/CamOverlayPainter/ResourceManager.d.ts +14 -0
- package/{CamOverlayPainter → esm/CamOverlayPainter}/ResourceManager.js +6 -10
- package/esm/CamScripterAPI.d.ts +19 -0
- package/{CamScripterAPI.js → esm/CamScripterAPI.js} +4 -10
- package/esm/CamScripterAPICameraEventsGenerator.d.ts +74 -0
- package/{CamScripterAPICameraEventsGenerator.js → esm/CamScripterAPICameraEventsGenerator.js} +6 -3
- package/esm/CamStreamerAPI.d.ts +16 -0
- package/{CamStreamerAPI.js → esm/CamStreamerAPI.js} +4 -10
- package/esm/CamSwitcherAPI.d.ts +52 -0
- package/{CamSwitcherAPI.js → esm/CamSwitcherAPI.js} +24 -27
- package/esm/CamSwitcherEvents.d.ts +18 -0
- package/{CamSwitcherEvents.js → esm/CamSwitcherEvents.js} +1 -1
- package/esm/CreatePackage.d.ts +1 -0
- package/esm/PlaneTrackerAPI.d.ts +47 -0
- package/esm/PlaneTrackerAPI.js +172 -0
- package/esm/VapixAPI.d.ts +78 -0
- package/{VapixAPI.js → esm/VapixAPI.js} +93 -60
- package/esm/VapixEvents.d.ts +43 -0
- package/{VapixEvents.js → esm/VapixEvents.js} +3 -3
- package/esm/errors/errors.d.ts +37 -0
- package/{errors → esm/errors}/errors.js +6 -0
- package/esm/events/AxisCameraStationEvents.d.ts +10 -0
- package/{events → esm/events}/AxisCameraStationEvents.js +1 -1
- package/esm/events/GenetecAgent.d.ts +175 -0
- package/{events → esm/events}/GenetecAgent.js +5 -5
- package/esm/index.d.ts +18 -0
- package/esm/index.js +18 -0
- package/esm/internal/Digest.d.ts +4 -0
- package/{internal → esm/internal}/Digest.js +6 -6
- package/esm/internal/ProxyClient.d.ts +11 -0
- package/{internal → esm/internal}/ProxyClient.js +6 -4
- package/esm/internal/constants.d.ts +1 -0
- package/esm/internal/transformers.d.ts +5 -0
- package/esm/internal/types.d.ts +35 -0
- package/esm/internal/types.js +1 -0
- package/esm/internal/utils.d.ts +15 -0
- package/{internal → esm/internal}/utils.js +20 -1
- package/esm/internal/versionCompare.d.ts +6 -0
- package/esm/models/CamOverlayAPI/accuweatherSchema.d.ts +84 -0
- package/esm/models/CamOverlayAPI/accuweatherSchema.js +45 -0
- package/esm/models/CamOverlayAPI/constants.d.ts +11 -0
- package/esm/models/CamOverlayAPI/constants.js +11 -0
- package/esm/models/CamOverlayAPI/customGraphicsSchema.d.ts +699 -0
- package/esm/models/CamOverlayAPI/customGraphicsSchema.js +70 -0
- package/esm/models/CamOverlayAPI/fileSchema.d.ts +28 -0
- package/esm/models/CamOverlayAPI/fileSchema.js +14 -0
- package/esm/models/CamOverlayAPI/imagesSchema.d.ts +95 -0
- package/esm/models/CamOverlayAPI/imagesSchema.js +7 -0
- package/esm/models/CamOverlayAPI/index.d.ts +13 -0
- package/esm/models/CamOverlayAPI/index.js +13 -0
- package/esm/models/CamOverlayAPI/infotickerSchema.d.ts +96 -0
- package/esm/models/CamOverlayAPI/infotickerSchema.js +24 -0
- package/esm/models/CamOverlayAPI/pipSchema.d.ts +125 -0
- package/esm/models/CamOverlayAPI/pipSchema.js +37 -0
- package/esm/models/CamOverlayAPI/ptzCompassSchema.d.ts +93 -0
- package/esm/models/CamOverlayAPI/ptzCompassSchema.js +23 -0
- package/esm/models/CamOverlayAPI/ptzSchema.d.ts +118 -0
- package/esm/models/CamOverlayAPI/ptzSchema.js +10 -0
- package/esm/models/CamOverlayAPI/screenSharingSchema.d.ts +58 -0
- package/esm/models/CamOverlayAPI/screenSharingSchema.js +6 -0
- package/esm/models/CamOverlayAPI/webCameraSharingSchema.d.ts +58 -0
- package/esm/models/CamOverlayAPI/webCameraSharingSchema.js +6 -0
- package/esm/models/CamOverlayAPI/widgetCommonSchema.d.ts +126 -0
- package/esm/models/CamOverlayAPI/widgetCommonSchema.js +73 -0
- package/esm/models/CamOverlayAPI/widgetsSchema.d.ts +2823 -0
- package/esm/models/CamOverlayAPI/widgetsSchema.js +24 -0
- package/esm/node/DefaultClient.d.ts +16 -0
- package/{node → esm/node}/DefaultClient.js +9 -7
- package/esm/node/HttpRequestSender.d.ts +28 -0
- package/esm/node/HttpServer.d.ts +21 -0
- package/{node → esm/node}/HttpServer.js +1 -1
- package/esm/node/WsClient.d.ts +39 -0
- package/esm/node/WsEventClient.d.ts +13 -0
- package/esm/node/index.d.ts +2 -0
- package/esm/node/index.js +2 -0
- package/esm/types/CamOverlayAPI.d.ts +328 -0
- package/esm/types/CamOverlayAPI.js +14 -0
- package/esm/types/CamScripterAPI.d.ts +115 -0
- package/esm/types/CamScripterAPI.js +28 -0
- package/esm/types/CamStreamerAPI.d.ts +150 -0
- package/{types → esm/types}/CamStreamerAPI.js +4 -0
- package/esm/types/CamSwitcherAPI.d.ts +814 -0
- package/esm/types/CamSwitcherEvents.d.ts +568 -0
- package/{types/CamswitcherEvents.js → esm/types/CamSwitcherEvents.js} +8 -0
- package/esm/types/PlaneTrackerAPI.d.ts +2 -0
- package/esm/types/PlaneTrackerAPI.js +1 -0
- package/esm/types/VapixAPI.d.ts +1664 -0
- package/{types → esm/types}/VapixAPI.js +30 -23
- package/esm/types/common.d.ts +37 -0
- package/esm/web/DefaultClient.d.ts +6 -0
- package/{web → esm/web}/DefaultClient.js +6 -4
- package/esm/web/WsClient.d.ts +13 -0
- package/{web → esm/web}/WsClient.js +2 -2
- package/esm/web/index.d.ts +2 -0
- package/esm/web/index.js +2 -0
- package/package.json +6 -6
- package/CamOverlayAPI.d.ts +0 -31
- package/CamOverlayAPI.js +0 -172
- package/internal/ProxyClient.d.ts +0 -11
- package/internal/common.d.ts +0 -40
- package/internal/common.js +0 -23
- package/node/DefaultClient.d.ts +0 -15
- package/types/CamOverlayAPI.d.ts +0 -188
- package/types/CamOverlayAPI.js +0 -44
- package/types/CamScripterAPI.js +0 -17
- package/web/DefaultClient.d.ts +0 -6
- package/{CamOverlayPainter → cjs/CamOverlayPainter}/Frame.d.ts +0 -0
- package/{CamOverlayPainter → cjs/CamOverlayPainter}/ResourceManager.d.ts +0 -0
- package/{CreatePackage.d.ts → cjs/CreatePackage.d.ts} +0 -0
- package/{internal → cjs/internal}/Digest.d.ts +0 -0
- package/{internal → cjs/internal}/constants.d.ts +0 -0
- package/{internal → cjs/internal}/transformers.d.ts +0 -0
- package/{node → cjs/node}/HttpRequestSender.d.ts +0 -0
- package/{node → cjs/node}/HttpServer.d.ts +0 -0
- package/{types → cjs/types}/common.d.ts +2 -2
- /package/{web → cjs/web}/WsClient.d.ts +0 -0
- /package/{CamOverlayPainter → esm/CamOverlayPainter}/Frame.js +0 -0
- /package/{CreatePackage.js → esm/CreatePackage.js} +0 -0
- /package/{internal → esm/internal}/constants.js +0 -0
- /package/{internal → esm/internal}/transformers.js +0 -0
- /package/{internal → esm/internal}/versionCompare.js +0 -0
- /package/{node → esm/node}/HttpRequestSender.js +0 -0
- /package/{node → esm/node}/WsClient.js +0 -0
- /package/{node → esm/node}/WsEventClient.js +0 -0
- /package/{types → esm/types}/CamSwitcherAPI.js +0 -0
- /package/{types → esm/types}/common.js +0 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CamOverlayAPI = exports.BASE_URL = void 0;
|
|
4
|
+
const utils_1 = require("./internal/utils");
|
|
5
|
+
const CamOverlayAPI_1 = require("./types/CamOverlayAPI");
|
|
6
|
+
const errors_1 = require("./errors/errors");
|
|
7
|
+
const common_1 = require("./types/common");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const widgetsSchema_1 = require("./models/CamOverlayAPI/widgetsSchema");
|
|
10
|
+
const fileSchema_1 = require("./models/CamOverlayAPI/fileSchema");
|
|
11
|
+
exports.BASE_URL = '/local/camoverlay/api';
|
|
12
|
+
class CamOverlayAPI {
|
|
13
|
+
client;
|
|
14
|
+
constructor(client) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
}
|
|
17
|
+
static getProxyUrlPath = () => `${exports.BASE_URL}/proxy.cgi`;
|
|
18
|
+
static getFilePreviewPath = (path) => `${exports.BASE_URL}/image.cgi?path=${encodeURIComponent(path)}`;
|
|
19
|
+
async checkCameraTime() {
|
|
20
|
+
const responseSchema = zod_1.z.discriminatedUnion('state', [
|
|
21
|
+
zod_1.z.object({
|
|
22
|
+
state: zod_1.z.literal(true),
|
|
23
|
+
code: zod_1.z.number(),
|
|
24
|
+
}),
|
|
25
|
+
zod_1.z.object({
|
|
26
|
+
state: zod_1.z.literal(false),
|
|
27
|
+
code: zod_1.z.number(),
|
|
28
|
+
reason: zod_1.z.union([
|
|
29
|
+
zod_1.z.literal('INVALID_TIME'),
|
|
30
|
+
zod_1.z.literal('COULDNT_RESOLVE_HOST'),
|
|
31
|
+
zod_1.z.literal('CONNECTION_ERROR'),
|
|
32
|
+
]),
|
|
33
|
+
message: zod_1.z.string(),
|
|
34
|
+
}),
|
|
35
|
+
]);
|
|
36
|
+
const response = await this._get(`${exports.BASE_URL}/camera_time.cgi`);
|
|
37
|
+
const cameraTime = responseSchema.parse(response);
|
|
38
|
+
if (!cameraTime.state) {
|
|
39
|
+
console.error(`Camera time check failed: ${cameraTime.reason} - ${cameraTime.message}`);
|
|
40
|
+
}
|
|
41
|
+
return cameraTime.state;
|
|
42
|
+
}
|
|
43
|
+
async getNetworkCameraList() {
|
|
44
|
+
const response = await this._get(`${exports.BASE_URL}/network_camera_list.cgi`);
|
|
45
|
+
return common_1.networkCameraListSchema.parse(response.camera_list);
|
|
46
|
+
}
|
|
47
|
+
async wsAuthorization() {
|
|
48
|
+
const responseSchema = zod_1.z.object({
|
|
49
|
+
status: zod_1.z.number(),
|
|
50
|
+
message: zod_1.z.string(),
|
|
51
|
+
data: zod_1.z.string(),
|
|
52
|
+
});
|
|
53
|
+
const response = await this._get(`${exports.BASE_URL}/ws_authorization.cgi`);
|
|
54
|
+
return responseSchema.parse(response).data;
|
|
55
|
+
}
|
|
56
|
+
async getMjpegStreamImage(mjpegUrl) {
|
|
57
|
+
return await this._getBlob(`${exports.BASE_URL}/fetch_mjpeg_image.cgi?mjpeg_url=${encodeURIComponent(decodeURIComponent(mjpegUrl))}`);
|
|
58
|
+
}
|
|
59
|
+
async listFiles(fileType) {
|
|
60
|
+
const fileDataSchema = zod_1.z.object({
|
|
61
|
+
code: zod_1.z.number(),
|
|
62
|
+
list: fileSchema_1.fileListSchema,
|
|
63
|
+
});
|
|
64
|
+
const files = await this._get(`${exports.BASE_URL}/upload_${fileType}.cgi`, {
|
|
65
|
+
action: 'list',
|
|
66
|
+
});
|
|
67
|
+
return fileSchema_1.fileListSchema.parse(files.list);
|
|
68
|
+
}
|
|
69
|
+
async uploadFile(fileType, formData, storage) {
|
|
70
|
+
const path = `${exports.BASE_URL}/upload_${fileType}.cgi`;
|
|
71
|
+
await this._post(path, formData, {
|
|
72
|
+
action: 'upload',
|
|
73
|
+
storage: storage,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async removeFile(fileType, fileParams) {
|
|
77
|
+
const path = `${exports.BASE_URL}/upload_${fileType}.cgi`;
|
|
78
|
+
await this._postUrlEncoded(path, {
|
|
79
|
+
action: 'remove',
|
|
80
|
+
...fileParams,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async getFileStorage(fileType) {
|
|
84
|
+
const storageDataListSchema = zod_1.z.array(zod_1.z.object({
|
|
85
|
+
type: fileSchema_1.storageSchema,
|
|
86
|
+
state: zod_1.z.string(),
|
|
87
|
+
}));
|
|
88
|
+
const responseSchema = zod_1.z.object({
|
|
89
|
+
code: zod_1.z.number(),
|
|
90
|
+
list: storageDataListSchema,
|
|
91
|
+
});
|
|
92
|
+
const data = await this._get(`${exports.BASE_URL}/upload_${fileType}.cgi`, {
|
|
93
|
+
action: 'get_storage',
|
|
94
|
+
});
|
|
95
|
+
if (data.code !== 200) {
|
|
96
|
+
throw new Error('Error occured while fetching file storage data');
|
|
97
|
+
}
|
|
98
|
+
return storageDataListSchema.parse(data.list);
|
|
99
|
+
}
|
|
100
|
+
async getFilePreviewFromCamera(path) {
|
|
101
|
+
return await this._getBlob(CamOverlayAPI.getFilePreviewPath(path));
|
|
102
|
+
}
|
|
103
|
+
async updateInfoticker(serviceID, text) {
|
|
104
|
+
await this._get(`${exports.BASE_URL}/infoticker.cgi?service_id=${serviceID}&text=${text}`);
|
|
105
|
+
}
|
|
106
|
+
async setEnabled(serviceID, enabled) {
|
|
107
|
+
await this._post(`${exports.BASE_URL}/enabled.cgi?id_${serviceID}=${enabled ? 1 : 0}`, '');
|
|
108
|
+
}
|
|
109
|
+
async isEnabled(serviceID) {
|
|
110
|
+
const res = await this.client.get(`${exports.BASE_URL}/services.cgi?action=get`);
|
|
111
|
+
if (res.ok) {
|
|
112
|
+
const data = JSON.parse(await res.text());
|
|
113
|
+
for (const service of data.services) {
|
|
114
|
+
if (service.id === serviceID) {
|
|
115
|
+
return service.enabled === 1;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
throw new errors_1.ServiceNotFoundError();
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async getSingleWidget(serviceId) {
|
|
125
|
+
const data = await this._get(`${exports.BASE_URL}/services.cgi`, {
|
|
126
|
+
action: 'get',
|
|
127
|
+
service_id: serviceId.toString(),
|
|
128
|
+
});
|
|
129
|
+
return widgetsSchema_1.widgetsSchema.parse(data);
|
|
130
|
+
}
|
|
131
|
+
async getWidgets() {
|
|
132
|
+
const widgetList = await this._get(`${exports.BASE_URL}/services.cgi`, {
|
|
133
|
+
action: 'get',
|
|
134
|
+
});
|
|
135
|
+
const widgets = widgetList.services;
|
|
136
|
+
widgets.forEach((widget) => {
|
|
137
|
+
const parsedWidget = widgetsSchema_1.widgetsSchema.safeParse(widget);
|
|
138
|
+
if (!parsedWidget.success) {
|
|
139
|
+
console.warn(`[SERVICE SCHEMA MISMATCH]: Service ${widget.name} (${widget.id}) does not match the current schema, or is a hidden service.`);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return widgets;
|
|
143
|
+
}
|
|
144
|
+
async updateSingleWidget(widget) {
|
|
145
|
+
const path = `${exports.BASE_URL}/services.cgi`;
|
|
146
|
+
await this._postJsonEncoded(path, JSON.stringify(widget), {
|
|
147
|
+
action: 'set',
|
|
148
|
+
service_id: widget.id.toString(),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async updateWidgets(widgets) {
|
|
152
|
+
const path = `${exports.BASE_URL}/services.cgi`;
|
|
153
|
+
await this._postJsonEncoded(path, JSON.stringify({ services: widgets }), {
|
|
154
|
+
action: 'set',
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
updateCGText(serviceID, fields) {
|
|
158
|
+
const params = {};
|
|
159
|
+
for (const field of fields) {
|
|
160
|
+
const name = field.field_name;
|
|
161
|
+
params[name] = field.text;
|
|
162
|
+
if (field.color !== undefined) {
|
|
163
|
+
params[`${name}_color`] = field.color;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return this.promiseCGUpdate(serviceID, 'update_text', params);
|
|
167
|
+
}
|
|
168
|
+
updateCGImagePos(serviceID, coordinates = '', x = 0, y = 0) {
|
|
169
|
+
const params = {
|
|
170
|
+
coord_system: coordinates,
|
|
171
|
+
pos_x: x,
|
|
172
|
+
pos_y: y,
|
|
173
|
+
};
|
|
174
|
+
return this.promiseCGUpdate(serviceID, 'update_image', params);
|
|
175
|
+
}
|
|
176
|
+
updateCGImage(serviceID, path, coordinates = '', x = 0, y = 0) {
|
|
177
|
+
const params = {
|
|
178
|
+
coord_system: coordinates,
|
|
179
|
+
pos_x: x,
|
|
180
|
+
pos_y: y,
|
|
181
|
+
image: path,
|
|
182
|
+
};
|
|
183
|
+
return this.promiseCGUpdate(serviceID, 'update_image', params);
|
|
184
|
+
}
|
|
185
|
+
updateCGImageFromData(serviceID, imageType, imageData, coordinates = '', x = 0, y = 0) {
|
|
186
|
+
const contentType = imageType === CamOverlayAPI_1.ImageType.PNG ? 'image/png' : 'image/jpeg';
|
|
187
|
+
const params = {
|
|
188
|
+
coord_system: coordinates,
|
|
189
|
+
pos_x: x,
|
|
190
|
+
pos_y: y,
|
|
191
|
+
};
|
|
192
|
+
return this.promiseCGUpdate(serviceID, 'update_image', params, contentType, imageData);
|
|
193
|
+
}
|
|
194
|
+
async promiseCGUpdate(serviceID, action, params = {}, contentType, data) {
|
|
195
|
+
const path = `${exports.BASE_URL}/customGraphics.cgi`;
|
|
196
|
+
let headers = {};
|
|
197
|
+
if (contentType !== undefined && data) {
|
|
198
|
+
headers = { 'Content-Type': contentType };
|
|
199
|
+
}
|
|
200
|
+
const res = await this.client.post(path, data ?? '', {
|
|
201
|
+
action: action,
|
|
202
|
+
service_id: serviceID.toString(),
|
|
203
|
+
...params,
|
|
204
|
+
}, headers);
|
|
205
|
+
if (!res.ok) {
|
|
206
|
+
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async _get(...args) {
|
|
210
|
+
const res = await this.client.get(...args);
|
|
211
|
+
if (res.ok) {
|
|
212
|
+
return (await res.json());
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async _post(...args) {
|
|
219
|
+
const res = await this.client.post(...args);
|
|
220
|
+
if (res.ok) {
|
|
221
|
+
return (await res.json());
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async _getBlob(...args) {
|
|
228
|
+
const res = await this.client.get(...args);
|
|
229
|
+
if (res.ok) {
|
|
230
|
+
return await this.parseBlobResponse(res);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async parseBlobResponse(response) {
|
|
237
|
+
try {
|
|
238
|
+
return (await response.blob());
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
throw new errors_1.ParsingBlobError(err);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
async _postUrlEncoded(path, params, headers) {
|
|
245
|
+
const data = (0, utils_1.paramToUrl)(params);
|
|
246
|
+
const baseHeaders = { 'Content-Type': 'application/x-www-form-urlencoded' };
|
|
247
|
+
return this._post(path, data, {}, { ...baseHeaders, ...headers });
|
|
248
|
+
}
|
|
249
|
+
async _postJsonEncoded(...args) {
|
|
250
|
+
const [path, data, params, headers] = args;
|
|
251
|
+
const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
|
|
252
|
+
return this._post(path, data, params, { ...baseHeaders, ...headers });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
exports.CamOverlayAPI = CamOverlayAPI;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import * as EventEmitter from 'events';
|
|
4
|
-
import { WsOptions } from './internal/
|
|
4
|
+
import { WsOptions } from './internal/types';
|
|
5
5
|
export type CamOverlayDrawingOptions = WsOptions & {
|
|
6
6
|
camera?: number | number[];
|
|
7
7
|
zIndex?: number;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CamOverlayDrawingAPI = void 0;
|
|
4
|
+
const EventEmitter = require("events");
|
|
5
|
+
const WsClient_1 = require("./node/WsClient");
|
|
6
|
+
class CamOverlayDrawingAPI extends EventEmitter {
|
|
7
|
+
tls;
|
|
8
|
+
tlsInsecure;
|
|
9
|
+
ip;
|
|
10
|
+
port;
|
|
11
|
+
user;
|
|
12
|
+
pass;
|
|
13
|
+
cameraList;
|
|
14
|
+
zIndex;
|
|
15
|
+
callId;
|
|
16
|
+
sendMessages;
|
|
17
|
+
timeoutCheckTimer;
|
|
18
|
+
wsConnected;
|
|
19
|
+
ws;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
super();
|
|
22
|
+
this.tls = options?.tls ?? false;
|
|
23
|
+
this.tlsInsecure = options?.tlsInsecure ?? false;
|
|
24
|
+
this.ip = options?.ip ?? '127.0.0.1';
|
|
25
|
+
this.port = options?.port ?? (this.tls ? 443 : 80);
|
|
26
|
+
this.user = options?.user ?? '';
|
|
27
|
+
this.pass = options?.pass ?? '';
|
|
28
|
+
this.zIndex = options?.zIndex ?? 0;
|
|
29
|
+
this.cameraList = [0];
|
|
30
|
+
if (options && Array.isArray(options.camera)) {
|
|
31
|
+
this.cameraList = options.camera;
|
|
32
|
+
}
|
|
33
|
+
else if (typeof options?.camera === 'number') {
|
|
34
|
+
this.cameraList = [options.camera];
|
|
35
|
+
}
|
|
36
|
+
this.callId = 0;
|
|
37
|
+
this.sendMessages = {};
|
|
38
|
+
this.wsConnected = false;
|
|
39
|
+
this.createWsClient();
|
|
40
|
+
EventEmitter.call(this);
|
|
41
|
+
}
|
|
42
|
+
connect() {
|
|
43
|
+
this.ws.open();
|
|
44
|
+
this.startMsgsTimeoutCheck();
|
|
45
|
+
}
|
|
46
|
+
disconnect() {
|
|
47
|
+
this.ws.close();
|
|
48
|
+
this.stopMsgsTimeoutCheck();
|
|
49
|
+
}
|
|
50
|
+
isConnected() {
|
|
51
|
+
return this.wsConnected;
|
|
52
|
+
}
|
|
53
|
+
cairo(command, ...params) {
|
|
54
|
+
return this.sendMessage({ command: command, params: params });
|
|
55
|
+
}
|
|
56
|
+
writeText(...params) {
|
|
57
|
+
return this.sendMessage({ command: 'write_text', params: params });
|
|
58
|
+
}
|
|
59
|
+
uploadImageData(imgBuffer) {
|
|
60
|
+
return this.sendBinaryMessage({
|
|
61
|
+
command: 'upload_image_data',
|
|
62
|
+
params: [],
|
|
63
|
+
}, imgBuffer);
|
|
64
|
+
}
|
|
65
|
+
uploadFontData(fontBuffer) {
|
|
66
|
+
return this.sendBinaryMessage({
|
|
67
|
+
command: 'upload_font_data',
|
|
68
|
+
params: [fontBuffer.toString('base64')],
|
|
69
|
+
}, fontBuffer);
|
|
70
|
+
}
|
|
71
|
+
showCairoImage(cairoImage, posX, posY) {
|
|
72
|
+
return this.sendMessage({
|
|
73
|
+
command: 'show_cairo_image_v2',
|
|
74
|
+
params: [cairoImage, posX, posY, this.cameraList, this.zIndex],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
showCairoImageAbsolute(cairoImage, posX, posY, width, height) {
|
|
78
|
+
return this.sendMessage({
|
|
79
|
+
command: 'show_cairo_image_v2',
|
|
80
|
+
params: [
|
|
81
|
+
cairoImage,
|
|
82
|
+
-1.0 + (2.0 / width) * posX,
|
|
83
|
+
-1.0 + (2.0 / height) * posY,
|
|
84
|
+
this.cameraList,
|
|
85
|
+
this.zIndex,
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
removeImage() {
|
|
90
|
+
return this.sendMessage({ command: 'remove_image_v2', params: [] });
|
|
91
|
+
}
|
|
92
|
+
createWsClient() {
|
|
93
|
+
const options = {
|
|
94
|
+
ip: this.ip,
|
|
95
|
+
port: this.port,
|
|
96
|
+
address: '/local/camoverlay/ws',
|
|
97
|
+
protocol: 'cairo-api',
|
|
98
|
+
user: this.user,
|
|
99
|
+
pass: this.pass,
|
|
100
|
+
tls: this.tls,
|
|
101
|
+
tlsInsecure: this.tlsInsecure,
|
|
102
|
+
};
|
|
103
|
+
this.ws = new WsClient_1.WsClient(options);
|
|
104
|
+
this.ws.on('open', () => {
|
|
105
|
+
console.log('CamOverlay connection opened');
|
|
106
|
+
this.wsConnected = true;
|
|
107
|
+
this.emit('open');
|
|
108
|
+
});
|
|
109
|
+
this.ws.on('message', (msgData) => this.incomingWsMessageHandler(msgData));
|
|
110
|
+
this.ws.on('error', (error) => {
|
|
111
|
+
this.reportError(error);
|
|
112
|
+
});
|
|
113
|
+
this.ws.on('close', () => {
|
|
114
|
+
console.log('CamOverlay connection closed');
|
|
115
|
+
this.wsConnected = false;
|
|
116
|
+
this.reportClose();
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
incomingWsMessageHandler(msgData) {
|
|
120
|
+
const dataJSON = JSON.parse(msgData.toString());
|
|
121
|
+
let errorResponse;
|
|
122
|
+
if ('error' in dataJSON) {
|
|
123
|
+
errorResponse = dataJSON;
|
|
124
|
+
}
|
|
125
|
+
if (dataJSON.call_id !== undefined) {
|
|
126
|
+
if (errorResponse !== undefined) {
|
|
127
|
+
this.sendMessages[dataJSON.call_id]?.reject(new Error(errorResponse.error));
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
this.sendMessages[dataJSON.call_id]?.resolve(dataJSON);
|
|
131
|
+
}
|
|
132
|
+
delete this.sendMessages[dataJSON.call_id];
|
|
133
|
+
}
|
|
134
|
+
if (errorResponse !== undefined) {
|
|
135
|
+
this.reconnectWithError(new Error(errorResponse.error));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
this.reportMessage(msgData.toString());
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
sendMessage(msgJson) {
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
try {
|
|
144
|
+
if (!this.wsConnected) {
|
|
145
|
+
throw new Error('No CamOverlay connection');
|
|
146
|
+
}
|
|
147
|
+
msgJson.call_id = ++this.callId;
|
|
148
|
+
this.ws.send(JSON.stringify(msgJson));
|
|
149
|
+
this.sendMessages[this.callId] = { resolve, reject, sentTimestamp: Date.now() };
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
|
153
|
+
const error = new Error(`Send message error: ${errorMessage}`);
|
|
154
|
+
reject(error);
|
|
155
|
+
if (!this.wsConnected) {
|
|
156
|
+
this.reportError(error);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
this.reconnectWithError(error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
sendBinaryMessage(msgJson, data) {
|
|
165
|
+
return new Promise((resolve, reject) => {
|
|
166
|
+
try {
|
|
167
|
+
if (!this.wsConnected) {
|
|
168
|
+
throw new Error('No CamOverlay connection');
|
|
169
|
+
}
|
|
170
|
+
msgJson.call_id = ++this.callId;
|
|
171
|
+
const jsonBuffer = Buffer.from(JSON.stringify(msgJson));
|
|
172
|
+
const header = new ArrayBuffer(5);
|
|
173
|
+
const headerView = new DataView(header);
|
|
174
|
+
headerView.setInt8(0, 1);
|
|
175
|
+
headerView.setInt32(1, jsonBuffer.byteLength);
|
|
176
|
+
const msgBuffer = Buffer.concat([Buffer.from(header), jsonBuffer, data]);
|
|
177
|
+
this.ws.send(msgBuffer);
|
|
178
|
+
this.sendMessages[this.callId] = { resolve, reject, sentTimestamp: Date.now() };
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
|
182
|
+
const error = new Error(`Send binary message error: ${errorMessage}`);
|
|
183
|
+
reject(error);
|
|
184
|
+
if (!this.wsConnected) {
|
|
185
|
+
this.reportError(error);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
this.reconnectWithError(error);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
startMsgsTimeoutCheck() {
|
|
194
|
+
clearInterval(this.timeoutCheckTimer);
|
|
195
|
+
this.timeoutCheckTimer = setInterval(() => {
|
|
196
|
+
let reconnect = false;
|
|
197
|
+
const now = Date.now();
|
|
198
|
+
for (const callId in this.sendMessages) {
|
|
199
|
+
const msg = this.sendMessages[callId];
|
|
200
|
+
if (!msg) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (now - msg.sentTimestamp > 10000) {
|
|
204
|
+
reconnect = true;
|
|
205
|
+
msg.reject(new Error('Message timeout'));
|
|
206
|
+
delete this.sendMessages[callId];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (reconnect) {
|
|
210
|
+
this.reconnectWithError(new Error('Message timeout'));
|
|
211
|
+
}
|
|
212
|
+
}, 5000);
|
|
213
|
+
}
|
|
214
|
+
stopMsgsTimeoutCheck() {
|
|
215
|
+
clearInterval(this.timeoutCheckTimer);
|
|
216
|
+
}
|
|
217
|
+
reconnectWithError(err) {
|
|
218
|
+
this.reportError(err);
|
|
219
|
+
this.ws.reconnect();
|
|
220
|
+
}
|
|
221
|
+
reportMessage(msg) {
|
|
222
|
+
this.emit('message', msg);
|
|
223
|
+
}
|
|
224
|
+
reportError(err) {
|
|
225
|
+
this.emit('error', err);
|
|
226
|
+
}
|
|
227
|
+
reportClose() {
|
|
228
|
+
for (const callId in this.sendMessages) {
|
|
229
|
+
this.sendMessages[callId]?.reject(new Error('Connection lost'));
|
|
230
|
+
}
|
|
231
|
+
this.sendMessages = {};
|
|
232
|
+
this.emit('close');
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.CamOverlayDrawingAPI = CamOverlayDrawingAPI;
|