camstreamerlib 4.0.0-beta.4 → 4.0.0-beta.40

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