camstreamerlib 4.0.0-beta.29 → 4.0.0-beta.30

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 (161) hide show
  1. package/README.md +6 -2
  2. package/cjs/CamOverlayAPI.d.ts +38 -615
  3. package/cjs/CamOverlayAPI.js +128 -104
  4. package/cjs/CamOverlayDrawingAPI.d.ts +2 -47
  5. package/cjs/CamOverlayPainter/Frame.d.ts +8 -37
  6. package/cjs/CamOverlayPainter/Frame.js +33 -0
  7. package/cjs/CamOverlayPainter/Painter.d.ts +5 -10
  8. package/cjs/CamOverlayPainter/Painter.js +2 -4
  9. package/cjs/CamOverlayPainter/ResourceManager.d.ts +3 -2
  10. package/cjs/CamOverlayPainter/ResourceManager.js +2 -1
  11. package/cjs/CamScripterAPI.d.ts +12 -12
  12. package/cjs/CamScripterAPI.js +33 -27
  13. package/cjs/CamStreamerAPI.d.ts +11 -9
  14. package/cjs/CamStreamerAPI.js +28 -22
  15. package/cjs/CamSwitcherAPI.d.ts +35 -34
  16. package/cjs/CamSwitcherAPI.js +94 -82
  17. package/cjs/PlaneTrackerAPI.d.ts +30 -36
  18. package/cjs/PlaneTrackerAPI.js +132 -71
  19. package/cjs/VapixAPI.d.ts +43 -40
  20. package/cjs/VapixAPI.js +205 -183
  21. package/cjs/events/AxisCameraStationEvents.d.ts +5 -5
  22. package/cjs/events/AxisCameraStationEvents.js +17 -12
  23. package/cjs/events/GenetecAgent.d.ts +2 -0
  24. package/cjs/events/GenetecAgent.js +15 -4
  25. package/cjs/index.d.ts +7 -1
  26. package/cjs/index.js +12 -2
  27. package/cjs/internal/ProxyClient.d.ts +7 -8
  28. package/cjs/internal/ProxyClient.js +25 -31
  29. package/cjs/internal/types.d.ts +16 -9
  30. package/cjs/internal/utils.d.ts +1 -2
  31. package/cjs/internal/utils.js +1 -5
  32. package/cjs/node/DefaultClient.d.ts +3 -5
  33. package/cjs/node/DefaultClient.js +10 -14
  34. package/cjs/node/HttpRequestSender.d.ts +1 -0
  35. package/cjs/node/HttpRequestSender.js +13 -3
  36. package/cjs/node/WsClient.d.ts +1 -0
  37. package/cjs/node/index.d.ts +2 -0
  38. package/cjs/node/index.js +18 -1
  39. package/cjs/{models/CamOverlayAPI/widgetsSchema.d.ts → types/CamOverlayAPI/CamOverlayAPI.d.ts} +625 -375
  40. package/cjs/{models/CamOverlayAPI/widgetCommonSchema.js → types/CamOverlayAPI/CamOverlayAPI.js} +65 -14
  41. package/cjs/{models → types}/CamOverlayAPI/accuweatherSchema.d.ts +40 -10
  42. package/cjs/{models → types}/CamOverlayAPI/accuweatherSchema.js +11 -9
  43. package/cjs/{models → types}/CamOverlayAPI/customGraphicsSchema.d.ts +89 -5
  44. package/cjs/{models → types}/CamOverlayAPI/customGraphicsSchema.js +9 -7
  45. package/{esm/models → cjs/types}/CamOverlayAPI/imagesSchema.d.ts +40 -13
  46. package/cjs/types/CamOverlayAPI/imagesSchema.js +12 -0
  47. package/cjs/{models → types}/CamOverlayAPI/index.d.ts +0 -4
  48. package/cjs/{models → types}/CamOverlayAPI/index.js +0 -4
  49. package/{esm/models → cjs/types}/CamOverlayAPI/infotickerSchema.d.ts +43 -9
  50. package/cjs/{models → types}/CamOverlayAPI/infotickerSchema.js +10 -8
  51. package/{esm/models → cjs/types}/CamOverlayAPI/pipSchema.d.ts +48 -7
  52. package/cjs/{models → types}/CamOverlayAPI/pipSchema.js +8 -6
  53. package/{esm/models → cjs/types}/CamOverlayAPI/ptzCompassSchema.d.ts +40 -7
  54. package/cjs/{models → types}/CamOverlayAPI/ptzCompassSchema.js +8 -6
  55. package/cjs/{models → types}/CamOverlayAPI/ptzSchema.d.ts +42 -14
  56. package/cjs/types/CamOverlayAPI/ptzSchema.js +15 -0
  57. package/{esm/models → cjs/types}/CamOverlayAPI/screenSharingSchema.d.ts +26 -5
  58. package/cjs/types/CamOverlayAPI/screenSharingSchema.js +11 -0
  59. package/cjs/{models → types}/CamOverlayAPI/webCameraSharingSchema.d.ts +26 -5
  60. package/cjs/types/CamOverlayAPI/webCameraSharingSchema.js +11 -0
  61. package/cjs/types/CamOverlayDrawingAPI.d.ts +58 -0
  62. package/cjs/types/CamOverlayDrawingAPI.js +2 -0
  63. package/cjs/types/CamOverlayPainter.d.ts +74 -0
  64. package/cjs/types/CamOverlayPainter.js +2 -0
  65. package/cjs/types/CamStreamerAPI.d.ts +4 -4
  66. package/cjs/types/PlaneTrackerAPI.d.ts +6 -0
  67. package/cjs/types/common.d.ts +12 -3
  68. package/cjs/web/DefaultClient.d.ts +4 -4
  69. package/cjs/web/DefaultClient.js +21 -11
  70. package/esm/CamOverlayAPI.d.ts +38 -615
  71. package/esm/CamOverlayAPI.js +127 -103
  72. package/esm/CamOverlayDrawingAPI.d.ts +2 -47
  73. package/esm/CamOverlayPainter/Frame.d.ts +8 -37
  74. package/esm/CamOverlayPainter/Frame.js +33 -0
  75. package/esm/CamOverlayPainter/Painter.d.ts +5 -10
  76. package/esm/CamOverlayPainter/Painter.js +1 -2
  77. package/esm/CamOverlayPainter/ResourceManager.d.ts +3 -2
  78. package/esm/CamOverlayPainter/ResourceManager.js +1 -1
  79. package/esm/CamScripterAPI.d.ts +12 -12
  80. package/esm/CamScripterAPI.js +32 -26
  81. package/esm/CamStreamerAPI.d.ts +11 -9
  82. package/esm/CamStreamerAPI.js +28 -22
  83. package/esm/CamSwitcherAPI.d.ts +35 -34
  84. package/esm/CamSwitcherAPI.js +95 -83
  85. package/esm/PlaneTrackerAPI.d.ts +30 -36
  86. package/esm/PlaneTrackerAPI.js +131 -70
  87. package/esm/VapixAPI.d.ts +43 -40
  88. package/esm/VapixAPI.js +204 -182
  89. package/esm/events/AxisCameraStationEvents.d.ts +5 -5
  90. package/esm/events/AxisCameraStationEvents.js +18 -13
  91. package/esm/events/GenetecAgent.d.ts +2 -0
  92. package/esm/events/GenetecAgent.js +15 -4
  93. package/esm/index.d.ts +7 -1
  94. package/esm/index.js +7 -1
  95. package/esm/internal/ProxyClient.d.ts +7 -8
  96. package/esm/internal/ProxyClient.js +25 -31
  97. package/esm/internal/types.d.ts +16 -9
  98. package/esm/internal/utils.d.ts +1 -2
  99. package/esm/internal/utils.js +0 -3
  100. package/esm/node/DefaultClient.d.ts +3 -5
  101. package/esm/node/DefaultClient.js +10 -14
  102. package/esm/node/HttpRequestSender.d.ts +1 -0
  103. package/esm/node/HttpRequestSender.js +13 -3
  104. package/esm/node/WsClient.d.ts +1 -0
  105. package/esm/node/index.d.ts +2 -0
  106. package/esm/node/index.js +2 -0
  107. package/esm/{models/CamOverlayAPI/widgetsSchema.d.ts → types/CamOverlayAPI/CamOverlayAPI.d.ts} +625 -375
  108. package/esm/{models/CamOverlayAPI/widgetCommonSchema.js → types/CamOverlayAPI/CamOverlayAPI.js} +64 -13
  109. package/esm/{models → types}/CamOverlayAPI/accuweatherSchema.d.ts +40 -10
  110. package/esm/{models → types}/CamOverlayAPI/accuweatherSchema.js +3 -2
  111. package/esm/{models → types}/CamOverlayAPI/customGraphicsSchema.d.ts +89 -5
  112. package/esm/{models → types}/CamOverlayAPI/customGraphicsSchema.js +3 -2
  113. package/{cjs/models → esm/types}/CamOverlayAPI/imagesSchema.d.ts +40 -13
  114. package/esm/types/CamOverlayAPI/imagesSchema.js +8 -0
  115. package/esm/{models → types}/CamOverlayAPI/index.d.ts +0 -4
  116. package/esm/{models → types}/CamOverlayAPI/index.js +0 -4
  117. package/{cjs/models → esm/types}/CamOverlayAPI/infotickerSchema.d.ts +43 -9
  118. package/esm/{models → types}/CamOverlayAPI/infotickerSchema.js +3 -2
  119. package/{cjs/models → esm/types}/CamOverlayAPI/pipSchema.d.ts +48 -7
  120. package/esm/{models → types}/CamOverlayAPI/pipSchema.js +3 -2
  121. package/{cjs/models → esm/types}/CamOverlayAPI/ptzCompassSchema.d.ts +40 -7
  122. package/esm/{models → types}/CamOverlayAPI/ptzCompassSchema.js +3 -2
  123. package/esm/{models → types}/CamOverlayAPI/ptzSchema.d.ts +42 -14
  124. package/esm/{models → types}/CamOverlayAPI/ptzSchema.js +3 -2
  125. package/{cjs/models → esm/types}/CamOverlayAPI/screenSharingSchema.d.ts +26 -5
  126. package/esm/types/CamOverlayAPI/screenSharingSchema.js +7 -0
  127. package/esm/{models → types}/CamOverlayAPI/webCameraSharingSchema.d.ts +26 -5
  128. package/esm/types/CamOverlayAPI/webCameraSharingSchema.js +7 -0
  129. package/esm/types/CamOverlayDrawingAPI.d.ts +58 -0
  130. package/esm/types/CamOverlayDrawingAPI.js +1 -0
  131. package/esm/types/CamOverlayPainter.d.ts +74 -0
  132. package/esm/types/CamOverlayPainter.js +1 -0
  133. package/esm/types/CamStreamerAPI.d.ts +4 -4
  134. package/esm/types/PlaneTrackerAPI.d.ts +6 -0
  135. package/esm/types/common.d.ts +12 -3
  136. package/esm/web/DefaultClient.d.ts +4 -4
  137. package/esm/web/DefaultClient.js +21 -11
  138. package/package.json +2 -2
  139. package/cjs/models/CamOverlayAPI/constants.d.ts +0 -11
  140. package/cjs/models/CamOverlayAPI/constants.js +0 -14
  141. package/cjs/models/CamOverlayAPI/fileSchema.d.ts +0 -28
  142. package/cjs/models/CamOverlayAPI/fileSchema.js +0 -17
  143. package/cjs/models/CamOverlayAPI/imagesSchema.js +0 -10
  144. package/cjs/models/CamOverlayAPI/ptzSchema.js +0 -13
  145. package/cjs/models/CamOverlayAPI/screenSharingSchema.js +0 -9
  146. package/cjs/models/CamOverlayAPI/webCameraSharingSchema.js +0 -9
  147. package/cjs/models/CamOverlayAPI/widgetCommonSchema.d.ts +0 -126
  148. package/cjs/models/CamOverlayAPI/widgetsSchema.js +0 -27
  149. package/cjs/types/CamOverlayAPI.d.ts +0 -328
  150. package/cjs/types/CamOverlayAPI.js +0 -26
  151. package/esm/models/CamOverlayAPI/constants.d.ts +0 -11
  152. package/esm/models/CamOverlayAPI/constants.js +0 -11
  153. package/esm/models/CamOverlayAPI/fileSchema.d.ts +0 -28
  154. package/esm/models/CamOverlayAPI/fileSchema.js +0 -14
  155. package/esm/models/CamOverlayAPI/imagesSchema.js +0 -7
  156. package/esm/models/CamOverlayAPI/screenSharingSchema.js +0 -6
  157. package/esm/models/CamOverlayAPI/webCameraSharingSchema.js +0 -6
  158. package/esm/models/CamOverlayAPI/widgetCommonSchema.d.ts +0 -126
  159. package/esm/models/CamOverlayAPI/widgetsSchema.js +0 -24
  160. package/esm/types/CamOverlayAPI.d.ts +0 -328
  161. package/esm/types/CamOverlayAPI.js +0 -14
