camstreamerlib 4.0.0-beta.2 → 4.0.0-beta.21

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 (238) hide show
  1. package/README.md +5 -1
  2. package/cjs/CamOverlayAPI.d.ts +629 -0
  3. package/cjs/CamOverlayAPI.js +255 -0
  4. package/{CamOverlayDrawingAPI.d.ts → cjs/CamOverlayDrawingAPI.d.ts} +1 -1
  5. package/cjs/CamOverlayDrawingAPI.js +235 -0
  6. package/cjs/CamOverlayPainter/Frame.js +301 -0
  7. package/{CamOverlayPainter → cjs/CamOverlayPainter}/Painter.d.ts +14 -3
  8. package/cjs/CamOverlayPainter/Painter.js +171 -0
  9. package/cjs/CamOverlayPainter/ResourceManager.js +46 -0
  10. package/cjs/CamScripterAPI.d.ts +36 -0
  11. package/cjs/CamScripterAPI.js +73 -0
  12. package/{CamScripterAPICameraEventsGenerator.d.ts → cjs/CamScripterAPICameraEventsGenerator.d.ts} +1 -1
  13. package/cjs/CamScripterAPICameraEventsGenerator.js +162 -0
  14. package/{CamStreamerAPI.d.ts → cjs/CamStreamerAPI.d.ts} +5 -5
  15. package/cjs/CamStreamerAPI.js +59 -0
  16. package/{CamSwitcherAPI.d.ts → cjs/CamSwitcherAPI.d.ts} +10 -6
  17. package/cjs/CamSwitcherAPI.js +351 -0
  18. package/{CamSwitcherEvents.d.ts → cjs/CamSwitcherEvents.d.ts} +2 -2
  19. package/cjs/CamSwitcherEvents.js +67 -0
  20. package/cjs/CreatePackage.js +106 -0
  21. package/cjs/PlaneTrackerAPI.d.ts +47 -0
  22. package/cjs/PlaneTrackerAPI.js +176 -0
  23. package/{VapixAPI.d.ts → cjs/VapixAPI.d.ts} +19 -7
  24. package/cjs/VapixAPI.js +491 -0
  25. package/{VapixEvents.d.ts → cjs/VapixEvents.d.ts} +1 -1
  26. package/cjs/VapixEvents.js +88 -0
  27. package/{errors → cjs/errors}/errors.d.ts +3 -0
  28. package/cjs/errors/errors.js +86 -0
  29. package/{events → cjs/events}/AxisCameraStationEvents.d.ts +3 -2
  30. package/cjs/events/AxisCameraStationEvents.js +48 -0
  31. package/{events → cjs/events}/GenetecAgent.d.ts +4 -3
  32. package/cjs/events/GenetecAgent.js +123 -0
  33. package/cjs/index.d.ts +18 -0
  34. package/cjs/index.js +42 -0
  35. package/cjs/internal/Digest.js +42 -0
  36. package/cjs/internal/ProxyClient.d.ts +11 -0
  37. package/cjs/internal/ProxyClient.js +46 -0
  38. package/cjs/internal/constants.js +4 -0
  39. package/cjs/internal/transformers.js +32 -0
  40. package/cjs/internal/types.d.ts +35 -0
  41. package/cjs/internal/types.js +2 -0
  42. package/{internal → cjs/internal}/utils.d.ts +5 -1
  43. package/cjs/internal/utils.js +69 -0
  44. package/{internal → cjs/internal}/versionCompare.d.ts +2 -2
  45. package/cjs/internal/versionCompare.js +53 -0
  46. package/cjs/models/CamOverlayAPI/accuweatherSchema.d.ts +84 -0
  47. package/cjs/models/CamOverlayAPI/accuweatherSchema.js +48 -0
  48. package/cjs/models/CamOverlayAPI/constants.d.ts +11 -0
  49. package/cjs/models/CamOverlayAPI/constants.js +14 -0
  50. package/cjs/models/CamOverlayAPI/customGraphicsSchema.d.ts +699 -0
  51. package/cjs/models/CamOverlayAPI/customGraphicsSchema.js +73 -0
  52. package/cjs/models/CamOverlayAPI/fileSchema.d.ts +28 -0
  53. package/cjs/models/CamOverlayAPI/fileSchema.js +17 -0
  54. package/cjs/models/CamOverlayAPI/imagesSchema.d.ts +95 -0
  55. package/cjs/models/CamOverlayAPI/imagesSchema.js +10 -0
  56. package/cjs/models/CamOverlayAPI/index.d.ts +13 -0
  57. package/cjs/models/CamOverlayAPI/index.js +29 -0
  58. package/cjs/models/CamOverlayAPI/infotickerSchema.d.ts +96 -0
  59. package/cjs/models/CamOverlayAPI/infotickerSchema.js +27 -0
  60. package/cjs/models/CamOverlayAPI/pipSchema.d.ts +125 -0
  61. package/cjs/models/CamOverlayAPI/pipSchema.js +40 -0
  62. package/cjs/models/CamOverlayAPI/ptzCompassSchema.d.ts +93 -0
  63. package/cjs/models/CamOverlayAPI/ptzCompassSchema.js +26 -0
  64. package/cjs/models/CamOverlayAPI/ptzSchema.d.ts +118 -0
  65. package/cjs/models/CamOverlayAPI/ptzSchema.js +13 -0
  66. package/cjs/models/CamOverlayAPI/screenSharingSchema.d.ts +58 -0
  67. package/cjs/models/CamOverlayAPI/screenSharingSchema.js +9 -0
  68. package/cjs/models/CamOverlayAPI/webCameraSharingSchema.d.ts +58 -0
  69. package/cjs/models/CamOverlayAPI/webCameraSharingSchema.js +9 -0
  70. package/cjs/models/CamOverlayAPI/widgetCommonSchema.d.ts +126 -0
  71. package/cjs/models/CamOverlayAPI/widgetCommonSchema.js +76 -0
  72. package/cjs/models/CamOverlayAPI/widgetsSchema.d.ts +2823 -0
  73. package/cjs/models/CamOverlayAPI/widgetsSchema.js +27 -0
  74. package/cjs/node/DefaultClient.d.ts +16 -0
  75. package/cjs/node/DefaultClient.js +56 -0
  76. package/cjs/node/HttpRequestSender.js +89 -0
  77. package/cjs/node/HttpServer.js +96 -0
  78. package/{node → cjs/node}/WsClient.d.ts +1 -1
  79. package/cjs/node/WsClient.js +149 -0
  80. package/{node → cjs/node}/WsEventClient.d.ts +1 -1
  81. package/cjs/node/WsEventClient.js +22 -0
  82. package/cjs/node/index.d.ts +2 -0
  83. package/cjs/node/index.js +7 -0
  84. package/cjs/types/CamOverlayAPI.d.ts +328 -0
  85. package/cjs/types/CamOverlayAPI.js +26 -0
  86. package/{types → cjs/types}/CamScripterAPI.d.ts +66 -7
  87. package/cjs/types/CamScripterAPI.js +35 -0
  88. package/{types → cjs/types}/CamStreamerAPI.d.ts +16 -5
  89. package/cjs/types/CamStreamerAPI.js +32 -0
  90. package/{types → cjs/types}/CamSwitcherAPI.d.ts +5 -5
  91. package/cjs/types/CamSwitcherAPI.js +137 -0
  92. package/{types/CamswitcherEvents.d.ts → cjs/types/CamSwitcherEvents.d.ts} +77 -0
  93. package/cjs/types/CamSwitcherEvents.js +70 -0
  94. package/cjs/types/PlaneTrackerAPI.d.ts +2 -0
  95. package/cjs/types/PlaneTrackerAPI.js +2 -0
  96. package/{types → cjs/types}/VapixAPI.d.ts +479 -519
  97. package/cjs/types/VapixAPI.js +139 -0
  98. package/cjs/types/common.js +14 -0
  99. package/cjs/web/DefaultClient.d.ts +6 -0
  100. package/cjs/web/DefaultClient.js +22 -0
  101. package/cjs/web/WsClient.js +62 -0
  102. package/cjs/web/index.d.ts +2 -0
  103. package/cjs/web/index.js +7 -0
  104. package/esm/CamOverlayAPI.d.ts +629 -0
  105. package/esm/CamOverlayAPI.js +251 -0
  106. package/esm/CamOverlayDrawingAPI.d.ts +86 -0
  107. package/{CamOverlayDrawingAPI.js → esm/CamOverlayDrawingAPI.js} +6 -3
  108. package/esm/CamOverlayPainter/Frame.d.ts +96 -0
  109. package/esm/CamOverlayPainter/Painter.d.ts +48 -0
  110. package/{CamOverlayPainter → esm/CamOverlayPainter}/Painter.js +4 -1
  111. package/esm/CamOverlayPainter/ResourceManager.d.ts +14 -0
  112. package/{CamOverlayPainter → esm/CamOverlayPainter}/ResourceManager.js +6 -10
  113. package/esm/CamScripterAPI.d.ts +36 -0
  114. package/esm/CamScripterAPI.js +69 -0
  115. package/esm/CamScripterAPICameraEventsGenerator.d.ts +74 -0
  116. package/{CamScripterAPICameraEventsGenerator.js → esm/CamScripterAPICameraEventsGenerator.js} +6 -3
  117. package/esm/CamStreamerAPI.d.ts +16 -0
  118. package/{CamStreamerAPI.js → esm/CamStreamerAPI.js} +4 -10
  119. package/esm/CamSwitcherAPI.d.ts +52 -0
  120. package/{CamSwitcherAPI.js → esm/CamSwitcherAPI.js} +24 -27
  121. package/esm/CamSwitcherEvents.d.ts +18 -0
  122. package/{CamSwitcherEvents.js → esm/CamSwitcherEvents.js} +1 -1
  123. package/esm/CreatePackage.d.ts +1 -0
  124. package/esm/PlaneTrackerAPI.d.ts +47 -0
  125. package/esm/PlaneTrackerAPI.js +172 -0
  126. package/esm/VapixAPI.d.ts +78 -0
  127. package/{VapixAPI.js → esm/VapixAPI.js} +93 -60
  128. package/esm/VapixEvents.d.ts +43 -0
  129. package/{VapixEvents.js → esm/VapixEvents.js} +3 -3
  130. package/esm/errors/errors.d.ts +37 -0
  131. package/{errors → esm/errors}/errors.js +6 -0
  132. package/esm/events/AxisCameraStationEvents.d.ts +10 -0
  133. package/{events → esm/events}/AxisCameraStationEvents.js +1 -1
  134. package/esm/events/GenetecAgent.d.ts +175 -0
  135. package/{events → esm/events}/GenetecAgent.js +5 -5
  136. package/esm/index.d.ts +18 -0
  137. package/esm/index.js +18 -0
  138. package/esm/internal/Digest.d.ts +4 -0
  139. package/{internal → esm/internal}/Digest.js +6 -6
  140. package/esm/internal/ProxyClient.d.ts +11 -0
  141. package/{internal → esm/internal}/ProxyClient.js +6 -4
  142. package/esm/internal/constants.d.ts +1 -0
  143. package/esm/internal/transformers.d.ts +5 -0
  144. package/esm/internal/types.d.ts +35 -0
  145. package/esm/internal/types.js +1 -0
  146. package/esm/internal/utils.d.ts +15 -0
  147. package/{internal → esm/internal}/utils.js +20 -1
  148. package/esm/internal/versionCompare.d.ts +6 -0
  149. package/esm/models/CamOverlayAPI/accuweatherSchema.d.ts +84 -0
  150. package/esm/models/CamOverlayAPI/accuweatherSchema.js +45 -0
  151. package/esm/models/CamOverlayAPI/constants.d.ts +11 -0
  152. package/esm/models/CamOverlayAPI/constants.js +11 -0
  153. package/esm/models/CamOverlayAPI/customGraphicsSchema.d.ts +699 -0
  154. package/esm/models/CamOverlayAPI/customGraphicsSchema.js +70 -0
  155. package/esm/models/CamOverlayAPI/fileSchema.d.ts +28 -0
  156. package/esm/models/CamOverlayAPI/fileSchema.js +14 -0
  157. package/esm/models/CamOverlayAPI/imagesSchema.d.ts +95 -0
  158. package/esm/models/CamOverlayAPI/imagesSchema.js +7 -0
  159. package/esm/models/CamOverlayAPI/index.d.ts +13 -0
  160. package/esm/models/CamOverlayAPI/index.js +13 -0
  161. package/esm/models/CamOverlayAPI/infotickerSchema.d.ts +96 -0
  162. package/esm/models/CamOverlayAPI/infotickerSchema.js +24 -0
  163. package/esm/models/CamOverlayAPI/pipSchema.d.ts +125 -0
  164. package/esm/models/CamOverlayAPI/pipSchema.js +37 -0
  165. package/esm/models/CamOverlayAPI/ptzCompassSchema.d.ts +93 -0
  166. package/esm/models/CamOverlayAPI/ptzCompassSchema.js +23 -0
  167. package/esm/models/CamOverlayAPI/ptzSchema.d.ts +118 -0
  168. package/esm/models/CamOverlayAPI/ptzSchema.js +10 -0
  169. package/esm/models/CamOverlayAPI/screenSharingSchema.d.ts +58 -0
  170. package/esm/models/CamOverlayAPI/screenSharingSchema.js +6 -0
  171. package/esm/models/CamOverlayAPI/webCameraSharingSchema.d.ts +58 -0
  172. package/esm/models/CamOverlayAPI/webCameraSharingSchema.js +6 -0
  173. package/esm/models/CamOverlayAPI/widgetCommonSchema.d.ts +126 -0
  174. package/esm/models/CamOverlayAPI/widgetCommonSchema.js +73 -0
  175. package/esm/models/CamOverlayAPI/widgetsSchema.d.ts +2823 -0
  176. package/esm/models/CamOverlayAPI/widgetsSchema.js +24 -0
  177. package/esm/node/DefaultClient.d.ts +16 -0
  178. package/{node → esm/node}/DefaultClient.js +9 -7
  179. package/esm/node/HttpRequestSender.d.ts +28 -0
  180. package/esm/node/HttpServer.d.ts +21 -0
  181. package/{node → esm/node}/HttpServer.js +1 -1
  182. package/esm/node/WsClient.d.ts +39 -0
  183. package/esm/node/WsEventClient.d.ts +13 -0
  184. package/esm/node/index.d.ts +2 -0
  185. package/esm/node/index.js +2 -0
  186. package/esm/types/CamOverlayAPI.d.ts +328 -0
  187. package/esm/types/CamOverlayAPI.js +14 -0
  188. package/esm/types/CamScripterAPI.d.ts +126 -0
  189. package/esm/types/CamScripterAPI.js +32 -0
  190. package/esm/types/CamStreamerAPI.d.ts +150 -0
  191. package/{types → esm/types}/CamStreamerAPI.js +4 -0
  192. package/esm/types/CamSwitcherAPI.d.ts +814 -0
  193. package/esm/types/CamSwitcherEvents.d.ts +568 -0
  194. package/{types/CamswitcherEvents.js → esm/types/CamSwitcherEvents.js} +8 -0
  195. package/esm/types/PlaneTrackerAPI.d.ts +2 -0
  196. package/esm/types/PlaneTrackerAPI.js +1 -0
  197. package/esm/types/VapixAPI.d.ts +1664 -0
  198. package/{types → esm/types}/VapixAPI.js +30 -23
  199. package/esm/types/common.d.ts +37 -0
  200. package/esm/web/DefaultClient.d.ts +6 -0
  201. package/{web → esm/web}/DefaultClient.js +6 -4
  202. package/esm/web/WsClient.d.ts +13 -0
  203. package/{web → esm/web}/WsClient.js +2 -2
  204. package/esm/web/index.d.ts +2 -0
  205. package/esm/web/index.js +2 -0
  206. package/package.json +6 -6
  207. package/CamOverlayAPI.d.ts +0 -31
  208. package/CamOverlayAPI.js +0 -172
  209. package/CamScripterAPI.d.ts +0 -19
  210. package/CamScripterAPI.js +0 -66
  211. package/internal/ProxyClient.d.ts +0 -11
  212. package/internal/common.d.ts +0 -40
  213. package/internal/common.js +0 -23
  214. package/node/DefaultClient.d.ts +0 -15
  215. package/types/CamOverlayAPI.d.ts +0 -188
  216. package/types/CamOverlayAPI.js +0 -44
  217. package/types/CamScripterAPI.js +0 -17
  218. package/web/DefaultClient.d.ts +0 -6
  219. package/{CamOverlayPainter → cjs/CamOverlayPainter}/Frame.d.ts +0 -0
  220. package/{CamOverlayPainter → cjs/CamOverlayPainter}/ResourceManager.d.ts +0 -0
  221. package/{CreatePackage.d.ts → cjs/CreatePackage.d.ts} +0 -0
  222. package/{internal → cjs/internal}/Digest.d.ts +0 -0
  223. package/{internal → cjs/internal}/constants.d.ts +0 -0
  224. package/{internal → cjs/internal}/transformers.d.ts +0 -0
  225. package/{node → cjs/node}/HttpRequestSender.d.ts +0 -0
  226. package/{node → cjs/node}/HttpServer.d.ts +0 -0
  227. package/{types → cjs/types}/common.d.ts +2 -2
  228. /package/{web → cjs/web}/WsClient.d.ts +0 -0
  229. /package/{CamOverlayPainter → esm/CamOverlayPainter}/Frame.js +0 -0
  230. /package/{CreatePackage.js → esm/CreatePackage.js} +0 -0
  231. /package/{internal → esm/internal}/constants.js +0 -0
  232. /package/{internal → esm/internal}/transformers.js +0 -0
  233. /package/{internal → esm/internal}/versionCompare.js +0 -0
  234. /package/{node → esm/node}/HttpRequestSender.js +0 -0
  235. /package/{node → esm/node}/WsClient.js +0 -0
  236. /package/{node → esm/node}/WsEventClient.js +0 -0
  237. /package/{types → esm/types}/CamSwitcherAPI.js +0 -0
  238. /package/{types → esm/types}/common.js +0 -0
