camstreamerlib 4.0.0-beta.99 → 4.0.1

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 (218) hide show
  1. package/README.md +44 -15
  2. package/cjs/CamOverlayAPI.d.ts +145 -107
  3. package/cjs/CamOverlayAPI.js +14 -63
  4. package/cjs/CamScripterAPI.d.ts +5 -8
  5. package/cjs/CamScripterAPI.js +11 -29
  6. package/cjs/CamStreamerAPI.d.ts +2362 -806
  7. package/cjs/CamStreamerAPI.js +68 -76
  8. package/cjs/CamSwitcherAPI.d.ts +23 -22
  9. package/cjs/CamSwitcherAPI.js +30 -88
  10. package/cjs/PlaneTrackerAPI.d.ts +28 -30
  11. package/cjs/PlaneTrackerAPI.js +20 -75
  12. package/cjs/VapixAPI.d.ts +36 -23
  13. package/cjs/VapixAPI.js +227 -106
  14. package/cjs/errors/errors.d.ts +11 -5
  15. package/cjs/errors/errors.js +5 -1
  16. package/cjs/index.d.ts +1 -0
  17. package/cjs/index.js +1 -0
  18. package/cjs/internal/BasicAPI.d.ts +15 -0
  19. package/cjs/internal/BasicAPI.js +93 -0
  20. package/cjs/internal/WsEvents.d.ts +1 -0
  21. package/cjs/internal/WsEvents.js +5 -0
  22. package/cjs/internal/constants.d.ts +1 -0
  23. package/cjs/internal/constants.js +2 -1
  24. package/cjs/internal/convertors.d.ts +6 -0
  25. package/cjs/internal/convertors.js +115 -0
  26. package/cjs/internal/transformers.js +8 -8
  27. package/cjs/internal/types.d.ts +3 -0
  28. package/cjs/internal/versionCompare.d.ts +2 -2
  29. package/cjs/types/CamOverlayAPI/CamOverlayAPI.d.ts +878 -358
  30. package/cjs/types/CamOverlayAPI/CamOverlayAPI.js +54 -11
  31. package/cjs/types/CamOverlayAPI/accuweatherSchema.d.ts +10 -10
  32. package/cjs/types/CamOverlayAPI/customGraphicsSchema.d.ts +28 -28
  33. package/cjs/types/CamOverlayAPI/htmlOverlaySchema.d.ts +81 -0
  34. package/cjs/types/CamOverlayAPI/htmlOverlaySchema.js +21 -0
  35. package/cjs/types/CamOverlayAPI/imagesSchema.d.ts +10 -10
  36. package/cjs/types/CamOverlayAPI/index.d.ts +1 -0
  37. package/cjs/types/CamOverlayAPI/index.js +1 -0
  38. package/cjs/types/CamOverlayAPI/infotickerSchema.d.ts +8 -8
  39. package/cjs/types/CamOverlayAPI/pipSchema.d.ts +8 -8
  40. package/cjs/types/CamOverlayAPI/ptzCompassSchema.d.ts +10 -10
  41. package/cjs/types/CamOverlayAPI/ptzSchema.d.ts +13 -13
  42. package/cjs/types/CamOverlayAPI/scoreBoardSchema.d.ts +18 -18
  43. package/cjs/types/CamOverlayAPI/screenSharingSchema.d.ts +8 -8
  44. package/cjs/types/CamOverlayAPI/serviceCommonTypes.d.ts +17 -16
  45. package/cjs/types/CamOverlayAPI/serviceCommonTypes.js +6 -3
  46. package/cjs/types/CamOverlayAPI/webCameraSharingSchema.d.ts +8 -8
  47. package/cjs/types/CamScripterAPI.d.ts +0 -11
  48. package/cjs/types/CamScripterAPI.js +1 -5
  49. package/cjs/types/CamStreamerAPI/CamStreamerAPI.d.ts +17745 -4940
  50. package/cjs/types/CamStreamerAPI/CamStreamerAPI.js +126 -57
  51. package/cjs/types/CamStreamerAPI/facebookSchema.d.ts +395 -86
  52. package/cjs/types/CamStreamerAPI/facebookSchema.js +13 -1
  53. package/cjs/types/CamStreamerAPI/index.d.ts +1 -3
  54. package/cjs/types/CamStreamerAPI/index.js +1 -3
  55. package/cjs/types/CamStreamerAPI/oldStreamSchema.d.ts +47 -47
  56. package/cjs/types/CamStreamerAPI/oldStreamSchema.js +1 -1
  57. package/cjs/types/CamStreamerAPI/streamCommonTypes.d.ts +392 -304
  58. package/cjs/types/CamStreamerAPI/streamCommonTypes.js +116 -76
  59. package/cjs/types/CamStreamerAPI/streamsSchema.d.ts +8812 -0
  60. package/cjs/types/CamStreamerAPI/streamsSchema.js +81 -0
  61. package/cjs/types/CamStreamerAPI/windySchema.d.ts +356 -87
  62. package/cjs/types/CamStreamerAPI/windySchema.js +9 -1
  63. package/cjs/types/CamStreamerAPI/youtubeSchema.d.ts +351 -119
  64. package/cjs/types/CamStreamerAPI/youtubeSchema.js +5 -9
  65. package/cjs/types/CamSwitcherAPI.d.ts +96 -91
  66. package/cjs/types/CamSwitcherAPI.js +9 -9
  67. package/cjs/types/GenetecAgent.d.ts +2 -2
  68. package/cjs/types/PlaneTrackerAPI.d.ts +60 -47
  69. package/cjs/types/PlaneTrackerAPI.js +5 -2
  70. package/cjs/types/VapixAPI.d.ts +51 -32
  71. package/cjs/types/VapixAPI.js +10 -3
  72. package/cjs/types/common.d.ts +27 -0
  73. package/cjs/types/common.js +13 -1
  74. package/cjs/types/ws/CamStreamerEvents.d.ts +110 -77
  75. package/cjs/types/ws/CamStreamerEvents.js +11 -7
  76. package/cjs/types/ws/CamSwitcherEvents.d.ts +8 -8
  77. package/cjs/types/ws/PlaneTrackerEvents.d.ts +3 -3
  78. package/esm/CamOverlayAPI.js +16 -65
  79. package/esm/CamScripterAPI.js +9 -30
  80. package/esm/CamStreamerAPI.js +70 -78
  81. package/esm/CamSwitcherAPI.js +31 -89
  82. package/esm/PlaneTrackerAPI.js +21 -76
  83. package/esm/VapixAPI.js +228 -107
  84. package/esm/errors/errors.js +5 -1
  85. package/esm/index.js +1 -0
  86. package/esm/internal/BasicAPI.js +89 -0
  87. package/esm/internal/WsEvents.js +5 -0
  88. package/esm/internal/constants.js +1 -0
  89. package/esm/internal/convertors.js +108 -0
  90. package/esm/internal/transformers.js +1 -1
  91. package/esm/types/CamOverlayAPI/CamOverlayAPI.js +47 -10
  92. package/esm/types/CamOverlayAPI/htmlOverlaySchema.js +18 -0
  93. package/esm/types/CamOverlayAPI/index.js +1 -0
  94. package/esm/types/CamOverlayAPI/serviceCommonTypes.js +6 -3
  95. package/esm/types/CamScripterAPI.js +0 -4
  96. package/esm/types/CamStreamerAPI/CamStreamerAPI.js +109 -41
  97. package/esm/types/CamStreamerAPI/facebookSchema.js +13 -1
  98. package/esm/types/CamStreamerAPI/index.js +1 -3
  99. package/esm/types/CamStreamerAPI/oldStreamSchema.js +1 -1
  100. package/esm/types/CamStreamerAPI/streamCommonTypes.js +116 -76
  101. package/esm/types/CamStreamerAPI/streamsSchema.js +75 -0
  102. package/esm/types/CamStreamerAPI/windySchema.js +9 -1
  103. package/esm/types/CamStreamerAPI/youtubeSchema.js +5 -9
  104. package/esm/types/CamSwitcherAPI.js +8 -8
  105. package/esm/types/PlaneTrackerAPI.js +5 -2
  106. package/esm/types/VapixAPI.js +9 -2
  107. package/esm/types/common.js +12 -0
  108. package/esm/types/ws/CamStreamerEvents.js +11 -7
  109. package/package.json +4 -4
  110. package/types/CamOverlayAPI.d.ts +145 -107
  111. package/types/CamScripterAPI.d.ts +5 -8
  112. package/types/CamStreamerAPI.d.ts +2362 -806
  113. package/types/CamSwitcherAPI.d.ts +23 -22
  114. package/types/PlaneTrackerAPI.d.ts +28 -30
  115. package/types/VapixAPI.d.ts +36 -23
  116. package/types/errors/errors.d.ts +11 -5
  117. package/types/index.d.ts +1 -0
  118. package/types/internal/BasicAPI.d.ts +15 -0
  119. package/types/internal/WsEvents.d.ts +1 -0
  120. package/types/internal/constants.d.ts +1 -0
  121. package/types/internal/convertors.d.ts +6 -0
  122. package/types/internal/types.d.ts +3 -0
  123. package/types/internal/versionCompare.d.ts +2 -2
  124. package/types/types/CamOverlayAPI/CamOverlayAPI.d.ts +878 -358
  125. package/types/types/CamOverlayAPI/accuweatherSchema.d.ts +10 -10
  126. package/types/types/CamOverlayAPI/customGraphicsSchema.d.ts +28 -28
  127. package/types/types/CamOverlayAPI/htmlOverlaySchema.d.ts +81 -0
  128. package/types/types/CamOverlayAPI/imagesSchema.d.ts +10 -10
  129. package/types/types/CamOverlayAPI/index.d.ts +1 -0
  130. package/types/types/CamOverlayAPI/infotickerSchema.d.ts +8 -8
  131. package/types/types/CamOverlayAPI/pipSchema.d.ts +8 -8
  132. package/types/types/CamOverlayAPI/ptzCompassSchema.d.ts +10 -10
  133. package/types/types/CamOverlayAPI/ptzSchema.d.ts +13 -13
  134. package/types/types/CamOverlayAPI/scoreBoardSchema.d.ts +18 -18
  135. package/types/types/CamOverlayAPI/screenSharingSchema.d.ts +8 -8
  136. package/types/types/CamOverlayAPI/serviceCommonTypes.d.ts +17 -16
  137. package/types/types/CamOverlayAPI/webCameraSharingSchema.d.ts +8 -8
  138. package/types/types/CamScripterAPI.d.ts +0 -11
  139. package/types/types/CamStreamerAPI/CamStreamerAPI.d.ts +17745 -4940
  140. package/types/types/CamStreamerAPI/facebookSchema.d.ts +395 -86
  141. package/types/types/CamStreamerAPI/index.d.ts +1 -3
  142. package/types/types/CamStreamerAPI/oldStreamSchema.d.ts +47 -47
  143. package/types/types/CamStreamerAPI/streamCommonTypes.d.ts +392 -304
  144. package/types/types/CamStreamerAPI/streamsSchema.d.ts +8812 -0
  145. package/types/types/CamStreamerAPI/windySchema.d.ts +356 -87
  146. package/types/types/CamStreamerAPI/youtubeSchema.d.ts +351 -119
  147. package/types/types/CamSwitcherAPI.d.ts +96 -91
  148. package/types/types/GenetecAgent.d.ts +2 -2
  149. package/types/types/PlaneTrackerAPI.d.ts +60 -47
  150. package/types/types/VapixAPI.d.ts +51 -32
  151. package/types/types/common.d.ts +27 -0
  152. package/types/types/ws/CamStreamerEvents.d.ts +110 -77
  153. package/types/types/ws/CamSwitcherEvents.d.ts +8 -8
  154. package/types/types/ws/PlaneTrackerEvents.d.ts +3 -3
  155. package/cjs/types/CamStreamerAPI/churchSchema.d.ts +0 -275
  156. package/cjs/types/CamStreamerAPI/churchSchema.js +0 -11
  157. package/cjs/types/CamStreamerAPI/daCastSchema.d.ts +0 -275
  158. package/cjs/types/CamStreamerAPI/daCastSchema.js +0 -11
  159. package/cjs/types/CamStreamerAPI/dailymotionSchema.d.ts +0 -275
  160. package/cjs/types/CamStreamerAPI/dailymotionSchema.js +0 -11
  161. package/cjs/types/CamStreamerAPI/gameChangerSchema.d.ts +0 -275
  162. package/cjs/types/CamStreamerAPI/gameChangerSchema.js +0 -11
  163. package/cjs/types/CamStreamerAPI/hlsPullSchema.d.ts +0 -275
  164. package/cjs/types/CamStreamerAPI/hlsPullSchema.js +0 -11
  165. package/cjs/types/CamStreamerAPI/hlsPushSchema.d.ts +0 -275
  166. package/cjs/types/CamStreamerAPI/hlsPushSchema.js +0 -11
  167. package/cjs/types/CamStreamerAPI/ibmSchema.d.ts +0 -275
  168. package/cjs/types/CamStreamerAPI/ibmSchema.js +0 -11
  169. package/cjs/types/CamStreamerAPI/microsoftAzureSchema.d.ts +0 -275
  170. package/cjs/types/CamStreamerAPI/microsoftAzureSchema.js +0 -11
  171. package/cjs/types/CamStreamerAPI/microsoftStreamSchema.d.ts +0 -275
  172. package/cjs/types/CamStreamerAPI/microsoftStreamSchema.js +0 -11
  173. package/cjs/types/CamStreamerAPI/mpegDvbSchema.d.ts +0 -323
  174. package/cjs/types/CamStreamerAPI/mpegDvbSchema.js +0 -27
  175. package/cjs/types/CamStreamerAPI/rtmpSchema.d.ts +0 -284
  176. package/cjs/types/CamStreamerAPI/rtmpSchema.js +0 -14
  177. package/cjs/types/CamStreamerAPI/sdCardSchema.d.ts +0 -275
  178. package/cjs/types/CamStreamerAPI/sdCardSchema.js +0 -11
  179. package/cjs/types/CamStreamerAPI/srtSchema.d.ts +0 -275
  180. package/cjs/types/CamStreamerAPI/srtSchema.js +0 -11
  181. package/cjs/types/CamStreamerAPI/twitchSchema.d.ts +0 -275
  182. package/cjs/types/CamStreamerAPI/twitchSchema.js +0 -11
  183. package/cjs/types/CamStreamerAPI/vimeoSchema.d.ts +0 -275
  184. package/cjs/types/CamStreamerAPI/vimeoSchema.js +0 -11
  185. package/cjs/types/CamStreamerAPI/wowzaSchema.d.ts +0 -275
  186. package/cjs/types/CamStreamerAPI/wowzaSchema.js +0 -11
  187. package/esm/types/CamStreamerAPI/churchSchema.js +0 -5
  188. package/esm/types/CamStreamerAPI/daCastSchema.js +0 -5
  189. package/esm/types/CamStreamerAPI/dailymotionSchema.js +0 -5
  190. package/esm/types/CamStreamerAPI/gameChangerSchema.js +0 -5
  191. package/esm/types/CamStreamerAPI/hlsPullSchema.js +0 -5
  192. package/esm/types/CamStreamerAPI/hlsPushSchema.js +0 -5
  193. package/esm/types/CamStreamerAPI/ibmSchema.js +0 -5
  194. package/esm/types/CamStreamerAPI/microsoftAzureSchema.js +0 -5
  195. package/esm/types/CamStreamerAPI/microsoftStreamSchema.js +0 -5
  196. package/esm/types/CamStreamerAPI/mpegDvbSchema.js +0 -21
  197. package/esm/types/CamStreamerAPI/rtmpSchema.js +0 -8
  198. package/esm/types/CamStreamerAPI/sdCardSchema.js +0 -5
  199. package/esm/types/CamStreamerAPI/srtSchema.js +0 -5
  200. package/esm/types/CamStreamerAPI/twitchSchema.js +0 -5
  201. package/esm/types/CamStreamerAPI/vimeoSchema.js +0 -5
  202. package/esm/types/CamStreamerAPI/wowzaSchema.js +0 -5
  203. package/types/types/CamStreamerAPI/churchSchema.d.ts +0 -275
  204. package/types/types/CamStreamerAPI/daCastSchema.d.ts +0 -275
  205. package/types/types/CamStreamerAPI/dailymotionSchema.d.ts +0 -275
  206. package/types/types/CamStreamerAPI/gameChangerSchema.d.ts +0 -275
  207. package/types/types/CamStreamerAPI/hlsPullSchema.d.ts +0 -275
  208. package/types/types/CamStreamerAPI/hlsPushSchema.d.ts +0 -275
  209. package/types/types/CamStreamerAPI/ibmSchema.d.ts +0 -275
  210. package/types/types/CamStreamerAPI/microsoftAzureSchema.d.ts +0 -275
  211. package/types/types/CamStreamerAPI/microsoftStreamSchema.d.ts +0 -275
  212. package/types/types/CamStreamerAPI/mpegDvbSchema.d.ts +0 -323
  213. package/types/types/CamStreamerAPI/rtmpSchema.d.ts +0 -284
  214. package/types/types/CamStreamerAPI/sdCardSchema.d.ts +0 -275
  215. package/types/types/CamStreamerAPI/srtSchema.d.ts +0 -275
  216. package/types/types/CamStreamerAPI/twitchSchema.d.ts +0 -275
  217. package/types/types/CamStreamerAPI/vimeoSchema.d.ts +0 -275
  218. package/types/types/CamStreamerAPI/wowzaSchema.d.ts +0 -275
