camstreamerlib 4.0.0-beta.36 → 4.0.0-beta.38

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 (101) hide show
  1. package/cjs/CamOverlayAPI.js +52 -79
  2. package/cjs/CamScripterAPI.js +30 -24
  3. package/cjs/CamStreamerAPI.js +30 -33
  4. package/cjs/CamSwitcherAPI.js +57 -52
  5. package/cjs/PlaneTrackerAPI.js +55 -66
  6. package/cjs/VapixAPI.js +23 -22
  7. package/cjs/{CamOverlayDrawingAPI.js → node/CamOverlayDrawingAPI.js} +1 -1
  8. package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/Painter.js +4 -14
  9. package/cjs/{CamScripterAPICameraEventsGenerator.js → node/CamScripterAPICameraEventsGenerator.js} +1 -1
  10. package/cjs/{VapixEvents.js → node/VapixEvents.js} +1 -1
  11. package/cjs/node/events/GenetecAgent.js +5 -27
  12. package/cjs/node/index.js +17 -0
  13. package/cjs/types/CamOverlayAPI/CamOverlayAPI.js +18 -18
  14. package/cjs/types/CamOverlayAPI/accuweatherSchema.js +7 -7
  15. package/cjs/types/CamOverlayAPI/customGraphicsSchema.js +5 -5
  16. package/cjs/types/CamOverlayAPI/imagesSchema.js +4 -4
  17. package/cjs/types/CamOverlayAPI/index.js +1 -1
  18. package/cjs/types/CamOverlayAPI/infotickerSchema.js +6 -6
  19. package/cjs/types/CamOverlayAPI/pipSchema.js +4 -4
  20. package/cjs/types/CamOverlayAPI/ptzCompassSchema.js +4 -4
  21. package/cjs/types/CamOverlayAPI/ptzSchema.js +4 -4
  22. package/cjs/types/CamOverlayAPI/scoreBoardSchema.js +8 -8
  23. package/cjs/types/CamOverlayAPI/screenSharingSchema.js +3 -3
  24. package/cjs/types/CamOverlayAPI/{widgetCommonTypes.js → serviceCommonTypes.js} +8 -4
  25. package/cjs/types/CamOverlayAPI/webCameraSharingSchema.js +3 -3
  26. package/cjs/types/CamOverlayPainter.js +12 -0
  27. package/cjs/types/CamScripterAPICameraEventsGenerator.js +2 -0
  28. package/cjs/types/CamSwitcherAPI.js +38 -1
  29. package/cjs/types/GenetecAgent.js +31 -0
  30. package/cjs/types/PlaneTrackerAPI.js +277 -0
  31. package/cjs/types/VapixAPI.js +20 -2
  32. package/cjs/types/VapixEvents.js +2 -0
  33. package/esm/CamOverlayAPI.js +53 -80
  34. package/esm/CamScripterAPI.js +30 -24
  35. package/esm/CamStreamerAPI.js +30 -30
  36. package/esm/CamSwitcherAPI.js +58 -53
  37. package/esm/PlaneTrackerAPI.js +56 -67
  38. package/esm/VapixAPI.js +24 -23
  39. package/esm/{CamOverlayDrawingAPI.js → node/CamOverlayDrawingAPI.js} +1 -1
  40. package/esm/{CamOverlayPainter → node/CamOverlayPainter}/Painter.js +1 -11
  41. package/esm/{CamScripterAPICameraEventsGenerator.js → node/CamScripterAPICameraEventsGenerator.js} +1 -1
  42. package/esm/{VapixEvents.js → node/VapixEvents.js} +1 -1
  43. package/esm/node/events/GenetecAgent.js +1 -23
  44. package/esm/node/index.js +10 -0
  45. package/esm/types/CamOverlayAPI/CamOverlayAPI.js +17 -17
  46. package/esm/types/CamOverlayAPI/accuweatherSchema.js +3 -3
  47. package/esm/types/CamOverlayAPI/customGraphicsSchema.js +3 -3
  48. package/esm/types/CamOverlayAPI/imagesSchema.js +3 -3
  49. package/esm/types/CamOverlayAPI/index.js +1 -1
  50. package/esm/types/CamOverlayAPI/infotickerSchema.js +3 -3
  51. package/esm/types/CamOverlayAPI/pipSchema.js +3 -3
  52. package/esm/types/CamOverlayAPI/ptzCompassSchema.js +3 -3
  53. package/esm/types/CamOverlayAPI/ptzSchema.js +3 -3
  54. package/esm/types/CamOverlayAPI/scoreBoardSchema.js +5 -5
  55. package/esm/types/CamOverlayAPI/screenSharingSchema.js +2 -2
  56. package/esm/types/CamOverlayAPI/{widgetCommonTypes.js → serviceCommonTypes.js} +7 -3
  57. package/esm/types/CamOverlayAPI/webCameraSharingSchema.js +2 -2
  58. package/esm/types/CamOverlayPainter.js +11 -1
  59. package/esm/types/CamSwitcherAPI.js +38 -1
  60. package/esm/types/GenetecAgent.js +28 -0
  61. package/esm/types/PlaneTrackerAPI.js +276 -1
  62. package/esm/types/VapixAPI.js +19 -1
  63. package/esm/types/VapixEvents.js +1 -0
  64. package/package.json +1 -1
  65. package/types/CamOverlayAPI.d.ts +836 -10
  66. package/types/CamScripterAPI.d.ts +34 -9
  67. package/types/CamStreamerAPI.d.ts +27 -5
  68. package/types/CamSwitcherAPI.d.ts +136 -23
  69. package/types/PlaneTrackerAPI.d.ts +201 -20
  70. package/types/VapixAPI.d.ts +46 -12
  71. package/types/bin/CreatePackage.d.ts +1 -0
  72. package/types/{CamOverlayDrawingAPI.d.ts → node/CamOverlayDrawingAPI.d.ts} +1 -1
  73. package/types/{CamOverlayPainter → node/CamOverlayPainter}/Frame.d.ts +2 -2
  74. package/types/{CamOverlayPainter → node/CamOverlayPainter}/Painter.d.ts +2 -13
  75. package/types/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.d.ts +1 -1
  76. package/types/node/CamScripterAPICameraEventsGenerator.d.ts +31 -0
  77. package/types/node/VapixEvents.d.ts +16 -0
  78. package/types/node/events/GenetecAgent.d.ts +1 -144
  79. package/types/node/index.d.ts +10 -0
  80. package/types/types/CamOverlayAPI/CamOverlayAPI.d.ts +20 -20
  81. package/types/types/CamOverlayAPI/index.d.ts +1 -1
  82. package/types/types/CamOverlayAPI/{widgetCommonTypes.d.ts → serviceCommonTypes.d.ts} +6 -2
  83. package/types/types/CamOverlayDrawingAPI.d.ts +3 -13
  84. package/types/types/CamOverlayPainter.d.ts +12 -10
  85. package/types/types/CamScripterAPICameraEventsGenerator.d.ts +45 -0
  86. package/types/types/CamStreamerAPI.d.ts +2 -2
  87. package/types/types/CamSwitcherAPI.d.ts +111 -30
  88. package/types/types/GenetecAgent.d.ts +174 -0
  89. package/types/types/PlaneTrackerAPI.d.ts +859 -0
  90. package/types/types/VapixAPI.d.ts +54 -8
  91. package/types/types/VapixEvents.d.ts +15 -0
  92. package/types/types/common.d.ts +1 -0
  93. package/types/CamScripterAPICameraEventsGenerator.d.ts +0 -74
  94. package/types/VapixEvents.d.ts +0 -43
  95. /package/cjs/{CreatePackage.js → bin/CreatePackage.js} +0 -0
  96. /package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/Frame.js +0 -0
  97. /package/cjs/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.js +0 -0
  98. /package/esm/{CreatePackage.js → bin/CreatePackage.js} +0 -0
  99. /package/esm/{CamOverlayPainter → node/CamOverlayPainter}/Frame.js +0 -0
  100. /package/esm/{CamOverlayPainter → node/CamOverlayPainter}/ResourceManager.js +0 -0
  101. /package/{types/CreatePackage.d.ts → esm/types/CamScripterAPICameraEventsGenerator.js} +0 -0
