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