@@ -0,0 +1,491 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VapixAPI = void 0;
4
+ const prettifyXml = require("prettify-xml");
5
+ const utils_1 = require("./internal/utils");
6
+ const VapixAPI_1 = require("./types/VapixAPI");
7
+ const errors_1 = require("./errors/errors");
8
+ const ProxyClient_1 = require("./internal/ProxyClient");
9
+ const zod_1 = require("zod");
10
+ const fast_xml_parser_1 = require("fast-xml-parser");
11
+ class VapixAPI {
12
+ client;
13
+ constructor(client, getProxyUrl) {
14
+ this.client = new ProxyClient_1.ProxyClient(client, getProxyUrl);
15
+ }
16
+ async getUrlEncoded(proxy, path, parameters, headers = {}) {
17
+ const data = (0, utils_1.paramToUrl)(parameters);
18
+ const head = { ...headers, 'Content-Type': 'application/x-www-form-urlencoded' };
19
+ const res = await this.client.post(proxy, path, data, {}, head);
20
+ if (!res.ok) {
21
+ throw new Error(await (0, utils_1.responseStringify)(res));
22
+ }
23
+ return res;
24
+ }
25
+ async postJson(proxy, path, jsonData, headers = {}) {
26
+ const data = JSON.stringify(jsonData);
27
+ const head = { ...headers, 'Content-Type': 'application/json' };
28
+ const res = await this.client.post(proxy, path, data, {}, head);
29
+ if (!res.ok) {
30
+ throw new Error(await (0, utils_1.responseStringify)(res));
31
+ }
32
+ return res;
33
+ }
34
+ async getCameraImage(params, proxy = null) {
35
+ return await this.client.get(proxy, '/axis-cgi/jpg/image.cgi', params);
36
+ }
37
+ async getEventDeclarations(proxy = null) {
38
+ const data = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">' +
39
+ '<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
40
+ 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
41
+ '<GetEventInstances xmlns="http://www.axis.com/vapix/ws/event1"/>' +
42
+ '</s:Body>' +
43
+ '</s:Envelope>';
44
+ const res = await this.client.post(proxy, '/vapix/services', data, { 'Content-Type': 'application/soap+xml' });
45
+ if (!res.ok) {
46
+ throw new Error(await (0, utils_1.responseStringify)(res));
47
+ }
48
+ const declarations = await res.text();
49
+ return prettifyXml(declarations);
50
+ }
51
+ async getSupportedAudioSampleRate(proxy = null) {
52
+ const url = '/axis-cgi/audio/streamingcapabilities.cgi';
53
+ const jsonData = { apiVersion: '1.0', method: 'list' };
54
+ const res = await this.postJson(proxy, url, jsonData);
55
+ const encoders = VapixAPI_1.audioSampleRatesResponseSchema.parse(await res.json()).data.encoders;
56
+ const data = encoders.aac ?? encoders.AAC ?? [];
57
+ return data.map((item) => {
58
+ return {
59
+ sampleRate: item.sample_rate,
60
+ bitRates: item.bit_rates,
61
+ };
62
+ });
63
+ }
64
+ async performAutofocus(proxy = null) {
65
+ try {
66
+ const data = {
67
+ apiVersion: '1',
68
+ method: 'performAutofocus',
69
+ params: {
70
+ optics: [
71
+ {
72
+ opticsId: '0',
73
+ },
74
+ ],
75
+ },
76
+ };
77
+ await this.postJson(proxy, '/axis-cgi/opticscontrol.cgi', data);
78
+ }
79
+ catch (err) {
80
+ await this.getUrlEncoded(proxy, '/axis-cgi/opticssetup.cgi', {
81
+ autofocus: 'perform',
82
+ source: '1',
83
+ });
84
+ }
85
+ }
86
+ async checkSDCard(proxy = null) {
87
+ const res = await this.getUrlEncoded(proxy, '/axis-cgi/disks/list.cgi', {
88
+ diskid: 'SD_DISK',
89
+ });
90
+ const xmlText = await res.text();
91
+ const parser = new fast_xml_parser_1.XMLParser({
92
+ ignoreAttributes: false,
93
+ attributeNamePrefix: '',
94
+ allowBooleanAttributes: true,
95
+ });
96
+ const result = parser.parse(xmlText);
97
+ const data = result.root.disks.disk;
98
+ return {
99
+ totalSize: parseInt(data.totalsize),
100
+ freeSize: parseInt(data.freesize),
101
+ status: VapixAPI_1.sdCardWatchedStatuses.includes(data.status) ? data.status : 'disconnected',
102
+ };
103
+ }
104
+ mountSDCard(proxy = null) {
105
+ return this._doSDCardMountAction('MOUNT', proxy);
106
+ }
107
+ unmountSDCard(proxy = null) {
108
+ return this._doSDCardMountAction('UNMOUNT', proxy);
109
+ }
110
+ async _doSDCardMountAction(action, proxy = null) {
111
+ const res = await this.getUrlEncoded(proxy, '/axis-cgi/disks/mount.cgi', {
112
+ action: action,
113
+ diskid: 'SD_DISK',
114
+ });
115
+ const textXml = await res.text();
116
+ const parser = new fast_xml_parser_1.XMLParser({
117
+ ignoreAttributes: false,
118
+ attributeNamePrefix: '',
119
+ allowBooleanAttributes: true,
120
+ });
121
+ const result = parser.parse(textXml);
122
+ const job = result.root.job;
123
+ if (job.result !== 'OK') {
124
+ throw new errors_1.SDCardActionError(action, await (0, utils_1.responseStringify)(res));
125
+ }
126
+ return Number(job.jobid);
127
+ }
128
+ async fetchSDCardJobProgress(jobId, proxy = null) {
129
+ const res = await this.getUrlEncoded(proxy, '/disks/job.cgi', {
130
+ jobid: String(jobId),
131
+ diskid: 'SD_DISK',
132
+ });
133
+ const textXml = await res.text();
134
+ const parser = new fast_xml_parser_1.XMLParser({
135
+ ignoreAttributes: false,
136
+ attributeNamePrefix: '',
137
+ allowBooleanAttributes: true,
138
+ });
139
+ const job = parser.parse(textXml).root.job;
140
+ if (job.result !== 'OK') {
141
+ throw new errors_1.SDCardJobError();
142
+ }
143
+ return Number(job.progress);
144
+ }
145
+ downloadCameraReport(proxy = null) {
146
+ return this.getUrlEncoded(proxy, '/axis-cgi/serverreport.cgi', { mode: 'text' });
147
+ }
148
+ getSystemLog(proxy = null) {
149
+ return this.getUrlEncoded(proxy, '/axis-cgi/admin/systemlog.cgi');
150
+ }
151
+ async getMaxFps(channel, proxy = null) {
152
+ const data = { apiVersion: '1.0', method: 'getCaptureModes' };
153
+ const res = await this.postJson(proxy, '/axis-cgi/capturemode.cgi', data);
154
+ const response = VapixAPI_1.maxFpsResponseSchema.parse(await res.json());
155
+ const channels = response.data;
156
+ if (channels === undefined) {
157
+ throw new errors_1.MaxFPSError('MALFORMED_REPLY');
158
+ }
159
+ const channelData = channels.find((x) => x.channel === channel);
160
+ if (channelData === undefined) {
161
+ throw new errors_1.MaxFPSError('CHANNEL_NOT_FOUND');
162
+ }
163
+ const captureModes = channelData.captureMode;
164
+ const captureMode = captureModes.find((x) => x.enabled === true);
165
+ if (captureMode === undefined) {
166
+ throw new errors_1.MaxFPSError('CAPTURE_MODE_NOT_FOUND');
167
+ }
168
+ if ((0, utils_1.isNullish)(captureMode.maxFPS)) {
169
+ throw new errors_1.MaxFPSError('FPS_NOT_SPECIFIED');
170
+ }
171
+ return captureMode.maxFPS;
172
+ }
173
+ async getTimezone(proxy = null) {
174
+ try {
175
+ const resV2 = await this.client.get(proxy, '/config/rest/time/v2/timeZone');
176
+ if (!resV2.ok) {
177
+ throw new Error(await (0, utils_1.responseStringify)(resV2));
178
+ }
179
+ const json = await resV2.json();
180
+ const data = VapixAPI_1.timeZoneSchema.parse(json);
181
+ if (data.status === 'error') {
182
+ throw new Error(data.error.message);
183
+ }
184
+ return data.data.activeTimeZone;
185
+ }
186
+ catch (error) {
187
+ console.warn('Failed to fetch time zone data from time API v2:', error instanceof Error ? error.message : JSON.stringify(error));
188
+ console.warn('Falling back to deprecated time API v1');
189
+ }
190
+ const data = await this.getDateTimeInfo(proxy);
191
+ if (data.data.timeZone === undefined) {
192
+ throw new Error('Time zone not setup on the device');
193
+ }
194
+ return data.data.timeZone;
195
+ }
196
+ async getDateTimeInfo(proxy = null) {
197
+ const data = { apiVersion: '1.0', method: 'getDateTimeInfo' };
198
+ const res = await this.postJson(proxy, '/axis-cgi/time.cgi', data);
199
+ return VapixAPI_1.dateTimeinfoSchema.parse(await res.json());
200
+ }
201
+ async getDevicesSettings(proxy = null) {
202
+ const data = { apiVersion: '1.0', method: 'getDevicesSettings' };
203
+ const res = await this.postJson(proxy, '/axis-cgi/audiodevicecontrol.cgi', data);
204
+ const result = VapixAPI_1.audioDeviceRequestSchema.parse(await res.json());
205
+ return result.data.devices.map((device) => ({
206
+ ...device,
207
+ inputs: (device.inputs || []).sort((a, b) => a.id.localeCompare(b.id)),
208
+ outputs: (device.outputs || []).sort((a, b) => a.id.localeCompare(b.id)),
209
+ }));
210
+ }
211
+ async fetchRemoteDeviceInfo(payload, proxy = null) {
212
+ const res = await this.postJson(proxy, '/axis-cgi/basicdeviceinfo.cgi', payload);
213
+ const json = await res.json();
214
+ if ((0, utils_1.isNullish)(json.data)) {
215
+ throw new errors_1.NoDeviceInfoError();
216
+ }
217
+ return json.data;
218
+ }
219
+ async getHeaders(proxy = null) {
220
+ const data = { apiVersion: '1.0', method: 'list' };
221
+ const res = await this.postJson(proxy, '/axis-cgi/customhttpheader.cgi', data);
222
+ return zod_1.z.object({ data: zod_1.z.record(zod_1.z.string()) }).parse(await res.json()).data;
223
+ }
224
+ async setHeaders(headers, proxy = null) {
225
+ const data = { apiVersion: '1.0', method: 'set', params: headers };
226
+ return this.postJson(proxy, '/axis-cgi/customhttpheader.cgi', data);
227
+ }
228
+ async getParameter(paramNames, proxy = null) {
229
+ const response = await this.getUrlEncoded(proxy, '/axis-cgi/param.cgi', {
230
+ action: 'list',
231
+ group: (0, utils_1.arrayToUrl)(paramNames),
232
+ });
233
+ return parseParameters(await response.text());
234
+ }
235
+ async setParameter(params, proxy = null) {
236
+ const res = await this.getUrlEncoded(proxy, '/axis-cgi/param.cgi', {
237
+ ...params,
238
+ action: 'update',
239
+ });
240
+ const responseText = await res.text();
241
+ if (responseText.startsWith('# Error')) {
242
+ throw new Error(responseText);
243
+ }
244
+ return true;
245
+ }
246
+ async getGuardTourList(proxy = null) {
247
+ const gTourList = new Array();
248
+ const response = await this.getParameter('GuardTour', proxy);
249
+ for (let i = 0; i < 20; i++) {
250
+ const gTourBaseName = 'root.GuardTour.G' + i;
251
+ if (gTourBaseName + '.CamNbr' in response) {
252
+ const gTour = {
253
+ id: gTourBaseName,
254
+ camNbr: response[gTourBaseName + '.CamNbr'],
255
+ name: response[gTourBaseName + '.Name'] ?? 'Guard Tour ' + (i + 1),
256
+ randomEnabled: response[gTourBaseName + '.RandomEnabled'],
257
+ running: response[gTourBaseName + '.Running'] ?? 'no',
258
+ timeBetweenSequences: response[gTourBaseName + '.TimeBetweenSequences'],
259
+ tour: [],
260
+ };
261
+ for (let j = 0; j < 100; j++) {
262
+ const tourBaseName = 'root.GuardTour.G' + i + '.Tour.T' + j;
263
+ if (tourBaseName + '.MoveSpeed' in response) {
264
+ const tour = {
265
+ moveSpeed: response[tourBaseName + '.MoveSpeed'],
266
+ position: response[tourBaseName + '.Position'],
267
+ presetNbr: response[tourBaseName + '.PresetNbr'],
268
+ waitTime: response[tourBaseName + '.WaitTime'],
269
+ waitTimeViewType: response[tourBaseName + '.WaitTimeViewType'],
270
+ };
271
+ gTour.tour.push(tour);
272
+ }
273
+ }
274
+ gTourList.push(gTour);
275
+ }
276
+ else {
277
+ break;
278
+ }
279
+ }
280
+ return gTourList;
281
+ }
282
+ setGuardTourEnabled(guardTourID, enable, proxy = null) {
283
+ const options = {};
284
+ options[guardTourID + '.Running'] = enable ? 'yes' : 'no';
285
+ return this.setParameter(options, proxy);
286
+ }
287
+ async getPTZPresetList(channel, proxy = null) {
288
+ const res = await this.getUrlEncoded(proxy, '/axis-cgi/com/ptz.cgi', {
289
+ query: 'presetposcam',
290
+ camera: channel.toString(),
291
+ });
292
+ const text = await res.text();
293
+ const lines = text.split(/[\r\n]/);
294
+ const positions = [];
295
+ for (const line of lines) {
296
+ if (line.indexOf('presetposno') !== -1) {
297
+ const delimiterPos = line.indexOf('=');
298
+ if (delimiterPos !== -1) {
299
+ const value = line.substring(delimiterPos + 1);
300
+ positions.push(value);
301
+ }
302
+ }
303
+ }
304
+ return positions;
305
+ }
306
+ async listPTZ(camera, proxy = null) {
307
+ const url = `/axis-cgi/com/ptz.cgi`;
308
+ const response = await this.getUrlEncoded(proxy, url, {
309
+ camera,
310
+ query: 'presetposcamdata',
311
+ format: 'json',
312
+ });
313
+ const text = await response.text();
314
+ if (text === '') {
315
+ throw new errors_1.PtzNotSupportedError();
316
+ }
317
+ return parseCameraPtzResponse(text)[camera] ?? [];
318
+ }
319
+ async listPtzVideoSourceOverview(proxy = null) {
320
+ const response = await this.getUrlEncoded(proxy, '/axis-cgi/com/ptz.cgi', {
321
+ query: 'presetposall',
322
+ format: 'json',
323
+ });
324
+ const text = await response.text();
325
+ if (text === '') {
326
+ throw new errors_1.PtzNotSupportedError();
327
+ }
328
+ const data = parseCameraPtzResponse(text);
329
+ const res = {};
330
+ Object.keys(data)
331
+ .map(Number)
332
+ .forEach((camera) => {
333
+ if (data[camera] !== undefined) {
334
+ res[camera - 1] = data[camera]?.map(({ data: itemData, ...d }) => d);
335
+ }
336
+ });
337
+ return res;
338
+ }
339
+ goToPreset(channel, presetName, proxy = null) {
340
+ return this.getUrlEncoded(proxy, '/axis-cgi/com/ptz.cgi', {
341
+ camera: channel.toString(),
342
+ gotoserverpresetname: presetName,
343
+ });
344
+ }
345
+ async getPtzPosition(camera, proxy = null) {
346
+ const res = await this.getUrlEncoded(proxy, '/axis-cgi/com/ptz.cgi', {
347
+ query: 'position',
348
+ camera: camera.toString(),
349
+ });
350
+ const params = parseParameters(await res.text());
351
+ return {
352
+ pan: Number(params.pan),
353
+ tilt: Number(params.tilt),
354
+ zoom: Number(params.zoom),
355
+ };
356
+ }
357
+ async getInputState(port, proxy = null) {
358
+ const response = await (await this.getUrlEncoded(proxy, '/axis-cgi/io/port.cgi', { checkactive: port.toString() })).text();
359
+ return response.split('=')[1]?.indexOf('active') === 0;
360
+ }
361
+ async setOutputState(port, active, proxy = null) {
362
+ return this.getUrlEncoded(proxy, '/axis-cgi/io/port.cgi', { action: active ? `${port}:/` : `${port}:\\` });
363
+ }
364
+ async getApplicationList(proxy = null) {
365
+ const res = await this.client.get(proxy, '/axis-cgi/applications/list.cgi');
366
+ const xml = await res.text();
367
+ const parser = new fast_xml_parser_1.XMLParser({
368
+ ignoreAttributes: false,
369
+ attributeNamePrefix: '',
370
+ allowBooleanAttributes: true,
371
+ });
372
+ const result = parser.parse(xml);
373
+ return result.reply.application.map((app) => {
374
+ return {
375
+ ...app,
376
+ appId: VapixAPI_1.APP_IDS.find((id) => id.toLowerCase() === app.Name.toLowerCase()) ?? null,
377
+ };
378
+ });
379
+ }
380
+ async startApplication(applicationID, proxy = null) {
381
+ const res = await this.client.get(proxy, '/axis-cgi/applications/control.cgi', {
382
+ package: applicationID.toLowerCase(),
383
+ action: 'start',
384
+ });
385
+ const text = (await res.text()).trim().toLowerCase();
386
+ if (text !== 'ok' && !(text.startsWith('error:') && text.substring(7) === '6')) {
387
+ throw new errors_1.ApplicationAPIError('START', await (0, utils_1.responseStringify)(res));
388
+ }
389
+ }
390
+ async restartApplication(applicationID, proxy = null) {
391
+ const res = await this.client.get(proxy, '/axis-cgi/applications/control.cgi', {
392
+ package: applicationID.toLowerCase(),
393
+ action: 'restart',
394
+ });
395
+ const text = (await res.text()).trim().toLowerCase();
396
+ if (text !== 'ok') {
397
+ throw new errors_1.ApplicationAPIError('RESTART', await (0, utils_1.responseStringify)(res));
398
+ }
399
+ }
400
+ async stopApplication(applicationID, proxy = null) {
401
+ const res = await this.client.get(proxy, '/axis-cgi/applications/control.cgi', {
402
+ package: applicationID.toLowerCase(),
403
+ action: 'stop',
404
+ });
405
+ const text = (await res.text()).trim().toLowerCase();
406
+ if (text !== 'ok' && !(text.startsWith('error:') && text.substring(7) === '6')) {
407
+ throw new errors_1.ApplicationAPIError('STOP', await (0, utils_1.responseStringify)(res));
408
+ }
409
+ }
410
+ async installApplication(data, fileName) {
411
+ const formData = new FormData();
412
+ formData.append('packfil', data, fileName);
413
+ const res = await this.client.post(null, '/axis-cgi/applications/upload.cgi', formData, {}, {
414
+ contentType: 'application/octet-stream',
415
+ });
416
+ if (!res.ok) {
417
+ throw new Error(await (0, utils_1.responseStringify)(res));
418
+ }
419
+ const text = await res.text();
420
+ if (text.length > 5) {
421
+ throw new Error('installing error: ' + text);
422
+ }
423
+ }
424
+ }
425
+ exports.VapixAPI = VapixAPI;
426
+ const parseParameters = (response) => {
427
+ const params = {};
428
+ const lines = response.split(/[\r\n]/);
429
+ for (const line of lines) {
430
+ if (line.length === 0 || line.substring(0, 7) === '# Error') {
431
+ continue;
432
+ }
433
+ const delimiterPos = line.indexOf('=');
434
+ if (delimiterPos !== -1) {
435
+ const paramName = line.substring(0, delimiterPos).replace('root.', '');
436
+ const paramValue = line.substring(delimiterPos + 1);
437
+ params[paramName] = paramValue;
438
+ }
439
+ }
440
+ return params;
441
+ };
442
+ const parseCameraPtzResponse = (response) => {
443
+ const json = JSON.parse(response);
444
+ const parsed = {};
445
+ Object.keys(json).forEach((key) => {
446
+ if (!key.startsWith('Camera ')) {
447
+ return;
448
+ }
449
+ const camera = Number(key.replace('Camera ', ''));
450
+ if (json[key].presets !== undefined) {
451
+ parsed[camera] = parsePtz(json[key].presets);
452
+ }
453
+ });
454
+ return parsed;
455
+ };
456
+ const parsePtz = (parsed) => {
457
+ const res = [];
458
+ parsed.forEach((value) => {
459
+ const delimiterPos = value.indexOf('=');
460
+ if (delimiterPos === -1) {
461
+ return;
462
+ }
463
+ if (!value.startsWith('presetposno')) {
464
+ return;
465
+ }
466
+ const id = Number(value.substring(11, delimiterPos));
467
+ if (Number.isNaN(id)) {
468
+ return;
469
+ }
470
+ const data = value.substring(delimiterPos + 1).split(':');
471
+ const getValue = (valueName) => {
472
+ for (const d of data) {
473
+ const p = d.split('=');
474
+ if (p[0] === valueName) {
475
+ return Number(p[1]);
476
+ }
477
+ }
478
+ return 0;
479
+ };
480
+ res.push({
481
+ id,
482
+ name: data[0] ?? 'Preset ' + id,
483
+ data: {
484
+ pan: getValue('pan'),
485
+ tilt: getValue('tilt'),
486
+ zoom: getValue('zoom'),
487
+ },
488
+ });
489
+ });
490
+ return res;
491
+ };
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter2 as EventEmitter } from 'eventemitter2';
2
- import { WsOptions } from './internal/common';
2
+ import { WsOptions } from './internal/types';
3
3
  export type VapixEventsOptions = WsOptions;
