camstreamerlib 4.0.0-beta.37 → 4.0.0-beta.39
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 +38 -27
- package/cjs/CamOverlayAPI.js +42 -75
- 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 +2 -2
- package/cjs/types/CamOverlayAPI/scoreBoardSchema.js +6 -1
- 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 +43 -76
- 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 +1 -1
- package/esm/types/CamOverlayAPI/scoreBoardSchema.js +6 -1
- 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 +24 -14
- 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 +38 -38
- package/types/types/CamOverlayAPI/scoreBoardSchema.d.ts +13 -13
- 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/README.md
CHANGED
|
@@ -15,32 +15,34 @@ Examples of CamScripter packages can be found at https://github.com/CamStreamer/
|
|
|
15
15
|
npm install camstreamerlib
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
# Documentation for
|
|
19
|
-
|
|
20
|
-
- [HttpServer](doc/HttpServer.md) is a module for processing HTTP requests in your scripts. It also automatically serves up the content from html directory or you can register paths which you can process by your own (e.g. http://$CAMERA_IP/local/camscripter/proxy/$MY_PACKAGE_NAME/control.cgi).
|
|
18
|
+
# Documentation for ACAP and Camera API
|
|
21
19
|
|
|
22
20
|
- [VapixAPI](doc/VapixAPI.md) is a module to access Axis camera VAPIX interface.
|
|
23
21
|
|
|
24
|
-
- [VapixEvents](doc/VapixEvents.md) is a module which allows receiving camera events from the VAPIX API.
|
|
25
|
-
|
|
26
22
|
- [CamStreamerAPI](doc/CamStreamerAPI.md) is a module for easy control of video streaming in the CamStreamer ACAP application (RTMP, HLS, SRT and MPEG-TS protocols).
|
|
27
23
|
|
|
28
24
|
- [CamOverlayAPI](doc/CamOverlayAPI.md) is a module to access CamOverlay API.
|
|
29
25
|
|
|
26
|
+
- [CamScripterAPI](doc/CamScripterAPI.md) is a module to access CamScripter API.
|
|
27
|
+
|
|
28
|
+
- [CamSwitcherAPI](doc/CamSwitcherAPI.md) is a module to access CamSwitcher API.
|
|
29
|
+
|
|
30
|
+
- [PlaneTrackerAPI](doc/PlaneTrackerAPI.md) is a module to access PlaneTracker API.
|
|
31
|
+
|
|
32
|
+
# Documentation for Node.js modules
|
|
33
|
+
|
|
34
|
+
- [HttpServer](doc/HttpServer.md) is a module for processing HTTP requests in your scripts. It also automatically serves up the content from html directory or you can register paths which you can process by your own (e.g. http://$CAMERA_IP/local/camscripter/proxy/$MY_PACKAGE_NAME/control.cgi).
|
|
35
|
+
|
|
36
|
+
- [VapixEvents](doc/VapixEvents.md) is a module which allows receiving camera events from the VAPIX API.
|
|
37
|
+
|
|
30
38
|
- [CamOverlayDrawingAPI](doc/CamOverlayDrawingAPI.md) is a module for easy control of CamOverlay drawing API. For more details on supported video overlay drawing functions see https://camstreamer.com/camoverlay-api1
|
|
31
39
|
|
|
32
40
|
- [CamOverlayPainter/](doc/CamOverlayPainter.md) contains three modules which makes easier to use CamOverlayDrawingAPI.
|
|
33
41
|
|
|
34
|
-
- [CamScripterAPI](doc/CamScripterAPI.md) is a module to access CamScripter API.
|
|
35
|
-
|
|
36
42
|
- [CamScripterAPICameraEventsGenerator](doc/CamScripterAPICameraEventsGenerator.md) is a module which allows generating events on an Axis camera. These events can be used for triggers in the Axis camera rule engine (events/actions). It is also an easy way how to integrate events and metadata in VMS systems which support Axis camera events.
|
|
37
43
|
|
|
38
|
-
- [CamSwitcherAPI](doc/CamSwitcherAPI.md) is a module to access CamSwitcher API.
|
|
39
|
-
|
|
40
44
|
- [CamSwitcherEvents](doc/CamSwitcherEvents.md) is a module which allows receiving events from CamSwitcher ACAP application.
|
|
41
45
|
|
|
42
|
-
- [PlaneTrackerAPI](doc/PlaneTrackerAPI.md) is a module to access PlaneTracker API.
|
|
43
|
-
|
|
44
46
|
- [GenetecAgent](doc/GenetecAgent.md) is a module which allows receiving and sending data to Genetec VMS.
|
|
45
47
|
|
|
46
48
|
## For Developers
|
|
@@ -65,7 +67,7 @@ If you want to create your own package and upload it to CamScripter App, you can
|
|
|
65
67
|
|
|
66
68
|
```json
|
|
67
69
|
"scripts": {
|
|
68
|
-
"create-package": "node node_modules/camstreamerlib/CreatePackage.js"
|
|
70
|
+
"create-package": "node node_modules/camstreamerlib/bin/CreatePackage.js"
|
|
69
71
|
}
|
|
70
72
|
```
|
|
71
73
|
|
|
@@ -77,29 +79,38 @@ The zip package is created in the current directory. You can choose different lo
|
|
|
77
79
|
|
|
78
80
|
```json
|
|
79
81
|
"scripts": {
|
|
80
|
-
"create-package": "node node_modules/camstreamerlib/CreatePackage.js -i -e=react"
|
|
82
|
+
"create-package": "node node_modules/camstreamerlib/bin/CreatePackage.js -i -e=react"
|
|
81
83
|
}
|
|
82
84
|
```
|
|
83
85
|
|
|
84
|
-
### Breaking changes when moving from version
|
|
86
|
+
### Breaking changes when moving from version 3.\*.\* to 4.\*.\*
|
|
87
|
+
|
|
88
|
+
...
|
|
85
89
|
|
|
86
|
-
- Renamed file HTTPRequest.ts to HttpRequest.ts
|
|
87
|
-
- Removed deprecated protocol attribute from all options objects (use tls instead).
|
|
88
|
-
- Removed RTSP
|
|
89
|
-
> Previously CameraVapix.ts supported both WebSocket and RTSP.
|
|
90
|
-
> Starting with version 2.0.0, it supports WebSocket only.
|
|
91
|
-
- ServiceID shouldn't be passed to CamOverlayAPI by the options object. Pass it as a parameter.
|
|
92
|
-
- Renamed CamOverlayDrawingAPI event msg to message.
|
|
93
|
-
- Drawing services extracted from CamOverlayAPI.ts to a separate file.
|
|
94
|
-
> Please read [CamOverlayAPI](doc/CamOverlayAPI.md) and [CamOverlayDrawingAPI](doc/CamOverlayDrawingAPI.md) for more information.
|
|
95
90
|
|
|
96
91
|
### Breaking changes when moving from version 2.\*.\* to 3.\*.\*
|
|
97
92
|
|
|
98
93
|
- CamStreamerlib requiers Node.js version 18 or higher.
|
|
99
94
|
- CamOverlayDrawingAPI tries to reconnect when the websocket is closed. You don't have to do it manually.
|
|
100
|
-
|
|
95
|
+
> [!IMPORTANT]
|
|
96
|
+
> However, events `open` and `close` are still emitted in case you need to react to them.
|
|
101
97
|
- Files common.ts, Digest.ts, HttpRequest.ts and WsClient.ts moved to a folder internal.
|
|
102
98
|
- Removed function httpRequest(). Use sendRequest() instead. It uses the same interface except for the "noWaitForData" parameter.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
> [!IMPORTANT]
|
|
100
|
+
> It returns (Response object)[https://developer.mozilla.org/en-US/docs/Web/API/Response] which doesn't contain data by default.
|
|
101
|
+
> If you need to wait for data, you can call for example the function `await res.text()`.
|
|
102
|
+
> This change affects the function `vapixGet` from (CameraVapix)[doc/CameraVapix.md] too.
|
|
103
|
+
|
|
104
|
+
### Breaking changes when moving from version 1.\*.\* to 2.\*.\*
|
|
105
|
+
|
|
106
|
+
- Renamed file HTTPRequest.ts to HttpRequest.ts
|
|
107
|
+
- Removed deprecated protocol attribute from all options objects (use tls instead).
|
|
108
|
+
- Removed RTSP
|
|
109
|
+
> [!IMPORTANT]
|
|
110
|
+
> Previously CameraVapix.ts supported both WebSocket and RTSP.
|
|
111
|
+
> Starting with version 2.0.0, it supports WebSocket only.
|
|
112
|
+
- ServiceID shouldn't be passed to CamOverlayAPI by the options object. Pass it as a parameter.
|
|
113
|
+
- Renamed CamOverlayDrawingAPI event msg to message.
|
|
114
|
+
- Drawing services extracted from CamOverlayAPI.ts to a separate file.
|
|
115
|
+
> [!IMPORTANT]
|
|
116
|
+
> Please read [CamOverlayAPI](doc/CamOverlayAPI.md) and [CamOverlayDrawingAPI](doc/CamOverlayDrawingAPI.md) for more information.
|
package/cjs/CamOverlayAPI.js
CHANGED
|
@@ -20,68 +20,51 @@ class CamOverlayAPI {
|
|
|
20
20
|
return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
|
|
21
21
|
}
|
|
22
22
|
async checkCameraTime(options) {
|
|
23
|
-
const
|
|
24
|
-
return zod_1.z.boolean().parse(
|
|
23
|
+
const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
|
|
24
|
+
return zod_1.z.boolean().parse(res.state);
|
|
25
25
|
}
|
|
26
26
|
async getNetworkCameraList(options) {
|
|
27
|
-
const
|
|
28
|
-
return common_1.networkCameraListSchema.parse(
|
|
27
|
+
const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
|
|
28
|
+
return common_1.networkCameraListSchema.parse(res.camera_list);
|
|
29
29
|
}
|
|
30
30
|
async wsAuthorization(options) {
|
|
31
|
-
const
|
|
32
|
-
return CamOverlayAPI_1.
|
|
31
|
+
const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
|
|
32
|
+
return CamOverlayAPI_1.wsResponseSchema.parse(res).message;
|
|
33
33
|
}
|
|
34
34
|
async getMjpegStreamImage(mjpegUrl, options) {
|
|
35
|
-
return await this._getBlob({
|
|
36
|
-
path: `${BASE_PATH}/fetch_mjpeg_image.cgi?mjpeg_url=${encodeURIComponent(decodeURIComponent(mjpegUrl))}`,
|
|
37
|
-
}, options);
|
|
35
|
+
return await this._getBlob(`${BASE_PATH}/fetch_mjpeg_image.cgi`, { mjpeg_url: decodeURIComponent(mjpegUrl) }, options);
|
|
38
36
|
}
|
|
39
37
|
async listFiles(fileType, options) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
parameters: {
|
|
43
|
-
action: 'list',
|
|
44
|
-
},
|
|
45
|
-
}, options);
|
|
46
|
-
return CamOverlayAPI_1.fileListSchema.parse(files.list);
|
|
38
|
+
const res = await this._getJson(`${BASE_PATH}/upload_${fileType}.cgi`, { action: 'list' }, options);
|
|
39
|
+
return CamOverlayAPI_1.fileListSchema.parse(res.list);
|
|
47
40
|
}
|
|
48
41
|
async uploadFile(fileType, formData, storage, options) {
|
|
49
|
-
await this._post({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
parameters: {
|
|
53
|
-
action: 'upload',
|
|
54
|
-
storage: storage,
|
|
55
|
-
},
|
|
42
|
+
await this._post(`${BASE_PATH}/upload_${fileType}.cgi`, formData, {
|
|
43
|
+
action: 'upload',
|
|
44
|
+
storage: storage,
|
|
56
45
|
}, options);
|
|
57
46
|
}
|
|
58
47
|
async removeFile(fileType, fileParams, options) {
|
|
59
|
-
|
|
60
|
-
await this._postUrlEncoded(path, {
|
|
48
|
+
await this._postUrlEncoded(`${BASE_PATH}/upload_${fileType}.cgi`, {
|
|
61
49
|
action: 'remove',
|
|
62
50
|
...fileParams,
|
|
63
|
-
},
|
|
51
|
+
}, options, undefined);
|
|
64
52
|
}
|
|
65
53
|
async getFileStorage(fileType, options) {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
parameters: {
|
|
69
|
-
action: 'get_storage',
|
|
70
|
-
},
|
|
71
|
-
}, options);
|
|
72
|
-
if (data.code !== 200) {
|
|
54
|
+
const res = await this._getJson(`${BASE_PATH}/upload_${fileType}.cgi`, { action: 'get_storage' }, options);
|
|
55
|
+
if (res.code !== 200) {
|
|
73
56
|
throw new Error('Error occured while fetching file storage data');
|
|
74
57
|
}
|
|
75
|
-
return CamOverlayAPI_1.storageDataListSchema.parse(
|
|
58
|
+
return CamOverlayAPI_1.storageDataListSchema.parse(res.list);
|
|
76
59
|
}
|
|
77
60
|
async getFilePreviewFromCamera(path, options) {
|
|
78
|
-
return await this._getBlob(
|
|
61
|
+
return await this._getBlob(CamOverlayAPI.getFilePreviewPath(path), undefined, options);
|
|
79
62
|
}
|
|
80
63
|
async updateInfoticker(serviceId, text, options) {
|
|
81
|
-
await this.
|
|
64
|
+
await this._getJson(`${BASE_PATH}/infoticker.cgi`, { service_id: serviceId, text: text }, options);
|
|
82
65
|
}
|
|
83
66
|
async setEnabled(serviceId, enabled, options) {
|
|
84
|
-
await this._post(
|
|
67
|
+
await this._post(`${BASE_PATH}/enabled.cgi`, '', { [`id_${serviceId}`]: enabled ? 1 : 0 }, options);
|
|
85
68
|
}
|
|
86
69
|
async isEnabled(serviceId, options) {
|
|
87
70
|
const agent = this.getClient(options?.proxyParams);
|
|
@@ -100,43 +83,27 @@ class CamOverlayAPI {
|
|
|
100
83
|
}
|
|
101
84
|
}
|
|
102
85
|
async getSingleService(serviceId, options) {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
action: 'get',
|
|
107
|
-
service_id: serviceId.toString(),
|
|
108
|
-
},
|
|
86
|
+
const res = await this._getJson(`${BASE_PATH}/services.cgi`, {
|
|
87
|
+
action: 'get',
|
|
88
|
+
service_id: serviceId,
|
|
109
89
|
}, options);
|
|
110
|
-
return CamOverlayAPI_1.servicesSchema.parse(
|
|
90
|
+
return CamOverlayAPI_1.servicesSchema.parse(res);
|
|
111
91
|
}
|
|
112
92
|
async getServices(options) {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
parameters: {
|
|
116
|
-
action: 'get',
|
|
117
|
-
},
|
|
118
|
-
}, options);
|
|
119
|
-
const services = CamOverlayAPI_1.serviceListSchema.parse(serviceList).services;
|
|
120
|
-
services.forEach((service) => {
|
|
121
|
-
const parsedService = CamOverlayAPI_1.servicesSchema.safeParse(service);
|
|
122
|
-
if (!parsedService.success) {
|
|
123
|
-
console.warn(`[SERVICE SCHEMA MISMATCH]: Service ${service.name} (${service.id}) does not match the current schema, or is a hidden service.`);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
93
|
+
const res = await this._getJson(`${BASE_PATH}/services.cgi`, { action: 'get' }, options);
|
|
94
|
+
const services = CamOverlayAPI_1.serviceListSchema.parse(res).services;
|
|
126
95
|
return services;
|
|
127
96
|
}
|
|
128
97
|
async updateSingleService(service, options) {
|
|
129
|
-
|
|
130
|
-
await this._postJsonEncoded(path, JSON.stringify(service), {
|
|
98
|
+
await this._postJsonEncoded(`${BASE_PATH}/services.cgi`, JSON.stringify(service), {
|
|
131
99
|
action: 'set',
|
|
132
|
-
service_id: service.id
|
|
133
|
-
},
|
|
100
|
+
service_id: service.id,
|
|
101
|
+
}, options, undefined);
|
|
134
102
|
}
|
|
135
103
|
async updateServices(services, options) {
|
|
136
|
-
|
|
137
|
-
await this._postJsonEncoded(path, JSON.stringify({ services: services }), {
|
|
104
|
+
await this._postJsonEncoded(`${BASE_PATH}/services.cgi`, JSON.stringify({ services: services }), {
|
|
138
105
|
action: 'set',
|
|
139
|
-
},
|
|
106
|
+
}, options, undefined);
|
|
140
107
|
}
|
|
141
108
|
updateCGText(serviceId, fields, options) {
|
|
142
109
|
const params = {};
|
|
@@ -197,9 +164,9 @@ class CamOverlayAPI {
|
|
|
197
164
|
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
198
165
|
}
|
|
199
166
|
}
|
|
200
|
-
async
|
|
167
|
+
async _getJson(path, parameters, options) {
|
|
201
168
|
const agent = this.getClient(options?.proxyParams);
|
|
202
|
-
const res = await agent.get({
|
|
169
|
+
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
203
170
|
if (res.ok) {
|
|
204
171
|
return await res.json();
|
|
205
172
|
}
|
|
@@ -207,9 +174,9 @@ class CamOverlayAPI {
|
|
|
207
174
|
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
208
175
|
}
|
|
209
176
|
}
|
|
210
|
-
async _post(
|
|
177
|
+
async _post(path, data, parameters, options, headers) {
|
|
211
178
|
const agent = this.getClient(options?.proxyParams);
|
|
212
|
-
const res = await agent.post({
|
|
179
|
+
const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
|
|
213
180
|
if (res.ok) {
|
|
214
181
|
return await res.json();
|
|
215
182
|
}
|
|
@@ -217,9 +184,9 @@ class CamOverlayAPI {
|
|
|
217
184
|
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
218
185
|
}
|
|
219
186
|
}
|
|
220
|
-
async _getBlob(
|
|
187
|
+
async _getBlob(path, parameters, options) {
|
|
221
188
|
const agent = this.getClient(options?.proxyParams);
|
|
222
|
-
const res = await agent.get({
|
|
189
|
+
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
223
190
|
if (res.ok) {
|
|
224
191
|
return await this.parseBlobResponse(res);
|
|
225
192
|
}
|
|
@@ -235,14 +202,14 @@ class CamOverlayAPI {
|
|
|
235
202
|
throw new errors_1.ParsingBlobError(err);
|
|
236
203
|
}
|
|
237
204
|
}
|
|
238
|
-
async _postUrlEncoded(path,
|
|
239
|
-
const data = (0, utils_1.paramToUrl)(
|
|
205
|
+
async _postUrlEncoded(path, parameters, options, headers) {
|
|
206
|
+
const data = (0, utils_1.paramToUrl)(parameters);
|
|
240
207
|
const baseHeaders = { 'Content-Type': 'application/x-www-form-urlencoded' };
|
|
241
|
-
return this._post(
|
|
208
|
+
return this._post(path, data, undefined, options, { ...baseHeaders, ...headers });
|
|
242
209
|
}
|
|
243
|
-
async _postJsonEncoded(path, data, parameters,
|
|
210
|
+
async _postJsonEncoded(path, data, parameters, options, headers) {
|
|
244
211
|
const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
|
|
245
|
-
return this._post(
|
|
212
|
+
return this._post(path, data, parameters, options, { ...baseHeaders, ...headers });
|
|
246
213
|
}
|
|
247
214
|
}
|
|
248
215
|
exports.CamOverlayAPI = CamOverlayAPI;
|
package/cjs/CamScripterAPI.js
CHANGED
|
@@ -11,51 +11,57 @@ class CamScripterAPI {
|
|
|
11
11
|
constructor(client) {
|
|
12
12
|
this.client = client;
|
|
13
13
|
}
|
|
14
|
-
static
|
|
14
|
+
static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
|
|
15
15
|
getClient(proxyParams) {
|
|
16
16
|
return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
|
|
17
17
|
}
|
|
18
18
|
async checkCameraTime(options) {
|
|
19
|
-
const
|
|
20
|
-
return CamScripterAPI_1.cameraTimeResponseSchema.parse(
|
|
19
|
+
const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
|
|
20
|
+
return CamScripterAPI_1.cameraTimeResponseSchema.parse(res).state;
|
|
21
21
|
}
|
|
22
22
|
async getNetworkCameraList(options) {
|
|
23
|
-
const
|
|
24
|
-
return common_1.networkCameraListSchema.parse(
|
|
23
|
+
const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
|
|
24
|
+
return common_1.networkCameraListSchema.parse(res.camera_list);
|
|
25
25
|
}
|
|
26
26
|
async getStorageInfo(options) {
|
|
27
|
-
const
|
|
28
|
-
return CamScripterAPI_1.storageSchema.parse(
|
|
27
|
+
const res = await this._getJson(`${BASE_PATH}/package/get_storage.cgi`, undefined, options);
|
|
28
|
+
return CamScripterAPI_1.storageSchema.parse(res);
|
|
29
29
|
}
|
|
30
30
|
async getPackageList(options) {
|
|
31
|
-
const
|
|
32
|
-
return CamScripterAPI_1.packageInfoListSchema.parse(
|
|
31
|
+
const res = await this._getJson(`${BASE_PATH}/package/list.cgi`, undefined, options);
|
|
32
|
+
return CamScripterAPI_1.packageInfoListSchema.parse(res);
|
|
33
33
|
}
|
|
34
34
|
async installPackages(formData, storage, options) {
|
|
35
|
-
const
|
|
36
|
-
return CamScripterAPI_1.camscripterApiResponseSchema.parse(
|
|
35
|
+
const res = await this._post(`${BASE_PATH}/package/install.cgi`, formData, { storage: storage }, options);
|
|
36
|
+
return CamScripterAPI_1.camscripterApiResponseSchema.parse(res);
|
|
37
37
|
}
|
|
38
38
|
async uninstallPackage(packageId, options) {
|
|
39
|
-
const
|
|
40
|
-
return CamScripterAPI_1.camscripterApiResponseSchema.parse(
|
|
39
|
+
const res = await this._getJson(`${BASE_PATH}/package/remove.cgi`, { package_name: packageId }, options);
|
|
40
|
+
return CamScripterAPI_1.camscripterApiResponseSchema.parse(res);
|
|
41
41
|
}
|
|
42
42
|
async importSettings(packageId, formData, options) {
|
|
43
|
-
const
|
|
44
|
-
|
|
43
|
+
const res = await this._post(`${BASE_PATH}/package/data.cgi`, formData, {
|
|
44
|
+
action: 'IMPORT',
|
|
45
|
+
package_name: packageId,
|
|
46
|
+
}, options);
|
|
47
|
+
return CamScripterAPI_1.camscripterApiResponseSchema.parse(res);
|
|
45
48
|
}
|
|
46
49
|
async exportSettings(packageId, formData, options) {
|
|
47
|
-
const
|
|
48
|
-
|
|
50
|
+
const res = await this._post(`${BASE_PATH}/package/data.cgi`, formData, {
|
|
51
|
+
action: 'EXPORT',
|
|
52
|
+
package_name: packageId,
|
|
53
|
+
}, options);
|
|
54
|
+
return CamScripterAPI_1.camscripterApiResponseSchema.parse(res);
|
|
49
55
|
}
|
|
50
56
|
async getNodejsStatus(options) {
|
|
51
|
-
const
|
|
52
|
-
return CamScripterAPI_1.nodeStateSchema.parse(
|
|
57
|
+
const res = await this._getJson(`${BASE_PATH}/diagnostics.cgi`, undefined, options);
|
|
58
|
+
return CamScripterAPI_1.nodeStateSchema.parse(res);
|
|
53
59
|
}
|
|
54
60
|
async installNodejs(storage, options) {
|
|
55
|
-
const
|
|
56
|
-
return CamScripterAPI_1.camscripterApiResponseSchema.parse(
|
|
61
|
+
const res = await this._getJson(`${BASE_PATH}/node_update.cgi`, { storage: storage }, options);
|
|
62
|
+
return CamScripterAPI_1.camscripterApiResponseSchema.parse(res);
|
|
57
63
|
}
|
|
58
|
-
async
|
|
64
|
+
async _getJson(path, parameters, options) {
|
|
59
65
|
const agent = this.getClient(options?.proxyParams);
|
|
60
66
|
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
61
67
|
if (res.ok) {
|
|
@@ -65,9 +71,9 @@ class CamScripterAPI {
|
|
|
65
71
|
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
|
-
async
|
|
74
|
+
async _post(path, data, parameters, options, headers) {
|
|
69
75
|
const agent = this.getClient(options?.proxyParams);
|
|
70
|
-
const res = await agent.post({ path, data, parameters, timeout: options?.timeout });
|
|
76
|
+
const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
|
|
71
77
|
if (res.ok) {
|
|
72
78
|
return await res.json();
|
|
73
79
|
}
|
package/cjs/CamStreamerAPI.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.parseCameraStreamResponse = exports.CamStreamerAPI = void 0;
|
|
7
|
-
const zod_1 =
|
|
4
|
+
const zod_1 = require("zod");
|
|
8
5
|
const ProxyClient_1 = require("./internal/ProxyClient");
|
|
9
6
|
const utils_1 = require("./internal/utils");
|
|
10
7
|
const CamStreamerAPI_1 = require("./types/CamStreamerAPI");
|
|
@@ -17,28 +14,42 @@ class CamStreamerAPI {
|
|
|
17
14
|
getClient(proxyParams) {
|
|
18
15
|
return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
|
|
19
16
|
}
|
|
17
|
+
async wsAuthorization(options) {
|
|
18
|
+
const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
|
|
19
|
+
if (res.status !== 200) {
|
|
20
|
+
throw new Error(`Server error on ws authorization: ${res.message}`);
|
|
21
|
+
}
|
|
22
|
+
return zod_1.z.string().parse(res.data);
|
|
23
|
+
}
|
|
24
|
+
async getUtcTime(options) {
|
|
25
|
+
const res = await this._getJson(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
|
|
26
|
+
if (res.status !== 200) {
|
|
27
|
+
throw new Error(`Server error on get UTC time: ${res.message}`);
|
|
28
|
+
}
|
|
29
|
+
return zod_1.z.number().parse(res.data);
|
|
30
|
+
}
|
|
20
31
|
async getStreamList(options) {
|
|
21
|
-
const
|
|
22
|
-
const list = zod_1.
|
|
23
|
-
const
|
|
32
|
+
const res = await this._getJson(`${BASE_PATH}/stream/list.cgi`, undefined, options);
|
|
33
|
+
const list = zod_1.z.record(zod_1.z.string(), CamStreamerAPI_1.cameraStreamSchema).parse(res.data);
|
|
34
|
+
const streamList = {};
|
|
24
35
|
for (const [key, data] of Object.entries(list)) {
|
|
25
36
|
const streamId = parseInt(key);
|
|
26
|
-
|
|
37
|
+
streamList[streamId] = (0, exports.parseCameraStreamResponse)(data);
|
|
27
38
|
}
|
|
28
|
-
return
|
|
39
|
+
return streamList;
|
|
29
40
|
}
|
|
30
41
|
async getStream(streamId, options) {
|
|
31
|
-
const
|
|
32
|
-
const cameraData = CamStreamerAPI_1.cameraStreamSchema.parse(
|
|
42
|
+
const res = await this._getJson(`${BASE_PATH}/stream/get.cgi`, { stream_id: streamId }, options);
|
|
43
|
+
const cameraData = CamStreamerAPI_1.cameraStreamSchema.parse(res.data);
|
|
33
44
|
return (0, exports.parseCameraStreamResponse)(cameraData);
|
|
34
45
|
}
|
|
35
46
|
async getStreamParameter(streamId, paramName, options) {
|
|
36
|
-
const
|
|
37
|
-
return
|
|
47
|
+
const res = await this._getJson(`${BASE_PATH}/stream/get.cgi`, { stream_id: streamId }, options);
|
|
48
|
+
return zod_1.z.string().parse(res.data[paramName]);
|
|
38
49
|
}
|
|
39
50
|
async setStream(streamId, params, options) {
|
|
40
51
|
const { streamDelay, startTime, stopTime, ...rest } = params;
|
|
41
|
-
return await this.
|
|
52
|
+
return await this._getJson(`${BASE_PATH}/stream/set.cgi`, {
|
|
42
53
|
stream_id: streamId,
|
|
43
54
|
streamDelay: streamDelay ?? '',
|
|
44
55
|
startTime: startTime ?? null,
|
|
@@ -47,31 +58,17 @@ class CamStreamerAPI {
|
|
|
47
58
|
}, options);
|
|
48
59
|
}
|
|
49
60
|
async setStreamParameter(streamId, paramName, value, options) {
|
|
50
|
-
return await this.
|
|
61
|
+
return await this._getJson(`${BASE_PATH}/stream/set.cgi`, { stream_id: streamId, [paramName]: value }, options);
|
|
51
62
|
}
|
|
52
63
|
async isStreaming(streamId, options) {
|
|
53
|
-
const
|
|
54
|
-
return
|
|
64
|
+
const res = await this._getJson(`${BASE_PATH}/get_streamstat.cgi`, { stream_id: streamId }, options);
|
|
65
|
+
return res.data.is_streaming === 1;
|
|
55
66
|
}
|
|
56
67
|
async deleteStream(streamId, options) {
|
|
57
|
-
const res = await this.
|
|
68
|
+
const res = await this._getJson(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
|
|
58
69
|
return res.data.status === 200;
|
|
59
70
|
}
|
|
60
|
-
async
|
|
61
|
-
const res = await this.get(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
|
|
62
|
-
if (res.status !== 200) {
|
|
63
|
-
throw new Error(`Server error on ws authorization: ${res.message}`);
|
|
64
|
-
}
|
|
65
|
-
return res.data;
|
|
66
|
-
}
|
|
67
|
-
async getUtcTime(options) {
|
|
68
|
-
const res = await this.get(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
|
|
69
|
-
if (res.status !== 200) {
|
|
70
|
-
throw new Error(`Server error on get UTC time: ${res.message}`);
|
|
71
|
-
}
|
|
72
|
-
return res.data;
|
|
73
|
-
}
|
|
74
|
-
async get(path, parameters, options) {
|
|
71
|
+
async _getJson(path, parameters, options) {
|
|
75
72
|
const agent = this.getClient(options?.proxyParams);
|
|
76
73
|
const res = await agent.get({ path, parameters, timeout: options?.timeout });
|
|
77
74
|
if (res.ok) {
|