@@ -20,68 +20,51 @@ class CamOverlayAPI {
20
20
  return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
21
21
  }
22
22
  async checkCameraTime(options) {
23
- const response = await this._get({ path: `${BASE_PATH}/camera_time.cgi` }, options);
24
- return zod_1.z.boolean().parse(response.state);
23
+ const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
24
+ return zod_1.z.boolean().parse(res.state);
25
25
  }
26
26
  async getNetworkCameraList(options) {
27
- const response = await this._get({ path: `${BASE_PATH}/network_camera_list.cgi` }, options);
28
- return common_1.networkCameraListSchema.parse(response.camera_list);
27
+ const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
28
+ return common_1.networkCameraListSchema.parse(res.camera_list);
29
29
  }
30
30
  async wsAuthorization(options) {
31
- const response = await this._get({ path: `${BASE_PATH}/ws_authorization.cgi` }, options);
32
- return CamOverlayAPI_1.WSResponseSchema.parse(response).message;
31
+ const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
32
+ return CamOverlayAPI_1.wsResponseSchema.parse(res).message;
33
33
  }
34
34
  async getMjpegStreamImage(mjpegUrl, options) {
35
- return await this._getBlob({
36
- path: `${BASE_PATH}/fetch_mjpeg_image.cgi?mjpeg_url=${encodeURIComponent(decodeURIComponent(mjpegUrl))}`,
37
- }, options);
35
+ return await this._getBlob(`${BASE_PATH}/fetch_mjpeg_image.cgi`, { mjpeg_url: decodeURIComponent(mjpegUrl) }, options);
38
36
  }
39
37
  async listFiles(fileType, options) {
40
- const files = await this._get({
41
- path: `${BASE_PATH}/upload_${fileType}.cgi`,
42
- parameters: {
43
- action: 'list',
44
- },
45
- }, options);
46
- return CamOverlayAPI_1.fileListSchema.parse(files.list);
38
+ const res = await this._getJson(`${BASE_PATH}/upload_${fileType}.cgi`, { action: 'list' }, options);
39
+ return CamOverlayAPI_1.fileListSchema.parse(res.list);
47
40
  }