4
4
  type TEventMessage = {
5
5
  apiVersion: string;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VapixEvents = void 0;
4
+ const eventemitter2_1 = require("eventemitter2");
5
+ const WsClient_1 = require("./node/WsClient");
6
+ class VapixEvents extends eventemitter2_1.EventEmitter2 {
7
+ tls;
8
+ tlsInsecure;
9
+ ip;
10
+ port;
11
+ user;
12
+ pass;
13
+ ws;
14
+ constructor(options = {}) {
15
+ super();
16
+ this.tls = options.tls ?? false;
17
+ this.tlsInsecure = options.tlsInsecure ?? false;
18
+ this.ip = options.ip ?? '127.0.0.1';
19
+ this.port = options.port ?? (this.tls ? 443 : 80);
20
+ this.user = options.user ?? 'root';
21
+ this.pass = options.pass ?? '';
22
+ this.createWsClient();
23
+ eventemitter2_1.EventEmitter2.call(this);
24
+ }
25
+ connect() {
26
+ this.ws.open();
27
+ }
28
+ disconnect() {
29
+ this.ws.close();
30
+ }
31
+ createWsClient() {
32
+ const options = {
33
+ tls: this.tls,
34
+ tlsInsecure: this.tlsInsecure,
35
+ user: this.user,
36
+ pass: this.pass,
37
+ ip: this.ip,
38
+ port: this.port,
39
+ address: '/vapix/ws-data-stream?sources=events',
40
+ };
41
+ this.ws = new WsClient_1.WsClient(options);
42
+ this.ws.on('open', () => {
43
+ const topics = [];
44
+ const eventNames = this.eventNames();
45
+ for (const eventName of eventNames) {
46
+ if (!this.isReservedEventName(eventName)) {
47
+ const topic = {
48
+ topicFilter: eventName,
49
+ };
50
+ topics.push(topic);
51
+ }
52
+ }
53
+ const topicFilter = {
54
+ apiVersion: '1.0',
55
+ method: 'events:configure',
56
+ params: {
57
+ eventFilterList: topics,
58
+ },
59
+ };
60
+ this.ws.send(JSON.stringify(topicFilter));
61
+ });
62
+ this.ws.on('message', (data) => {
63
+ const dataJSON = JSON.parse(data.toString());
64
+ if (dataJSON.method === 'events:configure') {
65
+ if (dataJSON.error === undefined) {
66
+ this.emit('open');
67
+ }
68
+ else {
69
+ this.emit('error', dataJSON.error);
70
+ this.disconnect();
71
+ }
72
+ return;
73
+ }
74
+ const eventName = dataJSON.params.notification.topic;
75
+ this.emit(eventName, dataJSON);
76
+ });
77
+ this.ws.on('error', (error) => {
78
+ this.emit('error', error);
79
+ });
80
+ this.ws.on('close', () => {
81
+ this.emit('close');
82
+ });
83
+ }
84
+ isReservedEventName(eventName) {
85
+ return eventName === 'open' || eventName === 'close' || eventName === 'error';
86
+ }
87
+ }
88
+ exports.VapixEvents = VapixEvents;
@@ -31,4 +31,7 @@ export declare class FetchDeviceInfoError extends Error {
31
31
  export declare class AddNewClipError extends Error {
32
32
  constructor(message: string);
33
33
  }
34
+ export declare class PtzNotSupportedError extends Error {
35
+ constructor();
36
+ }
34
37
  export {};
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PtzNotSupportedError = exports.AddNewClipError = exports.FetchDeviceInfoError = exports.NoDeviceInfoError = exports.MaxFPSError = exports.SDCardJobError = exports.SDCardActionError = exports.ApplicationAPIError = exports.ParsingBlobError = exports.ServiceNotFoundError = exports.ServiceUnavailableError = void 0;
4
+ class ServiceUnavailableError extends Error {
5
+ constructor() {
6
+ super('Service is unavailable.');
7
+ this.name = 'ServiceUnavailableError';
8
+ }
9
+ }
10
+ exports.ServiceUnavailableError = ServiceUnavailableError;
11
+ class ServiceNotFoundError extends Error {
12
+ constructor() {
13
+ super('Service not found.');
14
+ this.name = 'ServiceNotFoundError';
15
+ }
16
+ }
17
+ exports.ServiceNotFoundError = ServiceNotFoundError;
18
+ class ParsingBlobError extends Error {
19
+ constructor(err) {
20
+ super('Error parsing response as Blob: ' + err);
21
+ this.name = 'ParsingBlobError';
22
+ }
23
+ }
24
+ exports.ParsingBlobError = ParsingBlobError;
25
+ class ApplicationAPIError extends Error {
26
+ constructor(action, res) {
27
+ super(`[APP ${action}] Error: ` + res);
28
+ this.name = 'ApplicationAPIError';
29
+ }
30
+ }
31
+ exports.ApplicationAPIError = ApplicationAPIError;
32
+ class SDCardActionError extends Error {
33
+ constructor(action, res) {
34
+ super(`[SD_CARD ${action}] Error: ` + res);
35
+ this.name = 'SDCardActionError';
36
+ }
37
+ }
38
+ exports.SDCardActionError = SDCardActionError;
39
+ class SDCardJobError extends Error {
40
+ constructor() {
41
+ super('Error while fetching SD card job progress');
42
+ this.name = 'SDCardJobError';
43
+ }
44
+ }
45
+ exports.SDCardJobError = SDCardJobError;
46
+ const MAX_FPS_ERROR_MESSAGES = {
47
+ MALFORMED_REPLY: 'Malformed reply from camera',
48
+ CHANNEL_NOT_FOUND: 'Video channel not found.',
49
+ CAPTURE_MODE_NOT_FOUND: 'No enabled capture mode found.',
50
+ FPS_NOT_SPECIFIED: 'Max fps not specified for given capture mode.',
51
+ };
52
+ class MaxFPSError extends Error {
53
+ constructor(state) {
54
+ super(`[MAX_FPS ${state}] Error: ` + MAX_FPS_ERROR_MESSAGES[state]);
55
+ this.name = 'MaxFPSError';
56
+ }
57
+ }
58
+ exports.MaxFPSError = MaxFPSError;
59
+ class NoDeviceInfoError extends Error {
60
+ constructor() {
61
+ super('Did not get any data from remote camera');
62
+ this.name = 'NoDeviceInfoError';
63
+ }
64
+ }
65
+ exports.NoDeviceInfoError = NoDeviceInfoError;
66
+ class FetchDeviceInfoError extends Error {
67
+ constructor(err) {
68
+ super('Error fetching remote camera data: ' + err);
69
+ this.name = 'NoDeviceInfoFromCameraError';
70
+ }
71
+ }
72
+ exports.FetchDeviceInfoError = FetchDeviceInfoError;
73
+ class AddNewClipError extends Error {
74
+ constructor(message) {
75
+ super('Error adding new clip: ' + message);
76
+ this.name = 'AddNewClipError';
77
+ }
78
+ }
79
+ exports.AddNewClipError = AddNewClipError;
80
+ class PtzNotSupportedError extends Error {
81
+ constructor() {
82
+ super('Ptz not supported.');
83
+ this.name = 'PtzNotSupportedError';
84
+ }
85
+ }
86
+ exports.PtzNotSupportedError = PtzNotSupportedError;