package/cjs/VapixAPI.js CHANGED
@@ -4,19 +4,15 @@ exports.VapixAPI = void 0;
4
4
  const utils_1 = require("./internal/utils");
5
5
  const VapixAPI_1 = require("./types/VapixAPI");
6
6
  const errors_1 = require("./errors/errors");
7
- const ProxyClient_1 = require("./internal/ProxyClient");
8
7
  const zod_1 = require("zod");
9
8
  const fast_xml_parser_1 = require("fast-xml-parser");
10
- class VapixAPI {
11
- client;
9
+ const BasicAPI_1 = require("./internal/BasicAPI");
10
+ class VapixAPI extends BasicAPI_1.BasicAPI {
12
11
  CustomFormData;
13
12
  constructor(client, CustomFormData = FormData) {
14
- this.client = client;
13
+ super(client);
15
14
  this.CustomFormData = CustomFormData;
16
15
  }
17
- getClient(proxyParams) {
18
- return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
19
- }
20
16
  async postUrlEncoded(path, parameters, headers, options) {
21
17
  const data = (0, utils_1.paramToUrl)(parameters);
22
18
  const head = { ...headers, 'Content-Type': 'application/x-www-form-urlencoded' };
@@ -27,11 +23,15 @@ class VapixAPI {
27
23
  }
28
24
  return res;
29
25
  }
30
- async postJson(path, jsonData, headers, options) {
31
- const data = JSON.stringify(jsonData);
32
- const head = { ...headers, 'Content-Type': 'application/json' };
26
+ async postJson(path, data, headers, options) {
33
27
  const agent = this.getClient(options?.proxyParams);
34
- const res = await agent.post({ path, data, headers: head, timeout: options?.timeout });
28
+ const jsonData = JSON.stringify(data);
29
+ const res = await agent.post({
30
+ path,
31
+ data: jsonData,
32
+ headers: { ...headers, 'Content-Type': 'application/json' },
33
+ timeout: options?.timeout,
34
+ });
35
35
  if (!res.ok) {
36
36
  throw new errors_1.ErrorWithResponse(res);
37
37
  }
@@ -39,11 +39,18 @@ class VapixAPI {
39
39
  }
40
40
  async getCameraImage(parameters, options) {
41
41
  const agent = this.getClient(options?.proxyParams);
42
- return (await agent.get({
42
+ const res = await agent.get({
43
43
  path: '/axis-cgi/jpg/image.cgi',
44
44
  parameters,
45
45
  timeout: options?.timeout,
46
- }));
46
+ });
47
+ if (!res.ok) {
48
+ throw new errors_1.ErrorWithResponse(res);
49
+ }
50
+ if (res.headers.get('content-type') !== 'image/jpeg') {
51
+ throw new Error(`Unexpected content-type: ${res.headers.get('content-type')}`);
52
+ }
53
+ return res;
47
54
  }
48
55
  async getEventDeclarations(options) {
49
56
  const data = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">' +
@@ -66,7 +73,7 @@ class VapixAPI {
66
73
  async getSupportedAudioSampleRate(options) {
67
74
  const path = '/axis-cgi/audio/streamingcapabilities.cgi';
68
75
  const jsonData = { apiVersion: '1.0', method: 'list' };
69
- const res = await this.postJson(path, jsonData, undefined, options);
76
+ const res = await this._postJsonEncoded(path, jsonData, undefined, options);
70
77
  const encoders = VapixAPI_1.audioSampleRatesResponseSchema.parse(await res.json()).data.encoders;
71
78
  const data = encoders.aac ?? encoders.AAC ?? [];
72
79
  return data.map((item) => {
@@ -89,83 +96,25 @@ class VapixAPI {
89
96
  ],
90
97
  },
91
98
  };
92
- await this.postJson('/axis-cgi/opticscontrol.cgi', data, undefined, options);
99
+ await this._postJsonEncoded('/axis-cgi/opticscontrol.cgi', data, undefined, options);
93
100
  }
94
101
  catch (err) {
95
- await this.postUrlEncoded('/axis-cgi/opticssetup.cgi', {
102
+ await this._postUrlEncoded('/axis-cgi/opticssetup.cgi', {
96
103
  autofocus: 'perform',
97
104
  source: '1',
98
- }, undefined, options);
99
- }
100
- }
101
- async checkSDCard(options) {
102
- const res = await this.postUrlEncoded('/axis-cgi/disks/list.cgi', {
103
- diskid: 'SD_DISK',
104
- }, undefined, options);
105
- const xmlText = await res.text();
106
- const parser = new fast_xml_parser_1.XMLParser({
107
- ignoreAttributes: false,
108
- attributeNamePrefix: '',
109
- allowBooleanAttributes: true,
110
- });
111
- const result = parser.parse(xmlText);
112
- const data = result.root.disks.disk;
113
- return VapixAPI_1.sdCardInfoSchema.parse({
114
- totalSize: parseInt(data.totalsize),
115
- freeSize: parseInt(data.freesize),
116
- status: VapixAPI_1.sdCardWatchedStatuses.includes(data.status) ? data.status : 'disconnected',
117
- });
118
- }
119
- mountSDCard(options) {
120
- return this._doSDCardMountAction('MOUNT', options);
121
- }
122
- unmountSDCard(options) {
123
- return this._doSDCardMountAction('UNMOUNT', options);
124
- }
125
- async _doSDCardMountAction(action, options) {
126
- const res = await this.postUrlEncoded('/axis-cgi/disks/mount.cgi', {
127
- action: action,
128
- diskid: 'SD_DISK',
129
- }, undefined, options);
130
- const textXml = await res.text();
131
- const parser = new fast_xml_parser_1.XMLParser({
132
- ignoreAttributes: false,
133
- attributeNamePrefix: '',
134
- allowBooleanAttributes: true,
135
- });
136
- const result = parser.parse(textXml);
137
- const job = result.root.job;
138
- if (job.result !== 'OK') {
139
- throw new errors_1.SDCardActionError(action, job.description);
105
+ }, options);
140
106
  }
141
- return Number(job.jobid);
142
- }
143
- async fetchSDCardJobProgress(jobId, options) {
144
- const res = await this.postUrlEncoded('/disks/job.cgi', {
145
- jobid: String(jobId),
146
- diskid: 'SD_DISK',
147
- }, undefined, options);
148
- const textXml = await res.text();
149
- const parser = new fast_xml_parser_1.XMLParser({
150
- ignoreAttributes: false,
151
- attributeNamePrefix: '',
152
- allowBooleanAttributes: true,
153
- });
154
- const job = parser.parse(textXml).root.job;
155
- if (job.result !== 'OK') {
156
- throw new errors_1.SDCardJobError(job.description);
157
- }
158
- return Number(job.progress);
159
107
  }
160
108
  downloadCameraReport(options) {
161
- return this.postUrlEncoded('/axis-cgi/serverreport.cgi', { mode: 'text' }, undefined, options);
109
+ return this._getText('/axis-cgi/serverreport.cgi', { mode: 'text' }, options);
162
110
  }
163
- getSystemLog(options) {
164
- return this.postUrlEncoded('/axis-cgi/admin/systemlog.cgi', undefined, undefined, options);
111
+ async getSystemLog(options) {
112
+ const res = await this._postUrlEncoded('/axis-cgi/admin/systemlog.cgi', {}, options);
113
+ return res.text();
165
114
  }
166
115
  async getMaxFps(channel, options) {
167
116
  const data = { apiVersion: '1.0', method: 'getCaptureModes' };
168
- const res = await this.postJson('/axis-cgi/capturemode.cgi', data, undefined, options);
117
+ const res = await this._postJsonEncoded('/axis-cgi/capturemode.cgi', data, undefined, options);
169
118
  const response = VapixAPI_1.maxFpsResponseSchema.parse(await res.json());
170
119
  const channels = response.data;
171
120
  if (channels === undefined) {
@@ -211,12 +160,12 @@ class VapixAPI {
211
160
  }
212
161
  async getDateTimeInfo(options) {
213
162
  const data = { apiVersion: '1.0', method: 'getDateTimeInfo' };
214
- const res = await this.postJson('/axis-cgi/time.cgi', data, undefined, options);
163
+ const res = await this._postJsonEncoded('/axis-cgi/time.cgi', data, undefined, options);
215
164
  return VapixAPI_1.dateTimeinfoSchema.parse(await res.json());
216
165
  }
217
166
  async getDevicesSettings(options) {
218
167
  const data = { apiVersion: '1.0', method: 'getDevicesSettings' };
219
- const res = await this.postJson('/axis-cgi/audiodevicecontrol.cgi', data, undefined, options);
168
+ const res = await this._postJsonEncoded('/axis-cgi/audiodevicecontrol.cgi', data, undefined, options);
220
169
  const result = VapixAPI_1.audioDeviceRequestSchema.parse(await res.json());
221
170
  return result.data.devices.map((device) => ({
222
171
  ...device,
@@ -225,7 +174,7 @@ class VapixAPI {
225
174
  }));
226
175
  }
227
176
  async fetchRemoteDeviceInfo(payload, options) {
228
- const res = await this.postJson('/axis-cgi/basicdeviceinfo.cgi', payload, undefined, options);
177
+ const res = await this._postJsonEncoded('/axis-cgi/basicdeviceinfo.cgi', payload, undefined, options);
229
178
  const json = await res.json();
230
179
  if ((0, utils_1.isNullish)(json.data)) {
231
180
  throw new errors_1.NoDeviceInfoError();
@@ -234,25 +183,84 @@ class VapixAPI {
234
183
  }
235
184
  async getHeaders(options) {
236
185
  const data = { apiVersion: '1.0', method: 'list' };
237
- const res = await this.postJson('/axis-cgi/customhttpheader.cgi', data, undefined, options);
186
+ const res = await this._postJsonEncoded('/axis-cgi/customhttpheader.cgi', data, undefined, options);
238
187
  return zod_1.z.object({ data: zod_1.z.record(zod_1.z.string()) }).parse(await res.json()).data;
239
188
  }
240
189
  async setHeaders(headers, options) {
241
190
  const data = { apiVersion: '1.0', method: 'set', params: headers };
242
- return this.postJson('/axis-cgi/customhttpheader.cgi', data, undefined, options);
191
+ await this._postJsonEncoded('/axis-cgi/customhttpheader.cgi', data, undefined, options);
192
+ }
193
+ async checkSDCard(options) {
194
+ const res = await this._postUrlEncoded('/axis-cgi/disks/list.cgi', {
195
+ diskid: 'SD_DISK',
196
+ }, options);
197
+ const xmlText = await res.text();
198
+ const parser = new fast_xml_parser_1.XMLParser({
199
+ ignoreAttributes: false,
200
+ attributeNamePrefix: '',
201
+ allowBooleanAttributes: true,
202
+ });
203
+ const result = parser.parse(xmlText);
204
+ const data = result.root.disks.disk;
205
+ return VapixAPI_1.sdCardInfoSchema.parse({
206
+ totalSize: parseInt(data.totalsize),
207
+ freeSize: parseInt(data.freesize),
208
+ status: VapixAPI_1.sdCardWatchedStatuses.includes(data.status) ? data.status : 'disconnected',
209
+ });
210
+ }
211
+ mountSDCard(options) {
212
+ return this._doSDCardMountAction('MOUNT', options);
213
+ }
214
+ unmountSDCard(options) {
215
+ return this._doSDCardMountAction('UNMOUNT', options);
216
+ }
217
+ async _doSDCardMountAction(action, options) {
218
+ const res = await this._postUrlEncoded('/axis-cgi/disks/mount.cgi', {
219
+ action: action,
220
+ diskid: 'SD_DISK',
221
+ }, options);
222
+ const textXml = await res.text();
223
+ const parser = new fast_xml_parser_1.XMLParser({
224
+ ignoreAttributes: false,
225
+ attributeNamePrefix: '',
226
+ allowBooleanAttributes: true,
227
+ });
228
+ const result = parser.parse(textXml);
229
+ const job = result.root.job;
230
+ if (job.result !== 'OK') {
231
+ throw new errors_1.SDCardActionError(action, job.description);
232
+ }
233
+ return Number(job.jobid);
234
+ }
235
+ async fetchSDCardJobProgress(jobId, options) {
236
+ const res = await this._postUrlEncoded('/disks/job.cgi', {
237
+ jobid: String(jobId),
238
+ diskid: 'SD_DISK',
239
+ }, options);
240
+ const textXml = await res.text();
241
+ const parser = new fast_xml_parser_1.XMLParser({
242
+ ignoreAttributes: false,
243
+ attributeNamePrefix: '',
244
+ allowBooleanAttributes: true,
245
+ });
246
+ const job = parser.parse(textXml).root.job;
247
+ if (job.result !== 'OK') {
248
+ throw new errors_1.SDCardJobError(job.description);
249
+ }
250
+ return Number(job.progress);
243
251
  }
244
252
  async getParameter(paramNames, options) {
245
- const response = await this.postUrlEncoded('/axis-cgi/param.cgi', {
253
+ const response = await this._postUrlEncoded('/axis-cgi/param.cgi', {
246
254
  action: 'list',
247
255
  group: (0, utils_1.arrayToUrl)(paramNames),
248
- }, undefined, options);
256
+ }, options);
249
257
  return VapixAPI.parseParameters(await response.text());
250
258
  }
251
259
  async setParameter(params, options) {
252
- const res = await this.postUrlEncoded('/axis-cgi/param.cgi', {
260
+ const res = await this._postUrlEncoded('/axis-cgi/param.cgi', {
253
261
  ...params,
254
262
  action: 'update',
255
- }, undefined, options);
263
+ }, options);
256
264
  const responseText = await res.text();
257
265
  if (responseText.startsWith('# Error')) {
258
266
  throw new errors_1.SettingParameterError(responseText);
@@ -300,10 +308,10 @@ class VapixAPI {
300
308
  return this.setParameter(params, options);
301
309
  }
302
310
  async getPTZPresetList(channel, options) {
303
- const res = await this.postUrlEncoded('/axis-cgi/com/ptz.cgi', {
311
+ const res = await this._postUrlEncoded('/axis-cgi/com/ptz.cgi', {
304
312
  query: 'presetposcam',
305
313
  camera: channel,
306
- }, undefined, options);
314
+ }, options);
307
315
  const text = await res.text();
308
316
  const lines = text.split(/[\r\n]/);
309
317
  const positions = [];
@@ -320,11 +328,11 @@ class VapixAPI {
320
328
  }
321
329
  async listPTZ(camera, options) {
322
330
  const url = `/axis-cgi/com/ptz.cgi`;
323
- const response = await this.postUrlEncoded(url, {
331
+ const response = await this._postUrlEncoded(url, {
324
332
  camera,
325
333
  query: 'presetposcamdata',
326
334
  format: 'json',
327
- }, undefined, options);
335
+ }, options);
328
336
  const text = await response.text();
329
337
  if (text === '') {
330
338
  throw new errors_1.PtzNotSupportedError();
@@ -332,10 +340,10 @@ class VapixAPI {
332
340
  return VapixAPI.parseCameraPtzResponse(text)[camera] ?? [];
333
341
  }
334
342
  async listPtzVideoSourceOverview(options) {
335
- const response = await this.postUrlEncoded('/axis-cgi/com/ptz.cgi', {
343
+ const response = await this._postUrlEncoded('/axis-cgi/com/ptz.cgi', {
336
344
  query: 'presetposall',
337
345
  format: 'json',
338
- }, undefined, options);
346
+ }, options);
339
347
  const text = await response.text();
340
348
  if (text === '') {
341
349
  throw new errors_1.PtzNotSupportedError();
@@ -352,17 +360,17 @@ class VapixAPI {
352
360
  });
353
361
  return VapixAPI_1.ptzOverviewSchema.parse(res);
354
362
  }
355
- goToPreset(channel, presetName, options) {
356
- return this.postUrlEncoded('/axis-cgi/com/ptz.cgi', {
363
+ async goToPreset(channel, presetName, options) {
364
+ await this._postUrlEncoded('/axis-cgi/com/ptz.cgi', {
357
365
  camera: channel.toString(),
358
366
  gotoserverpresetname: presetName,
359
- }, undefined, options);
367
+ }, options);
360
368
  }
361
369
  async getPtzPosition(camera, options) {
362
- const res = await this.postUrlEncoded('/axis-cgi/com/ptz.cgi', {
370
+ const res = await this._postUrlEncoded('/axis-cgi/com/ptz.cgi', {
363
371
  query: 'position',
364
372
  camera: camera.toString(),
365
- }, undefined, options);
373
+ }, options);
366
374
  const params = VapixAPI.parseParameters(await res.text());
367
375
  return VapixAPI_1.cameraPTZItemDataSchema.parse({
368
376
  pan: Number(params.pan),
@@ -371,16 +379,16 @@ class VapixAPI {
371
379
  });
372
380
  }
373
381
  async getPorts(options) {
374
- const res = await this.postJson('/axis-cgi/io/portmanagement.cgi', {
382
+ const res = await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
375
383
  apiVersion: '1.0',
376
384
  context: '',
377
385
  method: 'getPorts',
378
386
  }, undefined, options);
379
387
  const portResponseParsed = VapixAPI_1.getPortsResponseSchema.parse(await res.json());
380
- return portResponseParsed.data.items;
388
+ return portResponseParsed.data.items ?? [];
381
389
  }
382
390
  async setPorts(ports, options) {
383
- await this.postJson('/axis-cgi/io/portmanagement.cgi', {
391
+ await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
384
392
  apiVersion: '1.0',
385
393
  context: '',
386
394
  method: 'setPorts',
@@ -388,13 +396,103 @@ class VapixAPI {
388
396
  }, undefined, options);
389
397
  }
390
398
  async setPortStateSequence(port, sequence, options) {
391
- await this.postJson('/axis-cgi/io/portmanagement.cgi', {
399
+ await this._postJsonEncoded('/axis-cgi/io/portmanagement.cgi', {
392
400
  apiVersion: '1.0',
393
401
  context: '',
394
402
  method: 'setStateSequence',
395
403
  params: { port, sequence },
396
404
  }, undefined, options);
397
405
  }
406
+ async addCameraUser(username, pass, sgrp, comment, options) {
407
+ const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
408
+ action: 'add',
409
+ user: username,
410
+ pwd: pass,
411
+ grp: 'users',
412
+ sgrp,
413
+ comment,
414
+ }, options);
415
+ await VapixAPI.checkTextResponseForError(res);
416
+ }
417
+ async getCameraUsers(options) {
418
+ const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
419
+ action: 'get',
420
+ }, options);
421
+ const responseText = await VapixAPI.checkTextResponseForError(res);
422
+ const viewersString = responseText.match(/^viewer="([a-z0-9,]*)"/im)?.[1] ?? '';
423
+ return viewersString.split(',');
424
+ }
425
+ async editCameraUser(username, pass, options) {
426
+ const res = await this._postUrlEncoded('/axis-cgi/pwdgrp.cgi', {
427
+ action: 'update',
428
+ user: username,
429
+ pwd: pass,
430
+ }, options);
431
+ await VapixAPI.checkTextResponseForError(res);
432
+ }
433
+ async getRecordingRuleList(options) {
434
+ const res = await this._getText('/axis-cgi/record/continuous/listconfiguration.cgi', undefined, options);
435
+ const resultNode = VapixAPI.parseXmlResponse(res, 'continuousrecordingconfigurations');
436
+ const configurationNodes = resultNode.getElementsByTagName('continuousrecordingconfiguration');
437
+ const configs = [];
438
+ for (const node of configurationNodes) {
439
+ if ((0, utils_1.isNullish)(node)) {
440
+ continue;
441
+ }
442
+ configs.push({
443
+ profile: node.getAttribute('profile') ?? '',
444
+ diskid: node.getAttribute('diskid') ?? '',
445
+ options: VapixAPI.parseQueryString(node.getAttribute('options')),
446
+ eventid: node.getAttribute('eventid') ?? '',
447
+ });
448
+ }
449
+ return configs;
450
+ }
451
+ async addRecordingRule(params, options) {
452
+ const res = await this._getText('/axis-cgi/record/continuous/addconfiguration.cgi', params, options);
453
+ const resultNode = VapixAPI.parseXmlResponse(res, 'configure');
454
+ const result = resultNode.getAttribute('result');
455
+ if (result !== 'OK') {
456
+ throw new Error(resultNode.getAttribute('errormsg') ?? result ?? 'Unknown error');
457
+ }
458
+ return resultNode.getAttribute('profile');
459
+ }
460
+ async removeRecordingRule(profileId, options) {
461
+ const res = await this._getText('/axis-cgi/record/continuous/removeconfiguration.cgi', {
462
+ profile: profileId,
463
+ }, options);
464
+ const resultNode = VapixAPI.parseXmlResponse(res, 'remove');
465
+ const result = resultNode.getAttribute('result');
466
+ if (result !== 'OK') {
467
+ throw new Error(resultNode.getAttribute('errormsg') ?? result ?? 'Unknown error');
468
+ }
469
+ }
470
+ async getDiskInfo(diskId = 'all', options) {
471
+ const res = await this._getText('/axis-cgi/disks/list.cgi', {
472
+ diskid: diskId,
473
+ }, options);
474
+ const resultNode = VapixAPI.parseXmlResponse(res, 'disks');
475
+ const disks = resultNode.getElementsByTagName('disk');
476
+ if ((0, utils_1.isNullish)(disks) || disks.length === 0) {
477
+ return false;
478
+ }
479
+ const requiredReadyProps = {
480
+ status: 'OK',
481
+ locked: 'no',
482
+ readonly: 'no',
483
+ };
484
+ for (const disk of disks) {
485
+ let isReady = true;
486
+ for (const name in requiredReadyProps) {
487
+ const value = disk.getAttribute(name);
488
+ isReady = isReady && requiredReadyProps[name] === value;
489
+ }
490
+ if (isReady) {
491
+ return true;
492
+ }
493
+ }
494
+ return false;
495
+ }
398
496
  async getApplicationList(options) {
399
497
  const agent = this.getClient(options?.proxyParams);
400
498
  const res = await agent.get({ path: '/axis-cgi/applications/list.cgi', timeout: options?.timeout });
@@ -412,7 +510,7 @@ class VapixAPI {
412
510
  const appList = apps.map((app) => {
413
511
  return {
414
512
  ...app,
415
- appId: VapixAPI_1.APP_IDS.find((id) => id.toLowerCase() === app.Name.toLowerCase()) ?? null,
513
+ appId: VapixAPI_1.ALL_APP_IDS.find((id) => id.toLowerCase() === app.Name.toLowerCase()) ?? null,
416
514
  };
417
515
  });
418
516
  return VapixAPI_1.applicationListSchema.parse(appList);
@@ -472,7 +570,7 @@ class VapixAPI {
472
570
  headers: {
473
571
  contentType: 'application/octet-stream',
474
572
  },
475
- timeout: options?.timeout ?? 120000,
573
+ timeout: options?.timeout ?? 300000,
476
574
  });
477
575
  if (!res.ok) {
478
576
  throw new errors_1.ErrorWithResponse(res);
@@ -482,6 +580,21 @@ class VapixAPI {
482
580
  throw new errors_1.ApplicationAPIError('INSTALL', text);
483
581
  }
484
582
  }
583
+ static parseQueryString = (queryString) => {
584
+ const entries = queryString
585
+ ?.split('&')
586
+ .filter((x) => x !== '')
587
+ .map((x) => x.split('=', 2));
588
+ return !(0, utils_1.isNullish)(entries) ? Object.fromEntries(entries) : {};
589
+ };
590
+ static checkTextResponseForError = async (response) => {
591
+ const responseText = await response.text();
592
+ const isError = responseText.match(/Error:([^<]*)/);
593
+ if (!(0, utils_1.isNullish)(isError)) {
594
+ throw new errors_1.ErrorWithResponse(response);
595
+ }
596
+ return responseText;
597
+ };
485
598
  static parseParameters = (response) => {
486
599
  const params = {};
487
600
  const lines = response.split(/[\r\n]/);
@@ -548,5 +661,13 @@ class VapixAPI {
548
661
  });
549
662
  return res;
550
663
  };
664
+ static parseXmlResponse = (xml, nodeName) => {
665
+ const doc = new DOMParser().parseFromString(xml, 'text/xml');
666
+ const node = doc.getElementsByTagName(nodeName);
667
+ if (node.length !== 1 || (0, utils_1.isNullish)(node[0])) {
668
+ throw new Error('Invalid XML from camera');
669
+ }
670
+ return node[0];
671
+ };
551
672
  }
552
673
  exports.VapixAPI = VapixAPI;
@@ -92,11 +92,17 @@ export declare class BadRequestError<T extends TResponse> extends ErrorWithRespo
92
92
  }
93
93
  export declare class MigrationError extends Error {
94
94
  readonly valid: TStream[];
95
- readonly invalid: (TOldStream & {
96
- id: number;
95
+ readonly old: (TOldStream & {
96
+ streamId: string;
97
97
  })[];
98
- constructor(valid: TStream[], invalid: (TOldStream & {
99
- id: number;
100
- })[]);
98
+ readonly invalid: any[];
99
+ readonly unknown: {
100
+ platform: string;
101
+ }[];
102
+ constructor(valid: TStream[], old: (TOldStream & {
103
+ streamId: string;
104
+ })[], invalid?: any[], unknown?: {
105
+ platform: string;
106
+ }[]);
101
107
  }
102
108
  export {};
@@ -206,12 +206,16 @@ class BadRequestError extends ErrorWithResponse {
206
206
  exports.BadRequestError = BadRequestError;
207
207
  class MigrationError extends Error {
208
208
  valid;
209
+ old;
209
210
  invalid;
210
- constructor(valid, invalid) {
211
+ unknown;
212
+ constructor(valid, old, invalid = [], unknown = []) {
211
213
  super('Migration to newer version is needed: some stream entries failed to parse.');
212
214
  this.name = 'MigrationError';
213
215
  this.valid = valid;
216
+ this.old = old;
214
217
  this.invalid = invalid;
218
+ this.unknown = unknown;
215
219
  }
216
220
  }
217
221
  exports.MigrationError = MigrationError;
package/cjs/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './errors/errors';
2
2
  export * from './internal/types';
3
3
  export * from './internal/constants';
4
+ export * from './internal/convertors';
4
5
  export * from './internal/utils';
5
6
  export * from './internal/versionCompare';
6
7
  export * from './internal/ProxyClient';
package/cjs/index.js CHANGED
@@ -18,6 +18,7 @@ exports.VapixAPI = exports.CamScripterAPI = exports.PlaneTrackerEvents = exports
18
18
  __exportStar(require("./errors/errors"), exports);
19
19
  __exportStar(require("./internal/types"), exports);
20
20
  __exportStar(require("./internal/constants"), exports);
21
+ __exportStar(require("./internal/convertors"), exports);
21
22
  __exportStar(require("./internal/utils"), exports);
22
23
  __exportStar(require("./internal/versionCompare"), exports);
23
24
  __exportStar(require("./internal/ProxyClient"), exports);
@@ -0,0 +1,15 @@
1
+ import { THttpRequestOptions, TProxyParams } from '../types/common';
2
+ import { ProxyClient } from './ProxyClient';
3
+ import { IClient, TBlobResponse, TParameters, TResponse } from './types';
4
+ export declare class BasicAPI<Client extends IClient<TResponse, any>> {
5
+ protected client: Client;
6
+ constructor(client: Client);
7
+ getClient(proxyParams?: TProxyParams): Client | ProxyClient<Client>;
8
+ protected _getJson(path: string, parameters?: TParameters, options?: THttpRequestOptions): Promise<any>;
9
+ protected _getText(path: string, parameters?: TParameters, options?: THttpRequestOptions): Promise<string>;
10
+ protected _getBlob(path: string, parameters?: TParameters, options?: THttpRequestOptions): Promise<TBlobResponse<Client>>;
11
+ private parseBlobResponse;
12
+ protected _post(path: string, data: string | Parameters<Client['post']>[0]['data'], parameters?: TParameters, options?: THttpRequestOptions, headers?: Record<string, string>): Promise<any>;
13
+ protected _postJsonEncoded(path: string, data: string | Parameters<Client['post']>[0]['data'], parameters?: TParameters, options?: THttpRequestOptions): Promise<TResponse>;
14
+ protected _postUrlEncoded(path: string, data: TParameters, options?: THttpRequestOptions): Promise<TResponse>;
15
+ }