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
@@ -1,6 +1,6 @@
1
- import * as AdmZip from 'adm-zip';
2
- import * as Path from 'path';
3
- import * as fs from 'fs';
1
+ import AdmZip from 'adm-zip';
2
+ import Path from 'path';
3
+ import fs from 'fs';
4
4
  import { execSync } from 'child_process';
5
5
  const productionModulesFolder = 'production_modules';
6
6
  function isDirectory(path) {
@@ -16,6 +16,24 @@ export class ParsingBlobError extends Error {
16
16
  this.name = 'ParsingBlobError';
17
17
  }
18
18
  }
19
+ export class JsonParseError extends Error {
20
+ constructor(paramName, data) {
21
+ super(`Error: in JSON parsing of ${paramName}. Cannot parse: ${data}`);
22
+ this.name = 'JsonParseError';
23
+ }
24
+ }
25
+ export class ParameterNotFoundError extends Error {
26
+ constructor(paramName) {
27
+ super(`Error: no parameter '${paramName}' was found`);
28
+ this.name = 'ParameterNotFoundError';
29
+ }
30
+ }
31
+ export class SettingParameterError extends Error {
32
+ constructor(message) {
33
+ super(`Error setting parameter to camera: ${message}`);
34
+ this.name = 'SettingParameterError';
35
+ }
36
+ }
19
37
  export class ApplicationAPIError extends Error {
20
38
  constructor(action, res) {
21
39
  super(`[APP ${action}] Error: ` + res);
@@ -64,3 +82,51 @@ export class AddNewClipError extends Error {
64
82
  this.name = 'AddNewClipError';
65
83
  }
66
84
  }
85
+ export class PtzNotSupportedError extends Error {
86
+ constructor() {
87
+ super('Ptz not supported.');
88
+ this.name = 'PtzNotSupportedError';
89
+ }
90
+ }
91
+ export class StorageDataFetchError extends Error {
92
+ constructor(err) {
93
+ super('Error fetching storage data: ' + err);
94
+ this.name = 'StorageDataFetchError';
95
+ }
96
+ }
97
+ export class WsAuthorizationError extends Error {
98
+ constructor(message) {
99
+ super('Server error on ws authorization: ' + message);
100
+ this.name = 'WsAuthorizationError';
101
+ }
102
+ }
103
+ export class UtcTimeFetchError extends Error {
104
+ constructor(message) {
105
+ super('Server error on get UTC time: ' + message);
106
+ this.name = 'UtcTimeFetchError';
107
+ }
108
+ }
109
+ export class TimezoneNotSetupError extends Error {
110
+ constructor() {
111
+ super('Time zone not setup on the device');
112
+ this.name = 'TimezoneNotSetupError';
113
+ }
114
+ }
115
+ export class TimezoneFetchError extends Error {
116
+ constructor(err) {
117
+ super('Error fetching time zone information: ' + err);
118
+ this.name = 'TimezoneFetchError';
119
+ }
120
+ }
121
+ export class ResetCalibrationError extends Error {
122
+ constructor(type, err) {
123
+ super('Error resetting ' + type.toLowerCase() + ' calibration: ' + err);
124
+ this.name = 'ResetCalibrationError';
125
+ }
126
+ }
127
+ export class ImportSettingsError extends Error {
128
+ constructor(err) {
129
+ super('Error importing settings: ' + err);
130
+ this.name = 'ImportSettingsError';
131
+ }
132
+ }
package/esm/index.js CHANGED
@@ -1,11 +1,20 @@
1
- export * from './internal/common';
1
+ export * from './internal/types';
2
2
  export * from './internal/constants';
3
3
  export * from './internal/utils';
4
4
  export * from './internal/versionCompare';
5
+ export * from './internal/ProxyClient';
5
6
  export * from './types/common';
7
+ export { CamOverlayAPI } from './CamOverlayAPI';
8
+ export * from './types/CamOverlayAPI';
9
+ export { CamScripterAPI } from './CamScripterAPI';
10
+ export * from './types/CamScripterAPI';
11
+ export { CamStreamerAPI } from './CamStreamerAPI';
12
+ export * from './types/CamStreamerAPI';
6
13
  export { CamSwitcherAPI } from './CamSwitcherAPI';
14
+ export * from './types/CamSwitcherAPI';
7
15
  export { CamSwitcherEvents } from './CamSwitcherEvents';
8
- export { VapixAPI } from './VapixAPI';
9
16
  export * from './types/CamSwitcherEvents';
10
- export * from './types/CamSwitcherAPI';
17
+ export { PlaneTrackerAPI } from './PlaneTrackerAPI';
18
+ export * from './types/PlaneTrackerAPI';
19
+ export { VapixAPI } from './VapixAPI';
11
20
  export * from './types/VapixAPI';
@@ -1,40 +1,36 @@
1
1
  import { addParametersToPath } from './utils';
2
2
  export class ProxyClient {
3
3
  client;
4
- getProxyUrl;
5
- constructor(client, getProxyUrl) {
4
+ proxyParams;
5
+ constructor(client, proxyParams) {
6
6
  this.client = client;
7
- this.getProxyUrl = getProxyUrl;
7
+ this.proxyParams = proxyParams;
8
8
  }
9
- get = (proxy, path, parameters, headers = {}) => {
10
- const url = addParametersToPath(path, parameters);
11
- const { realUrl, realHeaders } = this.getReal(proxy, url, headers);
12
- return this.client.get(realUrl, {}, realHeaders);
13
- };
14
- post = (proxy, path, data, parameters, headers) => {
15
- const url = addParametersToPath(path, parameters);
16
- const { realUrl, realHeaders } = this.getReal(proxy, url, headers);
17
- return this.client.post(realUrl, data, {}, realHeaders);
18
- };
19
- getReal = (proxy, url, headers) => {
20
- if (proxy !== null) {
21
- return {
22
- realUrl: this.getProxyUrl(),
23
- realHeaders: {
24
- ...(headers ?? {}),
25
- 'x-target-camera-protocol': proxy.port === 443 ? 'https' : 'http',
26
- 'x-target-camera-path': url,
27
- 'x-target-camera-ip': proxy.ip,
28
- 'x-target-camera-mdns': proxy.mdnsName,
29
- 'x-target-camera-port': String(proxy.port),
30
- 'x-target-camera-pass': encodeURIComponent(proxy.pass),
31
- 'x-target-camera-user': encodeURIComponent(proxy.user),
32
- },
33
- };
34
- }
9
+ get(params) {
10
+ const { path, parameters, headers, timeout } = params;
11
+ const targetPath = addParametersToPath(path, parameters);
12
+ const { realPath, realHeaders } = this.getReal(targetPath, headers);
13
+ return this.client.get({ path: realPath, headers: realHeaders, timeout });
14
+ }
15
+ post(params) {
16
+ const { path, data, parameters, headers, timeout } = params;
17
+ const targetPath = addParametersToPath(path, parameters);
18
+ const { realPath, realHeaders } = this.getReal(targetPath, headers);
19
+ return this.client.post({ path: realPath, data, headers: realHeaders, timeout });
20
+ }
21
+ getReal(targetPath, headers) {
35
22
  return {
36
- realUrl: url,
37
- realHeaders: headers,
23
+ realPath: this.proxyParams.path,
24
+ realHeaders: {
25
+ ...(headers ?? {}),
26
+ 'x-target-camera-protocol': this.proxyParams.target.port === 443 ? 'https' : 'http',
27
+ 'x-target-camera-path': targetPath,
28
+ 'x-target-camera-ip': this.proxyParams.target.ip,
29
+ 'x-target-camera-mdns': this.proxyParams.target.mdnsName,
30
+ 'x-target-camera-port': String(this.proxyParams.target.port),
31
+ 'x-target-camera-pass': this.proxyParams.target.pass,
32
+ 'x-target-camera-user': this.proxyParams.target.user,
33
+ },
38
34
  };
39
- };
35
+ }
40
36
  }
@@ -0,0 +1,68 @@
1
+ export class WsEvents {
2
+ zodSchema;
3
+ ws;
4
+ _isDestroyed = false;
5
+ listeners = {};
6
+ constructor(zodSchema, ws) {
7
+ this.zodSchema = zodSchema;
8
+ this.ws = ws;
9
+ this.ws.onmessage = (e) => this.onMessage(e);
10
+ }
11
+ get isDestroyed() {
12
+ return this._isDestroyed;
13
+ }
14
+ resendInitData() {
15
+ const request = {
16
+ command: 'sendInitData',
17
+ };
18
+ this.ws.send(JSON.stringify(request));
19
+ }
20
+ addListener(type, listener, id) {
21
+ const typeList = this.listeners[type];
22
+ if (typeList === undefined) {
23
+ this.listeners[type] = { [id]: listener };
24
+ return;
25
+ }
26
+ typeList[id] = listener;
27
+ }
28
+ removeListener(type, id) {
29
+ const typeList = this.listeners[type];
30
+ if (typeList) {
31
+ delete typeList[id];
32
+ if (Object.keys(typeList).length === 0) {
33
+ delete this.listeners[type];
34
+ }
35
+ }
36
+ }
37
+ onMessage(evt) {
38
+ if (this.isDestroyed) {
39
+ return;
40
+ }
41
+ try {
42
+ const eventData = JSON.parse(evt.data);
43
+ const data = this.zodSchema.parse(eventData);
44
+ if (isInitEvent(data)) {
45
+ this.processMessage(data.data, true);
46
+ return;
47
+ }
48
+ this.processMessage(data, false);
49
+ }
50
+ catch (error) {
51
+ console.error('Error parsing event data:', evt.data, error);
52
+ }
53
+ }
54
+ processMessage(event, isInit) {
55
+ const listeners = this.listeners[event.type];
56
+ const list = Object.values(listeners ?? {});
57
+ list.forEach((listener) => listener(event, isInit));
58
+ }
59
+ destroy() {
60
+ this._isDestroyed = true;
61
+ this.ws.onmessage = () => { };
62
+ this.ws.destroy();
63
+ this.listeners = {};
64
+ }
65
+ }
66
+ const isInitEvent = (event) => {
67
+ return event.type === 'init';
68
+ };
@@ -1,4 +1,3 @@
1
- import { isNullish } from './common';
2
1
  export const addParametersToPath = (path, params) => {
3
2
  if (params === undefined || Object.keys(params).length === 0) {
4
3
  return path;
@@ -32,3 +31,20 @@ export const isClip = (id) => id?.charAt(0) === 's';
32
31
  export const isTracker = (id) => id?.charAt(0) === 't';
33
32
  export const isPlaylist = (id) => id?.charAt(0) === 'p';
34
33
  export const isLoopPlayType = (playType) => playType.includes('LOOP');
34
+ export async function responseStringify(res) {
35
+ return JSON.stringify({
36
+ status: res.status,
37
+ body: await res.text(),
38
+ });
39
+ }
40
+ export function pad(num, size) {
41
+ const sign = Math.sign(num) === -1 ? '-' : '';
42
+ return (sign +
43
+ new Array(size)
44
+ .concat([Math.abs(num)])
45
+ .join('0')
46
+ .slice(-size));
47
+ }
48
+ export function isNullish(value) {
49
+ return value === null || value === undefined;
50
+ }
@@ -1,5 +1,5 @@
1
- import * as EventEmitter from 'events';
2
- import { WsClient } from './node/WsClient';
1
+ import EventEmitter from 'events';
2
+ import { WsClient } from './WsClient';
3
3
  export class CamOverlayDrawingAPI extends EventEmitter {
4
4
  tls;
5
5
  tlsInsecure;
@@ -54,6 +54,14 @@ export class Frame extends EventEmitter {
54
54
  this.width = width;
55
55
  this.height = height;
56
56
  }
57
+ getFrameInfo() {
58
+ return {
59
+ x: this.posX,
60
+ y: this.posY,
61
+ width: this.width,
62
+ height: this.height,
63
+ };
64
+ }
57
65
  setText(text, align, textType = 'TFM_OVERFLOW', fontColor) {
58
66
  this.text = text;
59
67
  this.align = align;
@@ -73,6 +81,16 @@ export class Frame extends EventEmitter {
73
81
  this.fontName = undefined;
74
82
  this.font = fontData;
75
83
  }
84
+ getTextInfo() {
85
+ return {
86
+ text: this.text,
87
+ textAlign: this.align,
88
+ textType: this.textType,
89
+ fontColor: this.fontColor,
90
+ font: this.font,
91
+ fontName: this.fontName,
92
+ };
93
+ }
76
94
  setBgColor(color) {
77
95
  this.bgColor = color;
78
96
  }
@@ -89,6 +107,14 @@ export class Frame extends EventEmitter {
89
107
  setBgType(type) {
90
108
  this.bgType = type;
91
109
  }
110
+ getBgInfo() {
111
+ return {
112
+ bgColor: this.bgColor,
113
+ bgImage: this.bgImage,
114
+ bgImageName: this.bgImageName,
115
+ bgType: this.bgType,
116
+ };
117
+ }
92
118
  setBorderRadius(radius) {
93
119
  this.borderRadius = radius;
94
120
  }
@@ -98,6 +124,13 @@ export class Frame extends EventEmitter {
98
124
  setBorderColor(color) {
99
125
  this.borderColor = color;
100
126
  }
127
+ getBorderInfo() {
128
+ return {
129
+ borderRadius: this.borderRadius,
130
+ borderWidth: this.borderWidth,
131
+ borderColor: this.borderColor,
132
+ };
133
+ }
101
134
  setCustomDraw(customDraw) {
102
135
  this.customDraw = customDraw;
103
136
  }
@@ -1,17 +1,7 @@
1
1
  import { CamOverlayDrawingAPI } from '../CamOverlayDrawingAPI';
2
- import ResourceManager from './ResourceManager';
2
+ import { ResourceManager } from './ResourceManager';
3
3
  import { Frame } from './Frame';
4
- export const COORD = {
5
- top_left: [-1, -1],
6
- center_left: [-1, 0],
7
- bottom_left: [-1, 1],
8
- top_center: [0, -1],
9
- center: [0, 0],
10
- bottom_center: [0, 1],
11
- top_right: [1, -1],
12
- center_right: [1, 0],
13
- bottom_right: [1, 1],
14
- };
4
+ import { COORD } from '../../types/CamOverlayPainter';
15
5
  export class Painter extends Frame {
16
6
  screenWidth;
17
7
  screenHeight;
@@ -163,4 +153,3 @@ export class Painter extends Frame {
163
153
  }
164
154
  }
165
155
  }
166
- export { Frame, ResourceManager };
@@ -1,5 +1,5 @@
1
1
  import * as fs from 'fs/promises';
2
- export default class ResourceManager {
2
+ export class ResourceManager {
3
3
  co;
4
4
  imgFileNames = {};
5
5
  fontFileNames = {};
@@ -18,8 +18,9 @@ export default class ResourceManager {
18
18
  if (this.images[moniker] !== undefined) {
19
19
  return this.images[moniker];
20
20
  }
21
- if (this.imgFileNames[moniker] !== undefined) {
22
- const imgData = await fs.readFile(this.imgFileNames[moniker]);
21
+ const path = this.imgFileNames[moniker];
22
+ if (path !== undefined) {
23
+ const imgData = await fs.readFile(path);
23
24
  this.images[moniker] = await this.co.uploadImageData(imgData);
24
25
  return this.images[moniker];
25
26
  }
@@ -29,8 +30,9 @@ export default class ResourceManager {
29
30
  if (this.fonts[moniker] !== undefined) {
30
31
  return this.fonts[moniker];
31
32
  }
32
- if (this.fontFileNames[moniker] !== undefined) {
33
- const fontData = await fs.readFile(this.fontFileNames[moniker]);
33
+ const path = this.fontFileNames[moniker];
34
+ if (path !== undefined) {
35
+ const fontData = await fs.readFile(path);
34
36
  this.fonts[moniker] = await this.co.uploadFontData(fontData);
35
37
  return this.fonts[moniker];
36
38
  }
@@ -1,5 +1,5 @@
1
- import * as EventEmitter from 'events';
2
- import { WsClient } from './node/WsClient';
1
+ import EventEmitter from 'events';
2
+ import { WsClient } from './WsClient';
3
3
  export class CamScripterAPICameraEventsGenerator extends EventEmitter {
4
4
  tls;
5
5
  tlsInsecure;
@@ -22,29 +22,27 @@ export class DefaultClient {
22
22
  }
23
23
  this.httpRequestSender = new HttpRequestSender(agentOptions);
24
24
  }
25
- get url() {
26
- return `${this.tls ? 'https' : 'http'}://${this.user}:${this.pass}@${this.ip}:${this.port}`;
27
- }
28
- async get(path, parameters = {}, headers) {
29
- const options = this.getBaseConnectionParams('GET', path, parameters);
30
- options.headers = headers;
25
+ get(params) {
26
+ const { path, parameters, headers, timeout } = params;
27
+ const options = this.getBaseConnectionParams('GET', path, parameters, headers, timeout);
31
28
  return this.httpRequestSender.sendRequest(options);
32
29
  }
33
- async post(path, data, parameters = {}, headers) {
34
- const options = this.getBaseConnectionParams('POST', path, parameters);
35
- options.headers = headers;
30
+ post(params) {
31
+ const { path, data, parameters, headers, timeout } = params;
32
+ const options = this.getBaseConnectionParams('POST', path, parameters, headers, timeout);
36
33
  return this.httpRequestSender.sendRequest(options, data);
37
34
  }
38
- getBaseConnectionParams(method, path, params) {
39
- const pathName = addParametersToPath(path, params);
35
+ getBaseConnectionParams(method, path, params, headers, timeout) {
40
36
  return {
41
37
  method: method,
42
38
  protocol: this.tls ? 'https:' : 'http:',
43
39
  host: this.ip,
44
40
  port: this.port,
45
- path: pathName,
41
+ path: addParametersToPath(path, params),
46
42
  user: this.user,
47
43
  pass: this.pass,
44
+ headers,
45
+ timeout,
48
46
  };
49
47
  }
50
48
  }
@@ -1,4 +1,4 @@
1
- import * as crypto from 'crypto';
1
+ import crypto from 'crypto';
2
2
  export class Digest {
3
3
  nonceCount = 1;
4
4
  getAuthHeader(user, pass, method, uri, wwwAuthenticateHeader) {
@@ -1,4 +1,4 @@
1
- import { Digest } from '../internal/Digest';
1
+ import { Digest } from './Digest';
2
2
  import { Agent, fetch as undiciFetch, Request as UndiciRequest, } from 'undici';
3
3
  export class HttpRequestSender {
4
4
  agent;
@@ -8,8 +8,18 @@ export class HttpRequestSender {
8
8
  connect: { rejectUnauthorized: agentOptions?.rejectUnaurhorized, keepAlive: agentOptions?.keepAlive },
9
9
  });
10
10
  }
11
- sendRequest(options, postData) {
12
- return this.sendRequestWithAuth(options, postData);
11
+ async sendRequest(options, postData) {
12
+ const stackHolder = { stack: '' };
13
+ Error.captureStackTrace(stackHolder, this.sendRequest);
14
+ try {
15
+ return await this.sendRequestWithAuth(options, postData);
16
+ }
17
+ catch (err) {
18
+ if (err instanceof Error) {
19
+ err.stack = `${err.stack}\nCaptured at:\n${stackHolder.stack}`;
20
+ }
21
+ throw err;
22
+ }
13
23
  }
14
24
  async sendRequestWithAuth(options, postData, wwwAuthenticateHeader) {
15
25
  options.timeout ??= 10000;
@@ -79,7 +89,7 @@ export class HttpRequestSender {
79
89
  return authData.digest.getAuthHeader(options.user, options.pass, options.method ?? 'GET', options.path, authData.wwwAuthenticateHeader);
80
90
  }
81
91
  else {
82
- return `Basic ${btoa(options.user + ':' + options.pass)}`;
92
+ return `Basic ${Buffer.from(`${options.user}:${options.pass}`).toString('base64')}`;
83
93
  }
84
94
  }
85
95
  }
@@ -1,8 +1,8 @@
1
- import * as http from 'http';
2
- import * as url from 'url';
3
- import * as fs from 'fs';
4
- import * as path from 'path';
5
- import * as EventEmitter from 'events';
1
+ import http from 'http';
2
+ import url from 'url';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import EventEmitter from 'events';
6
6
  export class HttpServer extends EventEmitter {
7
7
  host;
8
8
  port;
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter2 as EventEmitter } from 'eventemitter2';
2
- import { WsClient } from './node/WsClient';
2
+ import { WsClient } from './WsClient';
3
3
  export class VapixEvents extends EventEmitter {
4
4
  tls;
5
5
  tlsInsecure;
@@ -1,6 +1,6 @@
1
- import * as EventEmitter from 'events';
2
- import * as WebSocket from 'ws';
3
- import { Digest } from '../internal/Digest';
1
+ import EventEmitter from 'events';
2
+ import WebSocket from 'ws';
3
+ import { Digest } from './Digest';
4
4
  export class WsClient extends EventEmitter {
5
5
  user;
6
6
  pass;
@@ -1,18 +1,17 @@
1
- import { DefaultClient } from '../node/DefaultClient';
2
- import { isClient, pad } from '../internal/common';
1
+ import { pad } from '../../internal/utils';
2
+ import { ProxyClient } from '../../internal/ProxyClient';
3
+ import { DefaultClient } from '../DefaultClient';
3
4
  export class AxisCameraStationEvents {
4
5
  sourceKey;
5
6
  client;
6
- constructor(sourceKey, opt = {}) {
7
+ constructor(clientOptions, sourceKey) {
7
8
  this.sourceKey = sourceKey;
8
- if (isClient(opt)) {
9
- this.client = opt;
10
- }
11
- else {
12
- this.client = new DefaultClient(opt);
13
- }
9
+ this.client = new DefaultClient(clientOptions);
14
10
  }
15
- async sendEvent(data, eventType) {
11
+ getClient(proxyParams) {
12
+ return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
13
+ }
14
+ async sendEvent(data, eventType, options) {
16
15
  const dateString = this.getDate();
17
16
  const event = {
18
17
  addExternalDataRequest: {
@@ -23,9 +22,15 @@ export class AxisCameraStationEvents {
23
22
  },
24
23
  };
25
24
  const eventData = JSON.stringify(event);
26
- const res = await this.client.post('/Acs/Api/ExternalDataFacade/AddExternalData', eventData, undefined, {
27
- 'Content-Type': 'application/json',
28
- 'Content-Length': eventData.length.toString(),
25
+ const agent = this.getClient(options?.proxyParams);
26
+ const res = await agent.post({
27
+ path: '/Acs/Api/ExternalDataFacade/AddExternalData',
28
+ data: eventData,
29
+ headers: {
30
+ 'Content-Type': 'application/json',
31
+ 'Content-Length': eventData.length.toString(),
32
+ },
33
+ timeout: options?.timeout,
29
34
  });
30
35
  if (!res.ok) {
31
36
  throw new Error(`ACS status code: ${res.status}`);