package/cjs/VapixAPI.js CHANGED
@@ -10,48 +10,56 @@ const zod_1 = require("zod");
10
10
  const fast_xml_parser_1 = require("fast-xml-parser");
11
11
  class VapixAPI {
12
12
  client;
13
- constructor(client, getProxyUrl) {
14
- this.client = new ProxyClient_1.ProxyClient(client, getProxyUrl);
13
+ constructor(client) {
14
+ this.client = client;
15
15
  }
16
- async getUrlEncoded(proxy, path, parameters, headers = {}) {
16
+ async postUrlEncoded(path, parameters, headers, options) {
17
17
  const data = (0, utils_1.paramToUrl)(parameters);
18
18
  const head = { ...headers, 'Content-Type': 'application/x-www-form-urlencoded' };
19
- const res = await this.client.post(proxy, path, data, {}, head);
19
+ const agent = this.getAgent(options?.proxyParams);
20
+ const res = await agent.post({ path, data, headers: head, timeout: options?.timeout });
20
21
  if (!res.ok) {
21
22
  throw new Error(await (0, utils_1.responseStringify)(res));
22
23
  }
23
24
  return res;
24
25
  }
25
- async postJson(proxy, path, jsonData, headers = {}) {
26
+ async postJson(path, jsonData, headers, options) {
26
27
  const data = JSON.stringify(jsonData);
27
28
  const head = { ...headers, 'Content-Type': 'application/json' };
28
- const res = await this.client.post(proxy, path, data, {}, head);
29
+ const agent = this.getAgent(options?.proxyParams);
30
+ const res = await agent.post({ path, data, headers: head, timeout: options?.timeout });
29
31
  if (!res.ok) {
30
32
  throw new Error(await (0, utils_1.responseStringify)(res));
31
33
  }
32
34
  return res;
33
35
  }
34
- async getCameraImage(params, proxy = null) {
35
- return await this.client.get(proxy, '/axis-cgi/jpg/image.cgi', params);
36
+ async getCameraImage(parameters, options) {
37
+ const agent = this.getAgent(options?.proxyParams);
38
+ return await agent.get({ path: '/axis-cgi/jpg/image.cgi', parameters, timeout: options?.timeout });
36
39
  }
37
- async getEventDeclarations(proxy = null) {
40
+ async getEventDeclarations(options) {
38
41
  const data = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">' +
39
42
  '<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
40
43
  'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
41
44
  '<GetEventInstances xmlns="http://www.axis.com/vapix/ws/event1"/>' +
42
45
  '</s:Body>' +
43
46
  '</s:Envelope>';
44
- const res = await this.client.post(proxy, '/vapix/services', data, { 'Content-Type': 'application/soap+xml' });
47
+ const agent = this.getAgent(options?.proxyParams);
48
+ const res = await agent.post({
49
+ path: '/vapix/services',
50
+ data,
51
+ headers: { 'Content-Type': 'application/soap+xml' },
52
+ });
45
53
  if (!res.ok) {
46
54
  throw new Error(await (0, utils_1.responseStringify)(res));
47
55
  }
48
56
  const declarations = await res.text();
49
57
  return prettifyXml(declarations);
50
58
  }
51
- async getSupportedAudioSampleRate(proxy = null) {
52
- const url = '/axis-cgi/audio/streamingcapabilities.cgi';
59
+ async getSupportedAudioSampleRate(options) {
60
+ const path = '/axis-cgi/audio/streamingcapabilities.cgi';
53
61
  const jsonData = { apiVersion: '1.0', method: 'list' };
54
- const res = await this.postJson(proxy, url, jsonData);
62
+ const res = await this.postJson(path, jsonData, undefined, options);
55
63
  const encoders = VapixAPI_1.audioSampleRatesResponseSchema.parse(await res.json()).data.encoders;
56
64
  const data = encoders.aac ?? encoders.AAC ?? [];
57
65
  return data.map((item) => {
@@ -61,7 +69,7 @@ class VapixAPI {
61
69
  };
62
70
  });
63
71
  }
64
- async performAutofocus(proxy = null) {
72
+ async performAutofocus(options) {
65
73
  try {
66
74
  const data = {
67
75
  apiVersion: '1',
@@ -74,19 +82,19 @@ class VapixAPI {
74
82
  ],
75
83
  },
76
84
  };
77
- await this.postJson(proxy, '/axis-cgi/opticscontrol.cgi', data);
85
+ await this.postJson('/axis-cgi/opticscontrol.cgi', data, undefined, options);
78
86
  }
79
87
  catch (err) {
80
- await this.getUrlEncoded(proxy, '/axis-cgi/opticssetup.cgi', {
88
+ await this.postUrlEncoded('/axis-cgi/opticssetup.cgi', {
81
89
  autofocus: 'perform',
82
90
  source: '1',
83
- });
91
+ }, undefined, options);
84
92
  }
85
93
  }
86
- async checkSDCard(proxy = null) {
87
- const res = await this.getUrlEncoded(proxy, '/axis-cgi/disks/list.cgi', {
94
+ async checkSDCard(options) {
95
+ const res = await this.postUrlEncoded('/axis-cgi/disks/list.cgi', {
88
96
  diskid: 'SD_DISK',
89
- });
97
+ }, undefined, options);
90
98
  const xmlText = await res.text();
91
99
  const parser = new fast_xml_parser_1.XMLParser({
92
100
  ignoreAttributes: false,
@@ -101,17 +109,17 @@ class VapixAPI {
101
109
  status: VapixAPI_1.sdCardWatchedStatuses.includes(data.status) ? data.status : 'disconnected',
102
110
  };
103
111
  }
104
- mountSDCard(proxy = null) {
105
- return this._doSDCardMountAction('MOUNT', proxy);
112
+ mountSDCard(options) {
113
+ return this._doSDCardMountAction('MOUNT', options);
106
114
  }
107
- unmountSDCard(proxy = null) {
108
- return this._doSDCardMountAction('UNMOUNT', proxy);
115
+ unmountSDCard(options) {
116
+ return this._doSDCardMountAction('UNMOUNT', options);
109
117
  }
110
- async _doSDCardMountAction(action, proxy = null) {
111
- const res = await this.getUrlEncoded(proxy, '/axis-cgi/disks/mount.cgi', {
118
+ async _doSDCardMountAction(action, options) {
119
+ const res = await this.postUrlEncoded('/axis-cgi/disks/mount.cgi', {
112
120
  action: action,
113
121
  diskid: 'SD_DISK',
114
- });
122
+ }, undefined, options);
115
123
  const textXml = await res.text();
116
124
  const parser = new fast_xml_parser_1.XMLParser({
117
125
  ignoreAttributes: false,
@@ -125,11 +133,11 @@ class VapixAPI {
125
133
  }
126
134
  return Number(job.jobid);
127
135
  }
128
- async fetchSDCardJobProgress(jobId, proxy = null) {
129
- const res = await this.getUrlEncoded(proxy, '/disks/job.cgi', {
136
+ async fetchSDCardJobProgress(jobId, options) {
137
+ const res = await this.postUrlEncoded('/disks/job.cgi', {
130
138
  jobid: String(jobId),
131
139
  diskid: 'SD_DISK',
132
- });
140
+ }, undefined, options);
133
141
  const textXml = await res.text();
134
142
  const parser = new fast_xml_parser_1.XMLParser({
135
143
  ignoreAttributes: false,
@@ -142,15 +150,15 @@ class VapixAPI {
142
150
  }
143
151
  return Number(job.progress);
144
152
  }
145
- downloadCameraReport(proxy = null) {
146
- return this.getUrlEncoded(proxy, '/axis-cgi/serverreport.cgi', { mode: 'text' });
153
+ downloadCameraReport(options) {
154
+ return this.postUrlEncoded('/axis-cgi/serverreport.cgi', { mode: 'text' }, undefined, options);
147
155
  }
148
- getSystemLog(proxy = null) {
149
- return this.getUrlEncoded(proxy, '/axis-cgi/admin/systemlog.cgi');
156
+ getSystemLog(options) {
157
+ return this.postUrlEncoded('/axis-cgi/admin/systemlog.cgi', undefined, undefined, options);
150
158
  }
151
- async getMaxFps(channel, proxy = null) {
159
+ async getMaxFps(channel, options) {
152
160
  const data = { apiVersion: '1.0', method: 'getCaptureModes' };
153
- const res = await this.postJson(proxy, '/axis-cgi/capturemode.cgi', data);
161
+ const res = await this.postJson('/axis-cgi/capturemode.cgi', data, undefined, options);
154
162
  const response = VapixAPI_1.maxFpsResponseSchema.parse(await res.json());
155
163
  const channels = response.data;
156
164
  if (channels === undefined) {
@@ -170,9 +178,10 @@ class VapixAPI {
170
178
  }
171
179
  return captureMode.maxFPS;
172
180
  }
173
- async getTimezone(proxy = null) {
181
+ async getTimezone(options) {
174
182
  try {
175
- const resV2 = await this.client.get(proxy, '/config/rest/time/v2/timeZone');
183
+ const agent = this.getAgent(options?.proxyParams);
184
+ const resV2 = await agent.get({ path: '/config/rest/time/v2/timeZone', timeout: options?.timeout });
176
185
  if (!resV2.ok) {
177
186
  throw new Error(await (0, utils_1.responseStringify)(resV2));
178
187
  }
@@ -187,20 +196,20 @@ class VapixAPI {
187
196
  console.warn('Failed to fetch time zone data from time API v2:', error instanceof Error ? error.message : JSON.stringify(error));
188
197
  console.warn('Falling back to deprecated time API v1');
189
198
  }
190
- const data = await this.getDateTimeInfo(proxy);
199
+ const data = await this.getDateTimeInfo(options);
191
200
  if (data.data.timeZone === undefined) {
192
201
  throw new Error('Time zone not setup on the device');
193
202
  }
194
203
  return data.data.timeZone;
195
204
  }
196
- async getDateTimeInfo(proxy = null) {
205
+ async getDateTimeInfo(options) {
197
206
  const data = { apiVersion: '1.0', method: 'getDateTimeInfo' };
198
- const res = await this.postJson(proxy, '/axis-cgi/time.cgi', data);
207
+ const res = await this.postJson('/axis-cgi/time.cgi', data, undefined, options);
199
208
  return VapixAPI_1.dateTimeinfoSchema.parse(await res.json());
200
209
  }
201
- async getDevicesSettings(proxy = null) {
210
+ async getDevicesSettings(options) {
202
211
  const data = { apiVersion: '1.0', method: 'getDevicesSettings' };
203
- const res = await this.postJson(proxy, '/axis-cgi/audiodevicecontrol.cgi', data);
212
+ const res = await this.postJson('/axis-cgi/audiodevicecontrol.cgi', data, undefined, options);
204
213
  const result = VapixAPI_1.audioDeviceRequestSchema.parse(await res.json());
205
214
  return result.data.devices.map((device) => ({
206
215
  ...device,
@@ -208,44 +217,44 @@ class VapixAPI {
208
217
  outputs: (device.outputs || []).sort((a, b) => a.id.localeCompare(b.id)),
209
218
  }));
210
219
  }
211
- async fetchRemoteDeviceInfo(payload, proxy = null) {
212
- const res = await this.postJson(proxy, '/axis-cgi/basicdeviceinfo.cgi', payload);
220
+ async fetchRemoteDeviceInfo(payload, options) {
221
+ const res = await this.postJson('/axis-cgi/basicdeviceinfo.cgi', payload, undefined, options);
213
222
  const json = await res.json();
214
223
  if ((0, utils_1.isNullish)(json.data)) {
215
224
  throw new errors_1.NoDeviceInfoError();
216
225
  }
217
226
  return json.data;
218
227
  }
219
- async getHeaders(proxy = null) {
228
+ async getHeaders(options) {
220
229
  const data = { apiVersion: '1.0', method: 'list' };
221
- const res = await this.postJson(proxy, '/axis-cgi/customhttpheader.cgi', data);
230
+ const res = await this.postJson('/axis-cgi/customhttpheader.cgi', data, undefined, options);
222
231
  return zod_1.z.object({ data: zod_1.z.record(zod_1.z.string()) }).parse(await res.json()).data;
223
232
  }
224
- async setHeaders(headers, proxy = null) {
233
+ async setHeaders(headers, options) {
225
234
  const data = { apiVersion: '1.0', method: 'set', params: headers };
226
- return this.postJson(proxy, '/axis-cgi/customhttpheader.cgi', data);
235
+ return this.postJson('/axis-cgi/customhttpheader.cgi', data, undefined, options);
227
236
  }
228
- async getParameter(paramNames, proxy = null) {
229
- const response = await this.getUrlEncoded(proxy, '/axis-cgi/param.cgi', {
237
+ async getParameter(paramNames, options) {
238
+ const response = await this.postUrlEncoded('/axis-cgi/param.cgi', {
230
239
  action: 'list',
231
240
  group: (0, utils_1.arrayToUrl)(paramNames),
232
- });
233
- return parseParameters(await response.text());
241
+ }, undefined, options);
242
+ return VapixAPI.parseParameters(await response.text());
234
243
  }
235
- async setParameter(params, proxy = null) {
236
- const res = await this.getUrlEncoded(proxy, '/axis-cgi/param.cgi', {
244
+ async setParameter(params, options) {
245
+ const res = await this.postUrlEncoded('/axis-cgi/param.cgi', {
237
246
  ...params,
238
247
  action: 'update',
239
- });
248
+ }, undefined, options);
240
249
  const responseText = await res.text();
241
250
  if (responseText.startsWith('# Error')) {
242
251
  throw new Error(responseText);
243
252
  }
244
253
  return true;
245
254
  }
246
- async getGuardTourList(proxy = null) {
255
+ async getGuardTourList(options) {
247
256
  const gTourList = new Array();
248
- const response = await this.getParameter('GuardTour', proxy);
257
+ const response = await this.getParameter('GuardTour', options);
249
258
  for (let i = 0; i < 20; i++) {
250
259
  const gTourBaseName = 'root.GuardTour.G' + i;
251
260
  if (gTourBaseName + '.CamNbr' in response) {
@@ -279,16 +288,16 @@ class VapixAPI {
279
288
  }
280
289
  return gTourList;
281
290
  }
282
- setGuardTourEnabled(guardTourID, enable, proxy = null) {
283
- const options = {};
284
- options[guardTourID + '.Running'] = enable ? 'yes' : 'no';
285
- return this.setParameter(options, proxy);
291
+ setGuardTourEnabled(guardTourID, enable, options) {
292
+ const params = {};
293
+ params[guardTourID + '.Running'] = enable ? 'yes' : 'no';
294
+ return this.setParameter(params, options);
286
295
  }
287
- async getPTZPresetList(channel, proxy = null) {
288
- const res = await this.getUrlEncoded(proxy, '/axis-cgi/com/ptz.cgi', {
296
+ async getPTZPresetList(channel, options) {
297
+ const res = await this.postUrlEncoded('/axis-cgi/com/ptz.cgi', {
289
298
  query: 'presetposcam',
290
299
  camera: channel.toString(),
291
- });
300
+ }, undefined, options);
292
301
  const text = await res.text();
293
302
  const lines = text.split(/[\r\n]/);
294
303
  const positions = [];
@@ -303,29 +312,29 @@ class VapixAPI {
303
312
  }
304
313
  return positions;
305
314
  }
306
- async listPTZ(camera, proxy = null) {
315
+ async listPTZ(camera, options) {
307
316
  const url = `/axis-cgi/com/ptz.cgi`;
308
- const response = await this.getUrlEncoded(proxy, url, {
317
+ const response = await this.postUrlEncoded(url, {
309
318
  camera,
310
319
  query: 'presetposcamdata',
311
320
  format: 'json',
312
- });
321
+ }, undefined, options);
313
322
  const text = await response.text();
314
323
  if (text === '') {
315
324
  throw new errors_1.PtzNotSupportedError();
316
325
  }
317
- return parseCameraPtzResponse(text)[camera] ?? [];
326
+ return VapixAPI.parseCameraPtzResponse(text)[camera] ?? [];
318
327
  }
319
- async listPtzVideoSourceOverview(proxy = null) {
320
- const response = await this.getUrlEncoded(proxy, '/axis-cgi/com/ptz.cgi', {
328
+ async listPtzVideoSourceOverview(options) {
329
+ const response = await this.postUrlEncoded('/axis-cgi/com/ptz.cgi', {
321
330
  query: 'presetposall',
322
331
  format: 'json',
323
- });
332
+ }, undefined, options);
324
333
  const text = await response.text();
325
334
  if (text === '') {
326
335
  throw new errors_1.PtzNotSupportedError();
327
336
  }
328
- const data = parseCameraPtzResponse(text);
337
+ const data = VapixAPI.parseCameraPtzResponse(text);
329
338
  const res = {};
330
339
  Object.keys(data)
331
340
  .map(Number)
@@ -336,63 +345,52 @@ class VapixAPI {
336
345
  });
337
346
  return res;
338
347
  }
339
- goToPreset(channel, presetName, proxy = null) {
340
- return this.getUrlEncoded(proxy, '/axis-cgi/com/ptz.cgi', {
348
+ goToPreset(channel, presetName, options) {
349
+ return this.postUrlEncoded('/axis-cgi/com/ptz.cgi', {
341
350
  camera: channel.toString(),
342
351
  gotoserverpresetname: presetName,
343
- });
352
+ }, undefined, options);
344
353
  }
345
- async getPtzPosition(camera, proxy = null) {
346
- const res = await this.getUrlEncoded(proxy, '/axis-cgi/com/ptz.cgi', {
354
+ async getPtzPosition(camera, options) {
355
+ const res = await this.postUrlEncoded('/axis-cgi/com/ptz.cgi', {
347
356
  query: 'position',
348
357
  camera: camera.toString(),
349
- });
350
- const params = parseParameters(await res.text());
358
+ }, undefined, options);
359
+ const params = VapixAPI.parseParameters(await res.text());
351
360
  return {
352
361
  pan: Number(params.pan),
353
362
  tilt: Number(params.tilt),
354
363
  zoom: Number(params.zoom),
355
364
  };
356
365
  }
357
- async getPorts(proxy = null) {
358
- const body = JSON.stringify({
366
+ async getPorts(options) {
367
+ const res = await this.postJson('/axis-cgi/io/portmanagement.cgi', {
359
368
  apiVersion: '1.0',
360
369
  context: '',
361
370
  method: 'getPorts',
362
- });
363
- const res = await this.client.post(proxy, '/axis-cgi/io/portmanagement.cgi', body, {}, { 'Content-Type': 'application/json' });
364
- if (!res.ok) {
365
- throw new Error(await (0, utils_1.responseStringify)(res));
366
- }
371
+ }, undefined, options);
367
372
  const portResponseParsed = await VapixAPI_1.getPortsResponseSchema.parse(res.json());
368
373
  return portResponseParsed.data.items;
369
374
  }
370
- async setPorts(ports, proxy = null) {
371
- const body = JSON.stringify({
375
+ async setPorts(ports, options) {
376
+ await this.postJson('/axis-cgi/io/portmanagement.cgi', {
372
377
  apiVersion: '1.0',
373
378
  context: '',
374
379
  method: 'setPorts',
375
380
  params: { ports },
376
- });
377
- const res = await this.client.post(proxy, '/axis-cgi/io/portmanagement.cgi', body, {}, { 'Content-Type': 'application/json' });
378
- if (!res.ok) {
379
- throw new Error(await (0, utils_1.responseStringify)(res));
380
- }
381
+ }, undefined, options);
381
382
  }
382
- async setPortStateSequence(port, sequence, proxy = null) {
383
- const body = JSON.stringify({
383
+ async setPortStateSequence(port, sequence, options) {
384
+ await this.postJson('/axis-cgi/io/portmanagement.cgi', {
384
385
  apiVersion: '1.0',
385
386
  context: '',
386
387
  method: 'setStateSequence',
387
388
  params: { port, sequence },
388
- });
389
- const res = await this.client.post(proxy, '/axis-cgi/io/portmanagement.cgi', body, {}, { 'Content-Type': 'application/json' });
390
- if (!res.ok) {
391
- throw new Error(await (0, utils_1.responseStringify)(res));
392
- }
389
+ }, undefined, options);
393
390
  }
394
- async getApplicationList(proxy = null) {
395
- const res = await this.client.get(proxy, '/axis-cgi/applications/list.cgi');
391
+ async getApplicationList(options) {
392
+ const agent = this.getAgent(options?.proxyParams);
393
+ const res = await agent.get({ path: '/axis-cgi/applications/list.cgi', timeout: options?.timeout });
396
394
  const xml = await res.text();
397
395
  const parser = new fast_xml_parser_1.XMLParser({
398
396
  ignoreAttributes: false,
@@ -411,41 +409,62 @@ class VapixAPI {
411
409
  };
412
410
  });
413
411
  }
414
- async startApplication(applicationID, proxy = null) {
415
- const res = await this.client.get(proxy, '/axis-cgi/applications/control.cgi', {
416
- package: applicationID.toLowerCase(),
417
- action: 'start',
412
+ async startApplication(applicationID, options) {
413
+ const agent = this.getAgent(options?.proxyParams);
414
+ const res = await agent.get({
415
+ path: '/axis-cgi/applications/control.cgi',
416
+ parameters: {
417
+ package: applicationID.toLowerCase(),
418
+ action: 'start',
419
+ },
420
+ timeout: options?.timeout,
418
421
  });
419
422
  const text = (await res.text()).trim().toLowerCase();
420
423
  if (text !== 'ok' && !(text.startsWith('error:') && text.substring(7) === '6')) {
421
424
  throw new errors_1.ApplicationAPIError('START', await (0, utils_1.responseStringify)(res));
422
425
  }
423
426
  }
424
- async restartApplication(applicationID, proxy = null) {
425
- const res = await this.client.get(proxy, '/axis-cgi/applications/control.cgi', {
426
- package: applicationID.toLowerCase(),
427
- action: 'restart',
427
+ async restartApplication(applicationID, options) {
428
+ const agent = this.getAgent(options?.proxyParams);
429
+ const res = await agent.get({
430
+ path: '/axis-cgi/applications/control.cgi',
431
+ parameters: {
432
+ package: applicationID.toLowerCase(),
433
+ action: 'restart',
434
+ },
435
+ timeout: options?.timeout,
428
436
  });
429
437
  const text = (await res.text()).trim().toLowerCase();
430
438
  if (text !== 'ok') {
431
439
  throw new errors_1.ApplicationAPIError('RESTART', await (0, utils_1.responseStringify)(res));
432
440
  }
433
441
  }
434
- async stopApplication(applicationID, proxy = null) {
435
- const res = await this.client.get(proxy, '/axis-cgi/applications/control.cgi', {
436
- package: applicationID.toLowerCase(),
437
- action: 'stop',
442
+ async stopApplication(applicationID, options) {
443
+ const agent = this.getAgent(options?.proxyParams);
444
+ const res = await agent.get({
445
+ path: '/axis-cgi/applications/control.cgi',
446
+ parameters: {
447
+ package: applicationID.toLowerCase(),
448
+ action: 'stop',
449
+ },
450
+ timeout: options?.timeout,
438
451
  });
439
452
  const text = (await res.text()).trim().toLowerCase();
440
453
  if (text !== 'ok' && !(text.startsWith('error:') && text.substring(7) === '6')) {
441
454
  throw new errors_1.ApplicationAPIError('STOP', await (0, utils_1.responseStringify)(res));
442
455
  }
443
456
  }
444
- async installApplication(data, fileName) {
457
+ async installApplication(data, fileName, options) {
445
458
  const formData = new FormData();
446
459
  formData.append('packfil', data, fileName);
447
- const res = await this.client.post(null, '/axis-cgi/applications/upload.cgi', formData, {}, {
448
- contentType: 'application/octet-stream',
460
+ const agent = this.getAgent(options?.proxyParams);
461
+ const res = await agent.post({
462
+ path: '/axis-cgi/applications/upload.cgi',
463
+ data: formData,
464
+ headers: {
465
+ contentType: 'application/octet-stream',
466
+ },
467
+ timeout: options?.timeout ?? 120000,
449
468
  });
450
469
  if (!res.ok) {
451
470
  throw new Error(await (0, utils_1.responseStringify)(res));
@@ -455,71 +474,74 @@ class VapixAPI {
455
474
  throw new Error('installing error: ' + text);
456
475
  }
457
476
  }
458
- }
459
- exports.VapixAPI = VapixAPI;
460
- const parseParameters = (response) => {
461
- const params = {};
462
- const lines = response.split(/[\r\n]/);
463
- for (const line of lines) {
464
- if (line.length === 0 || line.substring(0, 7) === '# Error') {
465
- continue;
466
- }
467
- const delimiterPos = line.indexOf('=');
468
- if (delimiterPos !== -1) {
469
- const paramName = line.substring(0, delimiterPos).replace('root.', '');
470
- const paramValue = line.substring(delimiterPos + 1);
471
- params[paramName] = paramValue;
472
- }
473
- }
474
- return params;
475
- };
476
- const parseCameraPtzResponse = (response) => {
477
- const json = JSON.parse(response);
478
- const parsed = {};
479
- Object.keys(json).forEach((key) => {
480
- if (!key.startsWith('Camera ')) {
481
- return;
482
- }
483
- const camera = Number(key.replace('Camera ', ''));
484
- if (json[key].presets !== undefined) {
485
- parsed[camera] = parsePtz(json[key].presets);
486
- }
487
- });
488
- return parsed;
489
- };
490
- const parsePtz = (parsed) => {
491
- const res = [];
492
- parsed.forEach((value) => {
493
- const delimiterPos = value.indexOf('=');
494
- if (delimiterPos === -1) {
495
- return;
496
- }
497
- if (!value.startsWith('presetposno')) {
498
- return;
499
- }
500
- const id = Number(value.substring(11, delimiterPos));
501
- if (Number.isNaN(id)) {
502
- return;
477
+ static parseParameters = (response) => {
478
+ const params = {};
479
+ const lines = response.split(/[\r\n]/);
480
+ for (const line of lines) {
481
+ if (line.length === 0 || line.substring(0, 7) === '# Error') {
482
+ continue;
483
+ }
484
+ const delimiterPos = line.indexOf('=');
485
+ if (delimiterPos !== -1) {
486
+ const paramName = line.substring(0, delimiterPos).replace('root.', '');
487
+ const paramValue = line.substring(delimiterPos + 1);
488
+ params[paramName] = paramValue;
489
+ }
503
490
  }
504
- const data = value.substring(delimiterPos + 1).split(':');
505
- const getValue = (valueName) => {
506
- for (const d of data) {
507
- const p = d.split('=');
508
- if (p[0] === valueName) {
509
- return Number(p[1]);
510
- }
491
+ return params;
492
+ };
493
+ static parseCameraPtzResponse = (response) => {
494
+ const json = JSON.parse(response);
495
+ const parsed = {};
496
+ Object.keys(json).forEach((key) => {
497
+ if (!key.startsWith('Camera ')) {
498
+ return;
511
499
  }
512
- return 0;
513
- };
514
- res.push({
515
- id,
516
- name: data[0] ?? 'Preset ' + id,
517
- data: {
518
- pan: getValue('pan'),
519
- tilt: getValue('tilt'),
520
- zoom: getValue('zoom'),
521
- },
500
+ const camera = Number(key.replace('Camera ', ''));
501
+ if (json[key].presets !== undefined) {
502
+ parsed[camera] = VapixAPI.parsePtz(json[key].presets);
503
+ }
504
+ });
505
+ return parsed;
506
+ };
507
+ static parsePtz = (parsed) => {
508
+ const res = [];
509
+ parsed.forEach((value) => {
510
+ const delimiterPos = value.indexOf('=');
511
+ if (delimiterPos === -1) {
512
+ return;
513
+ }
514
+ if (!value.startsWith('presetposno')) {
515
+ return;
516
+ }
517
+ const id = Number(value.substring(11, delimiterPos));
518
+ if (Number.isNaN(id)) {
519
+ return;
520
+ }
521
+ const data = value.substring(delimiterPos + 1).split(':');
522
+ const getValue = (valueName) => {
523
+ for (const d of data) {
524
+ const p = d.split('=');
525
+ if (p[0] === valueName) {
526
+ return Number(p[1]);
527
+ }
528
+ }
529
+ return 0;
530
+ };
531
+ res.push({
532
+ id,
533
+ name: data[0] ?? 'Preset ' + id,
534
+ data: {
535
+ pan: getValue('pan'),
536
+ tilt: getValue('tilt'),
537
+ zoom: getValue('zoom'),
538
+ },
539
+ });
522
540
  });
523
- });
524
- return res;
525
- };
541
+ return res;
542
+ };
543
+ getAgent(proxyParams) {
544
+ return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
545
+ }
546
+ }
547
+ exports.VapixAPI = VapixAPI;
@@ -1,10 +1,10 @@
1
- import { IClient, HttpOptions } from '../internal/types';
2
- import { Response } from 'undici';
3
- export type AcsEventsOptions = HttpOptions;
1
+ import { HttpOptions } from '../internal/types';
2
+ import { THttpRequestOptions } from '../types/common';
4
3
  export declare class AxisCameraStationEvents {
5
4
  private sourceKey;
6
5
  private client;
7
- constructor(sourceKey: string, opt?: AcsEventsOptions | IClient<Response>);
8
- sendEvent(data: Record<string, string>, eventType: string): Promise<void>;
6
+ constructor(clientOptions: HttpOptions, sourceKey: string);
7
+ sendEvent(data: Record<string, string>, eventType: string, options?: THttpRequestOptions): Promise<void>;
9
8
  private getDate;
9
+ private getAgent;
10
10
  }