48
41
  async uploadFile(fileType, formData, storage, options) {
49
- await this._post({
50
- path: `${BASE_PATH}/upload_${fileType}.cgi`,
51
- data: formData,
52
- parameters: {
53
- action: 'upload',
54
- storage: storage,
55
- },
42
+ await this._post(`${BASE_PATH}/upload_${fileType}.cgi`, formData, {
43
+ action: 'upload',
44
+ storage: storage,
56
45
  }, options);
57
46
  }
58
47
  async removeFile(fileType, fileParams, options) {
59
- const path = `${BASE_PATH}/upload_${fileType}.cgi`;
60
- await this._postUrlEncoded(path, {
48
+ await this._postUrlEncoded(`${BASE_PATH}/upload_${fileType}.cgi`, {
61
49
  action: 'remove',
62
50
  ...fileParams,
63
- }, undefined, options);
51
+ }, options, undefined);
64
52
  }
65
53
  async getFileStorage(fileType, options) {
66
- const data = await this._get({
67
- path: `${BASE_PATH}/upload_${fileType}.cgi`,
68
- parameters: {
69
- action: 'get_storage',
70
- },
71
- }, options);
72
- if (data.code !== 200) {
54
+ const res = await this._getJson(`${BASE_PATH}/upload_${fileType}.cgi`, { action: 'get_storage' }, options);
55
+ if (res.code !== 200) {
73
56
  throw new Error('Error occured while fetching file storage data');
74
57
  }
75
- return CamOverlayAPI_1.storageDataListSchema.parse(data.list);
58
+ return CamOverlayAPI_1.storageDataListSchema.parse(res.list);
76
59
  }
77
60
  async getFilePreviewFromCamera(path, options) {
78
- return await this._getBlob({ path: CamOverlayAPI.getFilePreviewPath(path) }, options);
61
+ return await this._getBlob(CamOverlayAPI.getFilePreviewPath(path), undefined, options);
79
62
  }
80
63
  async updateInfoticker(serviceId, text, options) {
81
- await this._get({ path: `${BASE_PATH}/infoticker.cgi?service_id=${serviceId}&text=${text}` }, options);
64
+ await this._getJson(`${BASE_PATH}/infoticker.cgi`, { service_id: serviceId, text: text }, options);
82
65
  }
83
66
  async setEnabled(serviceId, enabled, options) {
84
- await this._post({ path: `${BASE_PATH}/enabled.cgi?id_${serviceId}=${enabled ? 1 : 0}`, data: '' }, options);
67
+ await this._post(`${BASE_PATH}/enabled.cgi`, '', { [`id_${serviceId}`]: enabled ? 1 : 0 }, options);
85
68
  }
86
69
  async isEnabled(serviceId, options) {
87
70
  const agent = this.getClient(options?.proxyParams);
@@ -99,44 +82,34 @@ class CamOverlayAPI {
99
82
  throw new Error(await (0, utils_1.responseStringify)(res));
100
83
  }
101
84
  }
102
- async getSingleWidget(serviceId, options) {
103
- const data = await this._get({
104
- path: `${BASE_PATH}/services.cgi`,
105
- parameters: {
106
- action: 'get',
107
- service_id: serviceId.toString(),
108
- },
109
- }, options);
110
- return CamOverlayAPI_1.widgetsSchema.parse(data);
111
- }
112
- async getWidgets(options) {
113
- const widgetList = await this._get({
114
- path: `${BASE_PATH}/services.cgi`,
115
- parameters: {
116
- action: 'get',
117
- },
85
+ async getSingleService(serviceId, options) {
86
+ const res = await this._getJson(`${BASE_PATH}/services.cgi`, {
87
+ action: 'get',
88
+ service_id: serviceId,
118
89
  }, options);
119
- const widgets = widgetList.services;
120
- widgets.forEach((widget) => {
121
- const parsedWidget = CamOverlayAPI_1.widgetsSchema.safeParse(widget);
122
- if (!parsedWidget.success) {
123
- console.warn(`[SERVICE SCHEMA MISMATCH]: Service ${widget.name} (${widget.id}) does not match the current schema, or is a hidden service.`);
90
+ return CamOverlayAPI_1.servicesSchema.parse(res);
91
+ }
92
+ async getServices(options) {
93
+ const res = await this._getJson(`${BASE_PATH}/services.cgi`, { action: 'get' }, options);
94
+ const services = CamOverlayAPI_1.serviceListSchema.parse(res).services;
95
+ services.forEach((service) => {
96
+ const parsedService = CamOverlayAPI_1.servicesSchema.safeParse(service);
97
+ if (!parsedService.success) {
98
+ console.warn(`[SERVICE SCHEMA MISMATCH]: Service ${service.name} (${service.id}) does not match the current schema, or is a hidden service.`);
124
99
  }
125
100
  });
126
- return widgets;
101
+ return services;
127
102
  }
128
- async updateSingleWidget(widget, options) {
129
- const path = `${BASE_PATH}/services.cgi`;
130
- await this._postJsonEncoded(path, JSON.stringify(widget), {
103
+ async updateSingleService(service, options) {
104
+ await this._postJsonEncoded(`${BASE_PATH}/services.cgi`, JSON.stringify(service), {
131
105
  action: 'set',
132
- service_id: widget.id.toString(),
133
- }, undefined, options);
106
+ service_id: service.id,
107
+ }, options, undefined);
134
108
  }
135
- async updateWidgets(widgets, options) {
136
- const path = `${BASE_PATH}/services.cgi`;
137
- await this._postJsonEncoded(path, JSON.stringify({ services: widgets }), {
109
+ async updateServices(services, options) {
110
+ await this._postJsonEncoded(`${BASE_PATH}/services.cgi`, JSON.stringify({ services: services }), {
138
111
  action: 'set',
139
- }, undefined, options);
112
+ }, options, undefined);
140
113
  }
141
114
  updateCGText(serviceId, fields, options) {
142
115
  const params = {};
@@ -197,9 +170,9 @@ class CamOverlayAPI {
197
170
  throw new Error(await (0, utils_1.responseStringify)(res));
198
171
  }
199
172
  }
200
- async _get(params, options) {
173
+ async _getJson(path, parameters, options) {
201
174
  const agent = this.getClient(options?.proxyParams);
202
- const res = await agent.get({ ...params, timeout: options?.timeout });
175
+ const res = await agent.get({ path, parameters, timeout: options?.timeout });
203
176
  if (res.ok) {
204
177
  return await res.json();
205
178
  }
@@ -207,9 +180,9 @@ class CamOverlayAPI {
207
180
  throw new Error(await (0, utils_1.responseStringify)(res));
208
181
  }
209
182
  }
210
- async _post(params, options) {
183
+ async _post(path, data, parameters, options, headers) {
211
184
  const agent = this.getClient(options?.proxyParams);
212
- const res = await agent.post({ ...params, timeout: options?.timeout });
185
+ const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
213
186
  if (res.ok) {
214
187
  return await res.json();
215
188
  }
@@ -217,9 +190,9 @@ class CamOverlayAPI {
217
190
  throw new Error(await (0, utils_1.responseStringify)(res));
218
191
  }
219
192
  }
220
- async _getBlob(params, options) {
193
+ async _getBlob(path, parameters, options) {
221
194
  const agent = this.getClient(options?.proxyParams);
222
- const res = await agent.get({ ...params, timeout: options?.timeout });
195
+ const res = await agent.get({ path, parameters, timeout: options?.timeout });
223
196
  if (res.ok) {
224
197
  return await this.parseBlobResponse(res);
225
198
  }
@@ -235,14 +208,14 @@ class CamOverlayAPI {
235
208
  throw new errors_1.ParsingBlobError(err);
236
209
  }
237
210
  }
238
- async _postUrlEncoded(path, params, headers, options) {
239
- const data = (0, utils_1.paramToUrl)(params);
211
+ async _postUrlEncoded(path, parameters, options, headers) {
212
+ const data = (0, utils_1.paramToUrl)(parameters);
240
213
  const baseHeaders = { 'Content-Type': 'application/x-www-form-urlencoded' };
241
- return this._post({ path, data, headers: { ...baseHeaders, ...headers } }, options);
214
+ return this._post(path, data, undefined, options, { ...baseHeaders, ...headers });
242
215
  }
243
- async _postJsonEncoded(path, data, parameters, headers, options) {
216
+ async _postJsonEncoded(path, data, parameters, options, headers) {
244
217
  const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
245
- return this._post({ path, data, parameters, headers: { ...baseHeaders, ...headers } }, options);
218
+ return this._post(path, data, parameters, options, { ...baseHeaders, ...headers });
246
219
  }
247
220
  }
248
221
  exports.CamOverlayAPI = CamOverlayAPI;
@@ -11,51 +11,57 @@ class CamScripterAPI {
11
11
  constructor(client) {
12
12
  this.client = client;
13
13
  }
14
- static getProxyUrlPath = () => `${BASE_PATH}/proxy.cgi`;
14
+ static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
15
15
  getClient(proxyParams) {
16
16
  return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
17
17
  }
18
18
  async checkCameraTime(options) {
19
- const data = await this.get(`${BASE_PATH}/camera_time.cgi`, undefined, options);
20
- return CamScripterAPI_1.cameraTimeResponseSchema.parse(data).state;
19
+ const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
20
+ return CamScripterAPI_1.cameraTimeResponseSchema.parse(res).state;
21
21
  }
22
22
  async getNetworkCameraList(options) {
23
- const data = await this.get(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
24
- return common_1.networkCameraListSchema.parse(data.camera_list);
23
+ const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
24
+ return common_1.networkCameraListSchema.parse(res.camera_list);
25
25
  }
26
26
  async getStorageInfo(options) {
27
- const data = await this.get(`${BASE_PATH}/package/get_storage.cgi`, undefined, options);
28
- return CamScripterAPI_1.storageSchema.parse(data);
27
+ const res = await this._getJson(`${BASE_PATH}/package/get_storage.cgi`, undefined, options);
28
+ return CamScripterAPI_1.storageSchema.parse(res);
29
29
  }
30
30
  async getPackageList(options) {
31
- const data = await this.get(`${BASE_PATH}/package/list.cgi`, undefined, options);
32
- return CamScripterAPI_1.packageInfoListSchema.parse(data);
31
+ const res = await this._getJson(`${BASE_PATH}/package/list.cgi`, undefined, options);
32
+ return CamScripterAPI_1.packageInfoListSchema.parse(res);
33
33
  }
34
34
  async installPackages(formData, storage, options) {
35
- const data = await this.post(`${BASE_PATH}/package/install.cgi?storage=${storage}`, formData, undefined, options);
36
- return CamScripterAPI_1.camscripterApiResponseSchema.parse(data);
35
+ const res = await this._post(`${BASE_PATH}/package/install.cgi`, formData, { storage: storage }, options);
36
+ return CamScripterAPI_1.camscripterApiResponseSchema.parse(res);
37
37
  }
38
38
  async uninstallPackage(packageId, options) {
39
- const data = await this.get(`${BASE_PATH}/package/remove.cgi?package_name=${packageId}`, undefined, options);
40
- return CamScripterAPI_1.camscripterApiResponseSchema.parse(data);
39
+ const res = await this._getJson(`${BASE_PATH}/package/remove.cgi`, { package_name: packageId }, options);
40
+ return CamScripterAPI_1.camscripterApiResponseSchema.parse(res);
41
41
  }
42
42
  async importSettings(packageId, formData, options) {
43
- const data = await this.post(`${BASE_PATH}/package/data.cgi?action=IMPORT&package_name=${packageId}`, formData, undefined, options);
44
- return CamScripterAPI_1.camscripterApiResponseSchema.parse(data);
43
+ const res = await this._post(`${BASE_PATH}/package/data.cgi`, formData, {
44
+ action: 'IMPORT',
45
+ package_name: packageId,
46
+ }, options);
47
+ return CamScripterAPI_1.camscripterApiResponseSchema.parse(res);
45
48
  }
46
49
  async exportSettings(packageId, formData, options) {
47
- const data = await this.post(`${BASE_PATH}/package/data.cgi?action=EXPORT&package_name=${packageId}`, formData, undefined, options);
48
- return CamScripterAPI_1.camscripterApiResponseSchema.parse(data);
50
+ const res = await this._post(`${BASE_PATH}/package/data.cgi`, formData, {
51
+ action: 'EXPORT',
52
+ package_name: packageId,
53
+ }, options);
54
+ return CamScripterAPI_1.camscripterApiResponseSchema.parse(res);
49
55
  }
50
56
  async getNodejsStatus(options) {
51
- const data = await this.get(`${BASE_PATH}/diagnostics.cgi`, undefined, options);
52
- return CamScripterAPI_1.nodeStateSchema.parse(data);
57
+ const res = await this._getJson(`${BASE_PATH}/diagnostics.cgi`, undefined, options);
58
+ return CamScripterAPI_1.nodeStateSchema.parse(res);
53
59
  }
54
60
  async installNodejs(storage, options) {
55
- const data = await this.get(`${BASE_PATH}/node_update.cgi?storage=${storage}`, undefined, options);
56
- return CamScripterAPI_1.camscripterApiResponseSchema.parse(data);
61
+ const res = await this._getJson(`${BASE_PATH}/node_update.cgi`, { storage: storage }, options);
62
+ return CamScripterAPI_1.camscripterApiResponseSchema.parse(res);
57
63
  }
58
- async get(path, parameters, options) {
64
+ async _getJson(path, parameters, options) {
59
65
  const agent = this.getClient(options?.proxyParams);
60
66
  const res = await agent.get({ path, parameters, timeout: options?.timeout });
61
67
  if (res.ok) {
@@ -65,9 +71,9 @@ class CamScripterAPI {
65
71
  throw new Error(await (0, utils_1.responseStringify)(res));
66
72
  }
67
73
  }
68
- async post(path, data, parameters, options) {
74
+ async _post(path, data, parameters, options, headers) {
69
75
  const agent = this.getClient(options?.proxyParams);
70
- const res = await agent.post({ path, data, parameters, timeout: options?.timeout });
76
+ const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout });
71
77
  if (res.ok) {
72
78
  return await res.json();
73
79
  }
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.parseCameraStreamResponse = exports.CamStreamerAPI = void 0;
7
- const zod_1 = __importDefault(require("zod"));
4
+ const zod_1 = require("zod");
8
5
  const ProxyClient_1 = require("./internal/ProxyClient");
9
6
  const utils_1 = require("./internal/utils");
10
7
  const CamStreamerAPI_1 = require("./types/CamStreamerAPI");
@@ -17,28 +14,42 @@ class CamStreamerAPI {
17
14
  getClient(proxyParams) {
18
15
  return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
19
16
  }
17
+ async wsAuthorization(options) {
18
+ const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
19
+ if (res.status !== 200) {
20
+ throw new Error(`Server error on ws authorization: ${res.message}`);
21
+ }
22
+ return zod_1.z.string().parse(res.data);
23
+ }
24
+ async getUtcTime(options) {
25
+ const res = await this._getJson(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
26
+ if (res.status !== 200) {
27
+ throw new Error(`Server error on get UTC time: ${res.message}`);
28
+ }
29
+ return zod_1.z.number().parse(res.data);
30
+ }
20
31
  async getStreamList(options) {
21
- const streamListRes = await this.get(`${BASE_PATH}/stream/list.cgi`, undefined, options);
22
- const list = zod_1.default.record(zod_1.default.string(), CamStreamerAPI_1.cameraStreamSchema).parse(streamListRes.data);
23
- const res = {};
32
+ const res = await this._getJson(`${BASE_PATH}/stream/list.cgi`, undefined, options);
33
+ const list = zod_1.z.record(zod_1.z.string(), CamStreamerAPI_1.cameraStreamSchema).parse(res.data);
34
+ const streamList = {};
24
35
  for (const [key, data] of Object.entries(list)) {
25
36
  const streamId = parseInt(key);
26
- res[streamId] = (0, exports.parseCameraStreamResponse)(data);
37
+ streamList[streamId] = (0, exports.parseCameraStreamResponse)(data);
27
38
  }
28
- return res;
39
+ return streamList;
29
40
  }
30
41
  async getStream(streamId, options) {
31
- const stream = await this.get(`${BASE_PATH}/stream/get.cgi?stream_id=${streamId}`, undefined, options);
32
- const cameraData = CamStreamerAPI_1.cameraStreamSchema.parse(stream.data);
42
+ const res = await this._getJson(`${BASE_PATH}/stream/get.cgi`, { stream_id: streamId }, options);
43
+ const cameraData = CamStreamerAPI_1.cameraStreamSchema.parse(res.data);
33
44
  return (0, exports.parseCameraStreamResponse)(cameraData);
34
45
  }
35
46
  async getStreamParameter(streamId, paramName, options) {
36
- const stream = await this.get(`${BASE_PATH}/stream/get.cgi?stream_id=${streamId}`, undefined, options);
37
- return stream.data[paramName];
47
+ const res = await this._getJson(`${BASE_PATH}/stream/get.cgi`, { stream_id: streamId }, options);
48
+ return zod_1.z.string().parse(res.data[paramName]);
38
49
  }
39
50
  async setStream(streamId, params, options) {
40
51
  const { streamDelay, startTime, stopTime, ...rest } = params;
41
- return await this.get(`${BASE_PATH}/stream/set.cgi`, {
52
+ return await this._getJson(`${BASE_PATH}/stream/set.cgi`, {
42
53
  stream_id: streamId,
43
54
  streamDelay: streamDelay ?? '',
44
55
  startTime: startTime ?? null,
@@ -47,31 +58,17 @@ class CamStreamerAPI {
47
58
  }, options);
48
59
  }
49
60
  async setStreamParameter(streamId, paramName, value, options) {
50
- return await this.get(`${BASE_PATH}/stream/set.cgi?stream_id=${streamId}&${paramName}=${value}`, undefined, options);
61
+ return await this._getJson(`${BASE_PATH}/stream/set.cgi`, { stream_id: streamId, [paramName]: value }, options);
51
62
  }
52
63
  async isStreaming(streamId, options) {
53
- const response = await this.get(`${BASE_PATH}/get_streamstat.cgi?stream_id=${streamId}`, undefined, options);
54
- return response.data.is_streaming === 1;
64
+ const res = await this._getJson(`${BASE_PATH}/get_streamstat.cgi`, { stream_id: streamId }, options);
65
+ return res.data.is_streaming === 1;
55
66
  }
56
67
  async deleteStream(streamId, options) {
57
- const res = await this.get(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
68
+ const res = await this._getJson(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
58
69
  return res.data.status === 200;
59
70
  }
60
- async getWsAuthorization(options) {
61
- const res = await this.get(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
62
- if (res.status !== 200) {
63
- throw new Error(`Server error on ws authorization: ${res.message}`);
64
- }
65
- return res.data;
66
- }
67
- async getUtcTime(options) {
68
- const res = await this.get(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
69
- if (res.status !== 200) {
70
- throw new Error(`Server error on get UTC time: ${res.message}`);
71
- }
72
- return res.data;
73
- }
74
- async get(path, parameters, options) {
71
+ async _getJson(path, parameters, options) {
75
72
  const agent = this.getClient(options?.proxyParams);
76
73
  const res = await agent.get({ path, parameters, timeout: options?.timeout });
77
74
  if (res.ok) {
@@ -20,9 +20,9 @@ class CamSwitcherAPI {
20
20
  this.CustomFormData = CustomFormData;
21
21
  this.vapixAgent = new VapixAPI_1.VapixAPI(client);
22
22
  }
23
- static getProxyUrlPath = () => `${BASE_PATH}/proxy.cgi`;
24
- static getWsEventsUrlPath = () => `/local/camswitcher/events`;
25
- static getClipPreviewUrlPath = (id, storage) => `${BASE_PATH}/clip_preview.cgi?clip_name=${id}&storage=${storage}`;
23
+ static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
24
+ static getWsEventsPath = () => `/local/camswitcher/events`;
25
+ static getClipPreviewPath = (id, storage) => `${BASE_PATH}/clip_preview.cgi?clip_name=${id}&storage=${storage}`;
26
26
  getClient(proxyParams) {
27
27
  return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
28
28
  }
@@ -38,98 +38,105 @@ class CamSwitcherAPI {
38
38
  });
39
39
  }
40
40
  async checkCameraTime(options) {
41
- const data = await this.get(`${BASE_PATH}/camera_time.cgi`, undefined, options);
42
- return zod_1.z.boolean().parse(data);
41
+ const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
42
+ return zod_1.z.boolean().parse(res.data);
43
43
  }
44
44
  async getNetworkCameraList(options) {
45
- const data = await this.get(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
46
- return common_1.networkCameraListSchema.parse(data);
45
+ const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
46
+ return common_1.networkCameraListSchema.parse(res.data);
47
47
  }
48
48
  async getMaxFps(source, options) {
49
- const data = await this.get(`${BASE_PATH}/get_max_framerate.cgi`, {
50
- video_source: source.toString(),
49
+ const res = await this._getJson(`${BASE_PATH}/get_max_framerate.cgi`, {
50
+ video_source: source,
51
51
  }, options);
52
- return zod_1.z.number().parse(data);
52
+ return zod_1.z.number().parse(res.data);
53
53
  }
54
54
  async getStorageInfo(options) {
55
- const data = await this.get(`${BASE_PATH}/get_storage.cgi`, undefined, options);
56
- return CamSwitcherAPI_1.storageInfoListSchema.parse(data);
55
+ const res = await this._getJson(`${BASE_PATH}/get_storage.cgi`, undefined, options);
56
+ return CamSwitcherAPI_1.storageInfoListSchema.parse(res.data);
57
57
  }
58
58
  async wsAuthorization(options) {
59
- const data = await this.get(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
60
- return zod_1.z.string().parse(data);
59
+ const res = await this._getJson(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
60
+ return zod_1.z.string().parse(res.data);
61
61
  }
62
62
  async getOutputInfo(options) {
63
- const data = await this.get(`${BASE_PATH}/output_info.cgi`, undefined, options);
64
- return CamSwitcherAPI_1.outputInfoSchema.parse(data);
63
+ const res = await this._getJson(`${BASE_PATH}/output_info.cgi`, undefined, options);
64
+ return CamSwitcherAPI_1.outputInfoSchema.parse(res.data);
65
65
  }
66
66
  async getAudioPushInfo(options) {
67
- const data = await this.get(`${BASE_PATH}/audio_push_info.cgi`, undefined, options);
68
- return CamSwitcherAPI_1.audioPushInfoSchema.parse(data);
67
+ const res = await this._getJson(`${BASE_PATH}/audio_push_info.cgi`, undefined, options);
68
+ return CamSwitcherAPI_1.audioPushInfoSchema.parse(res.data);
69
69
  }
70
70
  async getStreamSaveList(options) {
71
- const data = await this.get(`${BASE_PATH}/streams.cgi`, { action: 'get' }, options);
72
- return CamSwitcherAPI_1.streamSaveLoadSchema.parse(data);
71
+ const res = await this._getJson(`${BASE_PATH}/streams.cgi`, { action: 'get' }, options);
72
+ return CamSwitcherAPI_1.streamSaveLoadSchema.parse(res.data);
73
73
  }
74
74
  async getClipSaveList(options) {
75
- const data = await this.get(`${BASE_PATH}/clips.cgi`, { action: 'get' }, options);
76
- return CamSwitcherAPI_1.clipSaveLoadSchema.parse(data);
75
+ const res = await this._getJson(`${BASE_PATH}/clips.cgi`, { action: 'get' }, options);
76
+ return CamSwitcherAPI_1.clipSaveLoadSchema.parse(res.data);
77
77
  }
78
78
  async getPlaylistSaveList(options) {
79
- const data = await this.get(`${BASE_PATH}/playlists.cgi`, { action: 'get' }, options);
80
- return CamSwitcherAPI_1.playlistSaveLoadSchema.parse(data);
79
+ const res = await this._getJson(`${BASE_PATH}/playlists.cgi`, { action: 'get' }, options);
80
+ return CamSwitcherAPI_1.playlistSaveLoadSchema.parse(res.data);
81
81
  }
82
82
  async getTrackerSaveList(options) {
83
- const data = await this.get(`${BASE_PATH}/trackers.cgi`, { action: 'get' }, options);
84
- return CamSwitcherAPI_1.trackerSaveLoadSchema.parse(data);
83
+ const res = await this._getJson(`${BASE_PATH}/trackers.cgi`, { action: 'get' }, options);
84
+ return CamSwitcherAPI_1.trackerSaveLoadSchema.parse(res.data);
85
85
  }
86
86
  async setStreamSaveList(data, options) {
87
- return await this.set(`${BASE_PATH}/streams.cgi`, data, { action: 'set' }, options);
87
+ return await this._post(`${BASE_PATH}/streams.cgi`, data, { action: 'set' }, options);
88
88
  }
89
89
  async setClipSaveList(data, options) {
90
- return await this.set(`${BASE_PATH}/clips.cgi`, data, { action: 'set' }, options);
90
+ return await this._post(`${BASE_PATH}/clips.cgi`, data, { action: 'set' }, options);
91
91
  }
92
92
  async setPlaylistSaveList(data, options) {
93
- return await this.set(`${BASE_PATH}/playlists.cgi`, data, { action: 'set' }, options);
93
+ return await this._post(`${BASE_PATH}/playlists.cgi`, data, { action: 'set' }, options);
94
94
  }
95
95
  async setTrackerSaveList(data, options) {
96
- return await this.set(`${BASE_PATH}/trackers.cgi`, data, { action: 'set' }, options);
96
+ return await this._post(`${BASE_PATH}/trackers.cgi`, data, { action: 'set' }, options);
97
97
  }
98
98
  async playlistSwitch(playlistName, options) {
99
- await this.get(`${BASE_PATH}/playlist_switch.cgi`, { playlist_name: playlistName }, options);
99
+ await this._getJson(`${BASE_PATH}/playlist_switch.cgi`, { playlist_name: playlistName }, options);
100
100
  }
101
101
  async playlistQueuePush(playlistName, options) {
102
- await this.get(`${BASE_PATH}/playlist_queue_push.cgi`, { playlist_name: playlistName }, options);
102
+ await this._getJson(`${BASE_PATH}/playlist_queue_push.cgi`, { playlist_name: playlistName }, options);
103
103
  }
104
104
  async playlistQueueClear(options) {
105
- await this.get(`${BASE_PATH}/playlist_queue_clear.cgi`, undefined, options);
105
+ await this._getJson(`${BASE_PATH}/playlist_queue_clear.cgi`, undefined, options);
106
106
  }
107
107
  async playlistQueueList(options) {
108
- const data = await this.get(`${BASE_PATH}/playlist_queue_list.cgi`, undefined, options);
109
- return CamSwitcherAPI_1.playlistQueueSchema.parse(data).playlistQueueList;
108
+ const res = await this._getJson(`${BASE_PATH}/playlist_queue_list.cgi`, undefined, options);
109
+ return CamSwitcherAPI_1.playlistQueueSchema.parse(res.data).playlistQueueList;
110
110
  }
111
111
  async playlistQueuePlayNext(options) {
112
- await this.get(`${BASE_PATH}/playlist_queue_play_next.cgi`, undefined, options);
112
+ await this._getJson(`${BASE_PATH}/playlist_queue_play_next.cgi`, undefined, options);
113
113
  }
114
114
  async addNewClip(file, clipType, storage, clipId, fileName, options) {
115
- const path = `${BASE_PATH}/clip_upload.cgi?storage=${storage}`;
115
+ const path = `${BASE_PATH}/clip_upload.cgi`;
116
116
  const formData = new this.CustomFormData();
117
117
  formData.append('clip_name', clipId);
118
118
  formData.append('clip_type', clipType);
119
119
  formData.append('file', file, fileName);
120
120
  const agent = this.getClient(options?.proxyParams);
121
- const res = await agent.post({ path, data: formData, timeout: options?.timeout });
121
+ const res = await agent.post({
122
+ path,
123
+ data: formData,
124
+ parameters: {
125
+ storage: storage,
126
+ },
127
+ timeout: options?.timeout,
128
+ });
122
129
  const output = (await res.json());
123
130
  if (output.status !== 200) {
124
131
  throw new errors_1.AddNewClipError(output.message);
125
132
  }
126
133
  }
127
134
  removeClip(clipId, storage, options) {
128
- return this.get(`${BASE_PATH}/clip_remove.cgi`, { clip_name: clipId, storage }, options);
135
+ return this._getJson(`${BASE_PATH}/clip_remove.cgi`, { clip_name: clipId, storage }, options);
129
136
  }
130
137
  async getClipList(options) {
131
- const data = await this.get(`${BASE_PATH}/clip_list.cgi`, undefined, options);
132
- return CamSwitcherAPI_1.clipListSchema.parse(data).clip_list;
138
+ const res = await this._getJson(`${BASE_PATH}/clip_list.cgi`, undefined, options);
139
+ return CamSwitcherAPI_1.clipListSchema.parse(res.data).clip_list;
133
140
  }
134
141
  setCamSwitchOptions(data, cameraFWVersion, options) {
135
142
  const bitrateVapixParams = parseBitrateOptionsToBitrateVapixParams(cameraFWVersion, data.bitrateMode, data);
@@ -230,7 +237,7 @@ class CamSwitcherAPI {
230
237
  settings.source = res.clip_name;
231
238
  settings.storage = res.storage;
232
239
  }
233
- return settings;
240
+ return CamSwitcherAPI_1.globalAudioSettingsSchema.parse(settings);
234
241
  }
235
242
  async getSecondaryAudioSettings(options) {
236
243
  const res = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SECONDARY_AUDIO, options);
@@ -242,30 +249,28 @@ class CamSwitcherAPI {
242
249
  secondaryAudioLevel: res.secondary_audio_level ?? 1,
243
250
  masterAudioLevel: res.master_audio_level ?? 1,
244
251
  };
245
- return settings;
252
+ return CamSwitcherAPI_1.secondaryAudioSettingsSchema.parse(settings);
246
253
  }
247
254
  async getPermanentRtspUrlToken(options) {
248
255
  const paramName = CSW_PARAM_NAMES.RTSP_TOKEN;
249
256
  const res = await this.vapixAgent.getParameter([paramName], options);
250
- return res[paramName] ?? '';
257
+ return zod_1.z.string().parse(res[paramName] ?? '');
251
258
  }
252
- async get(path, parameters, options) {
259
+ async _getJson(path, parameters, options) {
253
260
  const agent = this.getClient(options?.proxyParams);
254
261
  const res = await agent.get({ path, parameters, timeout: options?.timeout });
255
262
  if (res.ok) {
256
- const d = await res.json();
257
- return d.data;
263
+ return await res.json();
258
264
  }
259
265
  else {
260
266
  throw new Error(await (0, utils_1.responseStringify)(res));
261
267
  }
262
268
  }
263
- async set(path, data, parameters, options) {
269
+ async _post(path, data, parameters, options, headers) {
264
270
  const agent = this.getClient(options?.proxyParams);
265
- const res = await agent.post({ path, data: JSON.stringify(data), parameters, timeout: options?.timeout });
271
+ const res = await agent.post({ path, data, parameters, timeout: options?.timeout, headers });
266
272
  if (res.ok) {
267
- const parsed = await res.json();
268
- return parsed.message === 'OK';
273
+ return await res.json();
269
274
  }
270
275
  else {
271
276
  throw new Error(await (0, utils_1.responseStringify)(res));
@@ -306,7 +311,7 @@ const parseBitrateOptionsToBitrateVapixParams = (firmWareVersion, bitrateMode, c
306
311
  if (!(0, versionCompare_1.isFirmwareVersionAtLeast)(firmWareVersion, constants_1.FIRMWARE_WITH_BITRATE_MODES_SUPPORT)) {
307
312
  return `videomaxbitrate=${cameraOptions.maximumBitRate}`;
308
313
  }
309
- if (bitrateMode === null) {
314
+ if (bitrateMode === undefined) {
310
315
  return '';
311
316
  }
312
317
  const data = {