camstreamerlib 4.0.0-beta.4 → 4.0.0-beta.41

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 (240) 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 +210 -0
  8. package/cjs/VapixAPI.js +323 -233
  9. package/cjs/{CreatePackage.js → bin/CreatePackage.js} +22 -19
  10. package/cjs/errors/errors.js +78 -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 +286 -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 +206 -0
  62. package/esm/VapixAPI.js +315 -225
  63. package/esm/{CreatePackage.js → bin/CreatePackage.js} +3 -3
  64. package/esm/errors/errors.js +66 -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 +283 -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 +230 -0
  115. package/types/VapixAPI.d.ts +118 -0
  116. package/types/bin/CreatePackage.d.ts +1 -0
  117. package/types/errors/errors.d.ts +68 -0
  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 +890 -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/errors/errors.d.ts +0 -34
  208. package/esm/events/AxisCameraStationEvents.d.ts +0 -9
  209. package/esm/events/GenetecAgent.js +0 -119
  210. package/esm/index.d.ts +0 -11
  211. package/esm/internal/Digest.d.ts +0 -4
  212. package/esm/internal/ProxyClient.d.ts +0 -11
  213. package/esm/internal/common.d.ts +0 -39
  214. package/esm/internal/common.js +0 -20
  215. package/esm/internal/constants.d.ts +0 -1
  216. package/esm/internal/transformers.d.ts +0 -5
  217. package/esm/internal/utils.d.ts +0 -11
  218. package/esm/internal/versionCompare.d.ts +0 -6
  219. package/esm/node/DefaultClient.d.ts +0 -15
  220. package/esm/node/HttpServer.d.ts +0 -21
  221. package/esm/node/WsClient.d.ts +0 -39
  222. package/esm/node/WsEventClient.d.ts +0 -13
  223. package/esm/node/WsEventClient.js +0 -18
  224. package/esm/node/index.d.ts +0 -2
  225. package/esm/types/CamOverlayAPI.d.ts +0 -188
  226. package/esm/types/CamOverlayAPI.js +0 -44
  227. package/esm/types/CamScripterAPI.d.ts +0 -67
  228. package/esm/types/CamStreamerAPI.d.ts +0 -139
  229. package/esm/types/CamSwitcherEvents.d.ts +0 -491
  230. package/esm/types/VapixAPI.d.ts +0 -1683
  231. package/esm/web/DefaultClient.d.ts +0 -6
  232. package/esm/web/WsClient.d.ts +0 -13
  233. package/esm/web/index.d.ts +0 -2
  234. /package/{cjs/CreatePackage.d.ts → esm/internal/types.js} +0 -0
  235. /package/esm/{CreatePackage.d.ts → types/CamOverlayDrawingAPI.js} +0 -0
  236. /package/{cjs → types}/internal/constants.d.ts +0 -0
  237. /package/{cjs → types}/internal/transformers.d.ts +0 -0
  238. /package/{cjs/internal → types/node}/Digest.d.ts +0 -0
  239. /package/{cjs → types}/web/WsClient.d.ts +0 -0
  240. /package/{cjs/node → types/web}/index.d.ts +0 -0
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # CamStreamerLib - BETA
2
+
3
+ **This is beta version of CamStreamerLib v4, dont use it on production. Is going to be changed significantly.**
4
+
5
+ **The documentation is in progress**
6
+
7
+ Node.js helper library for CamStreamer ACAP applications.
8
+
9
+ The library is primarily developed for the CamScripter ACAP application running directly in Axis cameras.
10
+ Examples of CamScripter packages can be found at https://github.com/CamStreamer/CamScripterApp_examples
11
+
12
+ ## Installation
13
+
14
+ ```
15
+ npm install camstreamerlib
16
+ ```
17
+
18
+ ## Documentation for ACAP and Camera API
19
+
20
+
21
+ | API | Description |
22
+ | ------------- | ------------- |
23
+ | [VapixAPI](doc/VapixAPI.md) | Module to access Axis camera VAPIX interface. |
24
+ | [CamStreamerAPI](doc/CamStreamerAPI.md) | Module for easy control of video streaming in the CamStreamer ACAP application (RTMP, HLS, SRT and MPEG-TS protocols). |
25
+ | [CamOverlayAPI](doc/CamOverlayAPI.md) | Module to access CamOverlay API. |
26
+ | [CamScripterAPI](doc/CamScripterAPI.md) | Module to access CamScripter API. |
27
+ | [CamSwitcherAPI](doc/CamSwitcherAPI.md) | Module to access CamSwitcher API. |
28
+ | [PlaneTrackerAPI](doc/PlaneTrackerAPI.md) | Module to access PlaneTracker API. |
29
+
30
+ ## Documentation for Node.js modules
31
+
32
+ | Module | Description |
33
+ | ------------- | ------------- |
34
+ | [HttpServer](doc/HttpServer.md) | 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
+ | [VapixEvents](doc/VapixEvents.md) | Module which allows receiving camera events from the VAPIX API. |
36
+ | [CamOverlayDrawingAPI](doc/CamOverlayDrawingAPI.md) | Module for easy control of CamOverlay drawing API. For more details on supported video overlay drawing functions see https://camstreamer.com/camoverlay-api1 |
37
+ | [CamOverlayPainter](doc/CamOverlayPainter.md) | Contains three modules which makes easier to use CamOverlayDrawingAPI. |
38
+ | [CamScripterAPICameraEventsGenerator](doc/CamScripterAPICameraEventsGenerator.md) | 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. |
39
+ | [CamSwitcherEvents](doc/CamSwitcherEvents.md) | Module which allows receiving events from CamSwitcher ACAP application. |
40
+ | [GenetecAgent](doc/GenetecAgent.md) | Module which allows receiving and sending data to Genetec VMS. |
41
+
42
+
43
+ ## Breaking changes when moving from version 3.\*.\* to 4.\*.\* (latest)
44
+
45
+ ...
46
+
47
+
48
+ ## Breaking changes when moving from version 2.\*.\* to 3.\*.\*
49
+
50
+ - CamStreamerlib requiers Node.js version 18 or higher.
51
+ - CamOverlayDrawingAPI tries to reconnect when the websocket is closed. You don't have to do it manually.
52
+ > [!NOTE]
53
+ > However, events `open` and `close` are still emitted in case you need to react to them.
54
+ - Files `common.ts`, `Digest.ts`, `HttpRequest.ts` and `WsClient.ts` moved to a folder internal.
55
+ - Removed function `httpRequest()`. Use `sendRequest()` instead. It uses the same interface except for the "noWaitForData" parameter.
56
+ > [!IMPORTANT]
57
+ > It returns (Response object)[https://developer.mozilla.org/en-US/docs/Web/API/Response] which doesn't contain data by default.
58
+ > If you need to wait for data, you can call for example the function `await res.text()`.
59
+ > This change affects the function `vapixGet` from (CameraVapix)[doc/CameraVapix.md] too.
60
+
61
+ ## Breaking changes when moving from version 1.\*.\* to 2.\*.\*
62
+
63
+ - Renamed file HTTPRequest.ts to HttpRequest.ts
64
+ - Removed deprecated protocol attribute from all options objects (use tls instead).
65
+ - Removed RTSP
66
+ > [!IMPORTANT]
67
+ > Previously CameraVapix.ts supported both WebSocket and RTSP.
68
+ > Starting with version 2.0.0, it supports WebSocket only.
69
+ - ServiceID shouldn't be passed to CamOverlayAPI by the options object. Pass it as a parameter.
70
+ - Renamed CamOverlayDrawingAPI event msg to message.
71
+ - Drawing services extracted from CamOverlayAPI.ts to a separate file.
72
+ > [!IMPORTANT]
73
+ > Please read [CamOverlayAPI](doc/CamOverlayAPI.md) and [CamOverlayDrawingAPI](doc/CamOverlayDrawingAPI.md) for more information.
74
+
75
+
76
+ # For Developers
77
+
78
+ ### Publishing to npm repository
79
+
80
+ 1. Update version in package.json and push it
81
+ 2. Create git tag e.g. v1.2.4
82
+
83
+ - `git tag v1.2.4`
84
+ - `git push --tags`
85
+
86
+ 3. Publish new version to npm
87
+
88
+ - `npm publish ./dist`
89
+
90
+ 4. Edit GitHub release form.
91
+
92
+ ### Preparing a package to upload to CamScripter
93
+
94
+ If you want to create your own package and upload it to CamScripter App, you can use the script CreatePackage. It creates a zip file which contains all required files and directories in your package folder. The script accepts source code written either in JavaScript or TypeScript if the package has the correct structure (more information in https://github.com/CamStreamer/CamScripterApp_examples/#readme). To include this script in your package add the following lines in the file package.json:
95
+
96
+ ```json
97
+ "scripts": {
98
+ "create-package": "node node_modules/camstreamerlib/bin/CreatePackage.js"
99
+ }
100
+ ```
101
+
102
+ By default, the zipped package does not contain node_modules directory. If you want to include it (required when uploading to CamScripter App on Axis camera), add `-includeNodeModules` or `-i` parameter.
103
+
104
+ If you need to exclude a file or directory add `-exlude=` or `-e=` parameter with comma separated list.
105
+
106
+ The zip package is created in the current directory. You can choose different location with the `-where=` or `-w=` option.
107
+
108
+ ```json
109
+ "scripts": {
110
+ "create-package": "node node_modules/camstreamerlib/bin/CreatePackage.js -i -e=react"
111
+ }
112
+ ```
@@ -1,100 +1,115 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CamOverlayAPI = void 0;
4
- const common_1 = require("./internal/common");
5
- const DefaultClient_1 = require("./node/DefaultClient");
6
- const CamOverlayAPI_1 = require("./types/CamOverlayAPI");
4
+ const utils_1 = require("./internal/utils");
7
5
  const errors_1 = require("./errors/errors");
8
- const common_2 = require("./types/common");
6
+ const common_1 = require("./types/common");
7
+ const zod_1 = require("zod");
8
+ const ProxyClient_1 = require("./internal/ProxyClient");
9
+ const CamOverlayAPI_1 = require("./types/CamOverlayAPI");
10
+ const BASE_PATH = '/local/camoverlay/api';
9
11
  class CamOverlayAPI {
10
12
  client;
11
- constructor(options = {}) {
12
- if ((0, common_1.isClient)(options)) {
13
- this.client = options;
14
- }
15
- else {
16
- this.client = new DefaultClient_1.DefaultClient(options);
13
+ constructor(client) {
14
+ this.client = client;
15
+ }
16
+ static getBasePath = () => BASE_PATH;
17
+ static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
18
+ static getFilePreviewPath = (path) => `${BASE_PATH}/image.cgi?path=${encodeURIComponent(path)}`;
19
+ getClient(proxyParams) {
20
+ return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
21
+ }
22
+ async checkCameraTime(options) {
23
+ const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
24
+ return zod_1.z.boolean().parse(res.state);
25
+ }
26
+ async getNetworkCameraList(options) {
27
+ const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
28
+ return common_1.networkCameraListSchema.parse(res.camera_list);
29
+ }
30
+ async wsAuthorization(options) {
31
+ const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
32
+ return CamOverlayAPI_1.wsResponseSchema.parse(res).message;
33
+ }
34
+ async getMjpegStreamImage(mjpegUrl, options) {
35
+ return await this._getBlob(`${BASE_PATH}/fetch_mjpeg_image.cgi`, { mjpeg_url: decodeURIComponent(mjpegUrl) }, options);
36
+ }
37
+ async listFiles(fileType, options) {
38
+ const res = await this._getJson(`${BASE_PATH}/upload_${fileType}.cgi`, { action: 'list' }, options);
39
+ return CamOverlayAPI_1.fileListSchema.parse(res.list);
40
+ }
41
+ async uploadFile(fileType, formData, storage, options) {
42
+ await this._post(`${BASE_PATH}/upload_${fileType}.cgi`, formData, {
43
+ action: 'upload',
44
+ storage: storage,
45
+ }, options);
46
+ }
47
+ async removeFile(fileType, fileParams, options) {
48
+ await this._postUrlEncoded(`${BASE_PATH}/upload_${fileType}.cgi`, {
49
+ action: 'remove',
50
+ ...fileParams,
51
+ }, options, undefined);
52
+ }
53
+ async getFileStorage(fileType, options) {
54
+ const res = await this._getJson(`${BASE_PATH}/upload_${fileType}.cgi`, { action: 'get_storage' }, options);
55
+ if (res.code !== 200) {
56
+ throw new errors_1.StorageDataFetchError(res);
17
57
  }
58
+ return CamOverlayAPI_1.storageDataListSchema.parse(res.list);
18
59
  }
19
- async checkCameraTime() {
20
- const cameraTime = await this.get('/local/camoverlay/api/camera_time.cgi');
21
- return cameraTime.state;
22
- }
23
- async getNetworkCameraList() {
24
- const response = await this.get('/local/camoverlay/api/network_camera_list.cgi');
25
- return common_2.networkCameraListSchema.parse(response.camera_list);
26
- }
27
- async wsAutoratization() {
28
- const response = await this.get(`/local/camoverlay/api/ws_authorization.cgi`);
29
- return response.data;
60
+ async getFilePreviewFromCamera(path, options) {
61
+ return await this._getBlob(CamOverlayAPI.getFilePreviewPath(path), undefined, options);
30
62
  }
31
- async getMjpegStreamImage(mjpegUrl) {
32
- const res = await this.get(`/local/camoverlay/api/fetch_mjpeg_image.cgi?mjpeg_url=${encodeURIComponent(decodeURIComponent(mjpegUrl))}`);
33
- return await this.parseBlobResponse(res);
63
+ async updateInfoticker(serviceId, text, options) {
64
+ await this._getJson(`${BASE_PATH}/infoticker.cgi`, { service_id: serviceId, text: text }, options);
34
65
  }
35
- async listFiles(fileType) {
36
- const files = await this.get(`/local/camoverlay/api/upload_${fileType}.cgi?action=list`);
37
- return CamOverlayAPI_1.fileListSchema.parse(files.list);
66
+ async setEnabled(serviceId, enabled, options) {
67
+ await this._post(`${BASE_PATH}/enabled.cgi`, '', { [`id_${serviceId}`]: enabled ? 1 : 0 }, options);
38
68
  }
39
- async uploadFile(fileType, file, fileName) {
40
- const formData = new FormData();
41
- formData.append('target', 'SD0');
42
- formData.append('uploadedFile[]', file, fileName);
43
- const path = `/local/camoverlay/api/upload_${fileType}.cgi?action=upload`;
44
- await this.post(path, formData);
45
- }
46
- async removeFile(fileType, file) {
47
- const path = `/local/camoverlay/api/upload_${fileType}.cgi?action=remove`;
48
- await this.post(path, JSON.stringify(file));
49
- }
50
- async getFileStorage(fileType) {
51
- const data = await this.get(`/local/camoverlay/api/upload_${fileType}.cgi?action=get_storage`);
52
- return CamOverlayAPI_1.storageSchema.parse(data);
53
- }
54
- async updateInfoticker(serviceID, text) {
55
- await this.get(`/local/camoverlay/api/infoticker.cgi?service_id=${serviceID}&text=${text}`);
56
- }
57
- async setEnabled(serviceID, enabled) {
58
- await this.post(`/local/camoverlay/api/enabled.cgi?id_${serviceID}=${enabled ? 1 : 0}`, '');
59
- }
60
- async isEnabled(serviceID) {
61
- const res = await this.client.get('/local/camoverlay/api/services.cgi?action=get');
69
+ async isEnabled(serviceId, options) {
70
+ const agent = this.getClient(options?.proxyParams);
71
+ const res = await agent.get({
72
+ path: `${BASE_PATH}/services.cgi`,
73
+ parameters: { action: 'get' },
74
+ timeout: options?.timeout,
75
+ });
62
76
  if (res.ok) {
63
77
  const data = JSON.parse(await res.text());
64
78
  for (const service of data.services) {
65
- if (service.id === serviceID) {
79
+ if (service.id === serviceId) {
66
80
  return service.enabled === 1;
67
81
  }
68
82
  }
69
83
  throw new errors_1.ServiceNotFoundError();
70
84
  }
71
85
  else {
72
- throw new Error(await (0, common_1.responseStringify)(res));
86
+ throw new Error(await (0, utils_1.responseStringify)(res));
73
87
  }
74
88
  }
75
- async getSingleService(serviceId) {
76
- const data = await this.get('/local/camoverlay/api/services.cgi', {
89
+ async getSingleService(serviceId, options) {
90
+ const res = await this._getJson(`${BASE_PATH}/services.cgi`, {
77
91
  action: 'get',
78
- service_id: serviceId.toString(),
79
- });
80
- return CamOverlayAPI_1.serviceSchema.parse(data);
92
+ service_id: serviceId,
93
+ }, options);
94
+ return CamOverlayAPI_1.servicesSchema.parse(res);
81
95
  }
82
- async getServices() {
83
- const serviceList = await this.get('/local/camoverlay/api/services.cgi?action=get');
84
- return CamOverlayAPI_1.serviceSchema.parse(serviceList).services;
96
+ async getServices(options) {
97
+ const res = await this._getJson(`${BASE_PATH}/services.cgi`, { action: 'get' }, options);
98
+ const services = CamOverlayAPI_1.serviceListSchema.parse(res).services;
99
+ return services;
85
100
  }
86
- async updateSingleService(serviceId, serviceJson) {
87
- const path = '/local/camoverlay/api/services.cgi';
88
- await this.post(path, JSON.stringify(serviceJson), {
101
+ async updateSingleService(service, options) {
102
+ await this._postJsonEncoded(`${BASE_PATH}/services.cgi`, JSON.stringify(service), {
89
103
  action: 'set',
90
- service_id: serviceId.toString(),
91
- });
104
+ service_id: service.id,
105
+ }, options, undefined);
92
106
  }
93
- async updateServices(servicesJson) {
94
- const path = '/local/camoverlay/api/services.cgi?action=set';
95
- await this.post(path, JSON.stringify(servicesJson));
107
+ async updateServices(services, options) {
108
+ await this._postJsonEncoded(`${BASE_PATH}/services.cgi`, JSON.stringify({ services: services }), {
109
+ action: 'set',
110
+ }, options, undefined);
96
111
  }
97
- updateCGText(serviceID, fields) {
112
+ updateCGText(serviceId, fields, options) {
98
113
  const params = {};
99
114
  for (const field of fields) {
100
115
  const name = field.field_name;
@@ -103,74 +118,102 @@ class CamOverlayAPI {
103
118
  params[`${name}_color`] = field.color;
104
119
  }
105
120
  }
106
- return this.promiseCGUpdate(serviceID, 'update_text', params);
121
+ return this.promiseCGUpdate(serviceId, 'update_text', params, undefined, undefined, options);
107
122
  }
108
- updateCGImagePos(serviceID, coordinates = '', x = 0, y = 0) {
123
+ updateCGImagePos(serviceId, coordinates = '', x = 0, y = 0, options) {
109
124
  const params = {
110
125
  coord_system: coordinates,
111
126
  pos_x: x,
112
127
  pos_y: y,
113
128
  };
114
- return this.promiseCGUpdate(serviceID, 'update_image', params);
129
+ return this.promiseCGUpdate(serviceId, 'update_image', params, undefined, undefined, options);
115
130
  }
116
- updateCGImage(serviceID, path, coordinates = '', x = 0, y = 0) {
131
+ updateCGImage(serviceId, path, coordinates = '', x = 0, y = 0, options) {
117
132
  const params = {
118
133
  coord_system: coordinates,
119
134
  pos_x: x,
120
135
  pos_y: y,
121
136
  image: path,
122
137
  };
123
- return this.promiseCGUpdate(serviceID, 'update_image', params);
138
+ return this.promiseCGUpdate(serviceId, 'update_image', params, undefined, undefined, options);
124
139
  }
125
- updateCGImageFromData(serviceID, imageType, imageData, coordinates = '', x = 0, y = 0) {
140
+ updateCGImageFromData(serviceId, imageType, imageData, coordinates = '', x = 0, y = 0, options) {
126
141
  const contentType = imageType === CamOverlayAPI_1.ImageType.PNG ? 'image/png' : 'image/jpeg';
127
142
  const params = {
128
143
  coord_system: coordinates,
129
144
  pos_x: x,
130
145
  pos_y: y,
131
146
  };
132
- return this.promiseCGUpdate(serviceID, 'update_image', params, contentType, imageData);
147
+ return this.promiseCGUpdate(serviceId, 'update_image', params, contentType, imageData, options);
133
148
  }
134
- async promiseCGUpdate(serviceID, action, params = {}, contentType, data) {
135
- const path = `/local/camoverlay/api/customGraphics.cgi`;
149
+ async promiseCGUpdate(serviceId, action, params = {}, contentType, data, options) {
150
+ const path = `${BASE_PATH}/customGraphics.cgi`;
136
151
  let headers = {};
137
- if (contentType !== undefined && data) {
152
+ if (contentType !== undefined && data !== undefined) {
138
153
  headers = { 'Content-Type': contentType };
139
154
  }
140
- const res = await this.client.post(path, data ?? '', {
141
- action: action,
142
- service_id: serviceID.toString(),
143
- ...params,
144
- }, headers);
155
+ const agent = this.getClient(options?.proxyParams);
156
+ const res = await agent.post({
157
+ path,
158
+ data: data ?? '',
159
+ parameters: {
160
+ action: action,
161
+ service_id: serviceId.toString(),
162
+ ...params,
163
+ },
164
+ headers,
165
+ timeout: options?.timeout,
166
+ });
145
167
  if (!res.ok) {
146
- throw new Error(await (0, common_1.responseStringify)(res));
168
+ throw new Error(await (0, utils_1.responseStringify)(res));
147
169
  }
148
170
  }
149
- async get(path, params) {
150
- const res = await this.client.get(path, params);
171
+ async _getJson(path, parameters, options) {
172
+ const agent = this.getClient(options?.proxyParams);
173
+ const res = await agent.get({ path, parameters, timeout: options?.timeout });
151
174
  if (res.ok) {
152
175
  return await res.json();
153
176
  }
154
177
  else {
155
- throw new Error(await (0, common_1.responseStringify)(res));
178
+ throw new Error(await (0, utils_1.responseStringify)(res));
156
179
  }
157
180
  }
158
- async post(path, data, params) {
159
- const res = await this.client.post(path, data, params);
181
+ async _post(path, data, parameters, options, headers) {
182
+ const agent = this.getClient(options?.proxyParams);
183
+ const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
160
184
  if (res.ok) {
161
185
  return await res.json();
162
186
  }
163
187
  else {
164
- throw new Error(await (0, common_1.responseStringify)(res));
188
+ throw new Error(await (0, utils_1.responseStringify)(res));
189
+ }
190
+ }
191
+ async _getBlob(path, parameters, options) {
192
+ const agent = this.getClient(options?.proxyParams);
193
+ const res = await agent.get({ path, parameters, timeout: options?.timeout });
194
+ if (res.ok) {
195
+ return await this.parseBlobResponse(res);
196
+ }
197
+ else {
198
+ throw new Error(await (0, utils_1.responseStringify)(res));
165
199
  }
166
200
  }
167
201
  async parseBlobResponse(response) {
168
202
  try {
169
- return await response.blob();
203
+ return (await response.blob());
170
204
  }
171
205
  catch (err) {
172
206
  throw new errors_1.ParsingBlobError(err);
173
207
  }
174
208
  }
209
+ async _postUrlEncoded(path, parameters, options, headers) {
210
+ const data = (0, utils_1.paramToUrl)(parameters);
211
+ const baseHeaders = { 'Content-Type': 'application/x-www-form-urlencoded' };
212
+ return this._post(path, data, undefined, options, { ...baseHeaders, ...headers });
213
+ }
214
+ async _postJsonEncoded(path, data, parameters, options, headers) {
215
+ const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
216
+ return this._post(path, data, parameters, options, { ...baseHeaders, ...headers });
217
+ }
175
218
  }
176
219
  exports.CamOverlayAPI = CamOverlayAPI;
@@ -1,70 +1,80 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CamOverlayAPI = void 0;
4
- const common_1 = require("./internal/common");
5
- const DefaultClient_1 = require("./node/DefaultClient");
3
+ exports.CamScripterAPI = void 0;
4
+ const ProxyClient_1 = require("./internal/ProxyClient");
5
+ const utils_1 = require("./internal/utils");
6
6
  const CamScripterAPI_1 = require("./types/CamScripterAPI");
7
- const common_2 = require("./types/common");
8
- class CamOverlayAPI {
7
+ const common_1 = require("./types/common");
8
+ const BASE_PATH = '/local/camscripter';
9
+ class CamScripterAPI {
9
10
  client;
10
- constructor(options = {}) {
11
- if ((0, common_1.isClient)(options)) {
12
- this.client = options;
13
- }
14
- else {
15
- this.client = new DefaultClient_1.DefaultClient(options);
16
- }
11
+ constructor(client) {
12
+ this.client = client;
13
+ }
14
+ static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
15
+ getClient(proxyParams) {
16
+ return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
17
17
  }
18
- async checkCameraTime() {
19
- return (await this.get('/local/camscripter/camera_time.cgi')).state;
18
+ async checkCameraTime(options) {
19
+ const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
20
+ return CamScripterAPI_1.cameraTimeResponseSchema.parse(res).state;
20
21
  }
21
- async getStorageInfo() {
22
- const data = await this.get(`/local/camscripter/package/get_storage.cgi`);
23
- return CamScripterAPI_1.storageSchema.parse(data);
22
+ async getNetworkCameraList(options) {
23
+ const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
24
+ return common_1.networkCameraListSchema.parse(res.camera_list);
24
25
  }
25
- async getNetworkCameraList() {
26
- const response = await this.get('/local/camscripter/network_camera_list.cgi');
27
- return common_2.networkCameraListSchema.parse(response.camera_list);
26
+ async getStorageInfo(options) {
27
+ const res = await this._getJson(`${BASE_PATH}/package/get_storage.cgi`, undefined, options);
28
+ return CamScripterAPI_1.cameraStorageSchema.parse(res);
28
29
  }
29
- async getPackageList() {
30
- const data = await this.get('/local/camscripter/package/list.cgi');
31
- return CamScripterAPI_1.packageInfoListSchema.parse(data);
30
+ async getPackageList(options) {
31
+ const res = await this._getJson(`${BASE_PATH}/package/list.cgi`, undefined, options);
32
+ return CamScripterAPI_1.packageInfoListSchema.parse(res);
32
33
  }
33
- async installPackages(formData, storage) {
34
- await this.post(`/local/camscripter/package/install.cgi?storage=${storage}`, formData);
34
+ async installPackages(formData, storage, options) {
35
+ await this._post(`${BASE_PATH}/package/install.cgi`, formData, { storage: storage }, options);
35
36
  }
36
- async uninstallPackage(packageId) {
37
- await this.get(`/local/camscripter/package/remove.cgi?package_name=${packageId}`);
37
+ async uninstallPackage(packageId, options) {
38
+ await this._getJson(`${BASE_PATH}/package/remove.cgi`, { package_name: packageId }, options);
38
39
  }
39
- async importSettings(packageId, formData) {
40
- await this.post(`/local/camscripter/package/data.cgi?action=IMPORT&package_name=${packageId}`, formData);
40
+ async importSettings(packageId, formData, options) {
41
+ await this._post(`${BASE_PATH}/package/data.cgi`, formData, {
42
+ action: 'IMPORT',
43
+ package_name: packageId,
44
+ }, options);
41
45
  }
42
- async exportSettings(packageId, formData) {
43
- await this.post(`/local/camscripter/package/data.cgi?action=EXPORT&package_name=${packageId}`, formData);
46
+ async exportSettings(packageId, formData, options) {
47
+ await this._post(`${BASE_PATH}/package/data.cgi`, formData, {
48
+ action: 'EXPORT',
49
+ package_name: packageId,
50
+ }, options);
44
51
  }
45
- async getNodejsStatus() {
46
- return (await this.get('/local/camscripter/diagnostics.cgi')).node_state;
52
+ async getNodejsStatus(options) {
53
+ const res = await this._getJson(`${BASE_PATH}/diagnostics.cgi`, undefined, options);
54
+ return CamScripterAPI_1.nodeStateSchema.parse(res);
47
55
  }
48
- async installNodejs(storage) {
49
- await this.get(`/local/camscripter/node_update.cgi?storage=${storage}`);
56
+ async installNodejs(storage, options) {
57
+ await this._getJson(`${BASE_PATH}/node_update.cgi`, { storage: storage }, options);
50
58
  }
51
- async get(path, params) {
52
- const res = await this.client.get(path, params);
59
+ async _getJson(path, parameters, options) {
60
+ const agent = this.getClient(options?.proxyParams);
61
+ const res = await agent.get({ path, parameters, timeout: options?.timeout });
53
62
  if (res.ok) {
54
63
  return await res.json();
55
64
  }
56
65
  else {
57
- throw new Error(await (0, common_1.responseStringify)(res));
66
+ throw new Error(await (0, utils_1.responseStringify)(res));
58
67
  }
59
68
  }
60
- async post(path, data, params) {
61
- const res = await this.client.post(path, data, params);
69
+ async _post(path, data, parameters, options, headers) {
70
+ const agent = this.getClient(options?.proxyParams);
71
+ const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
62
72
  if (res.ok) {
63
73
  return await res.json();
64
74
  }
65
75
  else {
66
- throw new Error(await (0, common_1.responseStringify)(res));
76
+ throw new Error(await (0, utils_1.responseStringify)(res));
67
77
  }
68
78
  }
69
79
  }
70
- exports.CamOverlayAPI = CamOverlayAPI;
80
+ exports.CamScripterAPI = CamScripterAPI;