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.
Files changed (79) hide show
  1. package/README.md +38 -27
  2. package/cjs/CamOverlayAPI.js +42 -75
  3. package/cjs/CamScripterAPI.js +30 -24
  4. package/cjs/CamStreamerAPI.js +30 -33
  5. package/cjs/CamSwitcherAPI.js +57 -52
  6. package/cjs/PlaneTrackerAPI.js +55 -66
  7. package/cjs/VapixAPI.js +23 -22
  8. package/cjs/{CamOverlayDrawingAPI.js → node/CamOverlayDrawingAPI.js} +1 -1
  9. package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/Painter.js +4 -14
  10. package/cjs/{CamScripterAPICameraEventsGenerator.js → node/CamScripterAPICameraEventsGenerator.js} +1 -1
  11. package/cjs/{VapixEvents.js → node/VapixEvents.js} +1 -1
  12. package/cjs/node/events/GenetecAgent.js +5 -27
  13. package/cjs/node/index.js +17 -0
  14. package/cjs/types/CamOverlayAPI/CamOverlayAPI.js +2 -2
  15. package/cjs/types/CamOverlayAPI/scoreBoardSchema.js +6 -1
  16. package/cjs/types/CamOverlayPainter.js +12 -0
  17. package/cjs/types/CamScripterAPICameraEventsGenerator.js +2 -0
  18. package/cjs/types/CamSwitcherAPI.js +38 -1
  19. package/cjs/types/GenetecAgent.js +31 -0
  20. package/cjs/types/PlaneTrackerAPI.js +277 -0
  21. package/cjs/types/VapixAPI.js +20 -2
  22. package/cjs/types/VapixEvents.js +2 -0
  23. package/esm/CamOverlayAPI.js +43 -76
  24. package/esm/CamScripterAPI.js +30 -24
  25. package/esm/CamStreamerAPI.js +30 -30
  26. package/esm/CamSwitcherAPI.js +58 -53
  27. package/esm/PlaneTrackerAPI.js +56 -67
  28. package/esm/VapixAPI.js +24 -23
  29. package/esm/{CamOverlayDrawingAPI.js → node/CamOverlayDrawingAPI.js} +1 -1
  30. package/esm/{CamOverlayPainter → node/CamOverlayPainter}/Painter.js +1 -11
  31. package/esm/{CamScripterAPICameraEventsGenerator.js → node/CamScripterAPICameraEventsGenerator.js} +1 -1
  32. package/esm/{VapixEvents.js → node/VapixEvents.js} +1 -1
  33. package/esm/node/events/GenetecAgent.js +1 -23
  34. package/esm/node/index.js +10 -0
  35. package/esm/types/CamOverlayAPI/CamOverlayAPI.js +1 -1
  36. package/esm/types/CamOverlayAPI/scoreBoardSchema.js +6 -1
  37. package/esm/types/CamOverlayPainter.js +11 -1
  38. package/esm/types/CamSwitcherAPI.js +38 -1
  39. package/esm/types/GenetecAgent.js +28 -0
  40. package/esm/types/PlaneTrackerAPI.js +276 -1
  41. package/esm/types/VapixAPI.js +19 -1
  42. package/esm/types/VapixEvents.js +1 -0
  43. package/package.json +1 -1
  44. package/types/CamOverlayAPI.d.ts +24 -14
  45. package/types/CamScripterAPI.d.ts +34 -9
  46. package/types/CamStreamerAPI.d.ts +27 -5
  47. package/types/CamSwitcherAPI.d.ts +136 -23
  48. package/types/PlaneTrackerAPI.d.ts +201 -20
  49. package/types/VapixAPI.d.ts +46 -12
  50. package/types/bin/CreatePackage.d.ts +1 -0
  51. package/types/{CamOverlayDrawingAPI.d.ts → node/CamOverlayDrawingAPI.d.ts} +1 -1
  52. package/types/{CamOverlayPainter → node/CamOverlayPainter}/Frame.d.ts +2 -2
  53. package/types/{CamOverlayPainter → node/CamOverlayPainter}/Painter.d.ts +2 -13
  54. package/types/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.d.ts +1 -1
  55. package/types/node/CamScripterAPICameraEventsGenerator.d.ts +31 -0
  56. package/types/node/VapixEvents.d.ts +16 -0
  57. package/types/node/events/GenetecAgent.d.ts +1 -144
  58. package/types/node/index.d.ts +10 -0
  59. package/types/types/CamOverlayAPI/CamOverlayAPI.d.ts +38 -38
  60. package/types/types/CamOverlayAPI/scoreBoardSchema.d.ts +13 -13
  61. package/types/types/CamOverlayDrawingAPI.d.ts +3 -13
  62. package/types/types/CamOverlayPainter.d.ts +12 -10
  63. package/types/types/CamScripterAPICameraEventsGenerator.d.ts +45 -0
  64. package/types/types/CamStreamerAPI.d.ts +2 -2
  65. package/types/types/CamSwitcherAPI.d.ts +111 -30
  66. package/types/types/GenetecAgent.d.ts +174 -0
  67. package/types/types/PlaneTrackerAPI.d.ts +859 -0
  68. package/types/types/VapixAPI.d.ts +54 -8
  69. package/types/types/VapixEvents.d.ts +15 -0
  70. package/types/types/common.d.ts +1 -0
  71. package/types/CamScripterAPICameraEventsGenerator.d.ts +0 -74
  72. package/types/VapixEvents.d.ts +0 -43
  73. /package/cjs/{CreatePackage.js → bin/CreatePackage.js} +0 -0
  74. /package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/Frame.js +0 -0
  75. /package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.js +0 -0
  76. /package/esm/{CreatePackage.js → bin/CreatePackage.js} +0 -0
  77. /package/esm/{CamOverlayPainter → node/CamOverlayPainter}/Frame.js +0 -0
  78. /package/esm/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.js +0 -0
  79. /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 Node.js modules
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 1.\*.\* to 2.\*.\*
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
- > However, events `open` and `close` are still emitted in case you need to react to them.
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
- > It returns (Response object)[https://developer.mozilla.org/en-US/docs/Web/API/Response] which doesn't contain data by default.
104
- > If you need to wait for data, you can call for example the function `await res.text()`.
105
- > This change affects the function `vapixGet` from (CameraVapix)[doc/CameraVapix.md] too.
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.
@@ -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 response = await this._get({ path: `${BASE_PATH}/camera_time.cgi` }, options);
24
- return zod_1.z.boolean().parse(response.state);
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 response = await this._get({ path: `${BASE_PATH}/network_camera_list.cgi` }, options);
28
- return common_1.networkCameraListSchema.parse(response.camera_list);
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 response = await this._get({ path: `${BASE_PATH}/ws_authorization.cgi` }, options);
32
- return CamOverlayAPI_1.WSResponseSchema.parse(response).message;
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 files = await this._get({
41
- path: `${BASE_PATH}/upload_${fileType}.cgi`,
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
- path: `${BASE_PATH}/upload_${fileType}.cgi`,
51
- data: formData,
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
- const path = `${BASE_PATH}/upload_${fileType}.cgi`;
60
- await this._postUrlEncoded(path, {
48
+ await this._postUrlEncoded(`${BASE_PATH}/upload_${fileType}.cgi`, {
61
49
  action: 'remove',
62
50
  ...fileParams,
63
- }, undefined, options);
51
+ }, options, undefined);
64
52
  }
65
53
  async getFileStorage(fileType, options) {
66
- const data = await this._get({
67
- path: `${BASE_PATH}/upload_${fileType}.cgi`,
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(data.list);
58
+ return CamOverlayAPI_1.storageDataListSchema.parse(res.list);
76
59
  }
77
60
  async getFilePreviewFromCamera(path, options) {
78
- return await this._getBlob({ path: CamOverlayAPI.getFilePreviewPath(path) }, options);
61
+ return await this._getBlob(CamOverlayAPI.getFilePreviewPath(path), undefined, options);
79
62
  }
80
63
  async updateInfoticker(serviceId, text, options) {
81
- await this._get({ path: `${BASE_PATH}/infoticker.cgi?service_id=${serviceId}&text=${text}` }, options);
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({ path: `${BASE_PATH}/enabled.cgi?id_${serviceId}=${enabled ? 1 : 0}`, data: '' }, options);
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 data = await this._get({
104
- path: `${BASE_PATH}/services.cgi`,
105
- parameters: {
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(data);
90
+ return CamOverlayAPI_1.servicesSchema.parse(res);
111
91
  }
112
92
  async getServices(options) {
113
- const serviceList = await this._get({
114
- path: `${BASE_PATH}/services.cgi`,
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
- const path = `${BASE_PATH}/services.cgi`;
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.toString(),
133
- }, undefined, options);
100
+ service_id: service.id,
101
+ }, options, undefined);
134
102
  }
135
103
  async updateServices(services, options) {
136
- const path = `${BASE_PATH}/services.cgi`;
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
- }, undefined, options);
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 _get(params, options) {
167
+ async _getJson(path, parameters, options) {
201
168
  const agent = this.getClient(options?.proxyParams);
202
- const res = await agent.get({ ...params, timeout: options?.timeout });
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(params, options) {
177
+ async _post(path, data, parameters, options, headers) {
211
178
  const agent = this.getClient(options?.proxyParams);
212
- const res = await agent.post({ ...params, timeout: options?.timeout });
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(params, options) {
187
+ async _getBlob(path, parameters, options) {
221
188
  const agent = this.getClient(options?.proxyParams);
222
- const res = await agent.get({ ...params, timeout: options?.timeout });
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, params, headers, options) {
239
- const data = (0, utils_1.paramToUrl)(params);
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({ path, data, headers: { ...baseHeaders, ...headers } }, options);
208
+ return this._post(path, data, undefined, options, { ...baseHeaders, ...headers });
242
209
  }
243
- async _postJsonEncoded(path, data, parameters, headers, options) {
210
+ async _postJsonEncoded(path, data, parameters, options, headers) {
244
211
  const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
245
- return this._post({ path, data, parameters, headers: { ...baseHeaders, ...headers } }, options);
212
+ return this._post(path, data, parameters, options, { ...baseHeaders, ...headers });
246
213
  }
247
214
  }
248
215
  exports.CamOverlayAPI = CamOverlayAPI;
@@ -11,51 +11,57 @@ class CamScripterAPI {
11
11
  constructor(client) {
12
12
  this.client = client;
13
13
  }
14
- static getProxyUrlPath = () => `${BASE_PATH}/proxy.cgi`;
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 data = await this.get(`${BASE_PATH}/camera_time.cgi`, undefined, options);
20
- return CamScripterAPI_1.cameraTimeResponseSchema.parse(data).state;
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 data = await this.get(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
24
- return common_1.networkCameraListSchema.parse(data.camera_list);
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 data = await this.get(`${BASE_PATH}/package/get_storage.cgi`, undefined, options);
28
- return CamScripterAPI_1.storageSchema.parse(data);
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 data = await this.get(`${BASE_PATH}/package/list.cgi`, undefined, options);
32
- return CamScripterAPI_1.packageInfoListSchema.parse(data);
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 data = await this.post(`${BASE_PATH}/package/install.cgi?storage=${storage}`, formData, undefined, options);
36
- return CamScripterAPI_1.camscripterApiResponseSchema.parse(data);
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 data = await this.get(`${BASE_PATH}/package/remove.cgi?package_name=${packageId}`, undefined, options);
40
- return CamScripterAPI_1.camscripterApiResponseSchema.parse(data);
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 data = await this.post(`${BASE_PATH}/package/data.cgi?action=IMPORT&package_name=${packageId}`, formData, undefined, options);
44
- return CamScripterAPI_1.camscripterApiResponseSchema.parse(data);
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 data = await this.post(`${BASE_PATH}/package/data.cgi?action=EXPORT&package_name=${packageId}`, formData, undefined, options);
48
- return CamScripterAPI_1.camscripterApiResponseSchema.parse(data);
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 data = await this.get(`${BASE_PATH}/diagnostics.cgi`, undefined, options);
52
- return CamScripterAPI_1.nodeStateSchema.parse(data);
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 data = await this.get(`${BASE_PATH}/node_update.cgi?storage=${storage}`, undefined, options);
56
- return CamScripterAPI_1.camscripterApiResponseSchema.parse(data);
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 get(path, parameters, options) {
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 post(path, data, parameters, options) {
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
  }
@@ -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 = __importDefault(require("zod"));
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 streamListRes = await this.get(`${BASE_PATH}/stream/list.cgi`, undefined, options);
22
- const list = zod_1.default.record(zod_1.default.string(), CamStreamerAPI_1.cameraStreamSchema).parse(streamListRes.data);
23
- const res = {};
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
- res[streamId] = (0, exports.parseCameraStreamResponse)(data);
37
+ streamList[streamId] = (0, exports.parseCameraStreamResponse)(data);
27
38
  }
28
- return res;
39
+ return streamList;
29
40
  }
30
41
  async getStream(streamId, options) {
31
- const stream = await this.get(`${BASE_PATH}/stream/get.cgi?stream_id=${streamId}`, undefined, options);
32
- const cameraData = CamStreamerAPI_1.cameraStreamSchema.parse(stream.data);
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 stream = await this.get(`${BASE_PATH}/stream/get.cgi?stream_id=${streamId}`, undefined, options);
37
- return stream.data[paramName];
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.get(`${BASE_PATH}/stream/set.cgi`, {
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.get(`${BASE_PATH}/stream/set.cgi?stream_id=${streamId}&${paramName}=${value}`, undefined, options);
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 response = await this.get(`${BASE_PATH}/get_streamstat.cgi?stream_id=${streamId}`, undefined, options);
54
- return response.data.is_streaming === 1;
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.get(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
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 getWsAuthorization(options) {
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) {