camstreamerlib 4.0.0-beta.3 → 4.0.0-beta.31

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 (194) hide show
  1. package/README.md +8 -2
  2. package/cjs/CamOverlayAPI.d.ts +48 -26
  3. package/cjs/CamOverlayAPI.js +171 -88
  4. package/cjs/CamOverlayDrawingAPI.d.ts +2 -47
  5. package/cjs/CamOverlayDrawingAPI.js +6 -3
  6. package/cjs/CamOverlayPainter/Frame.d.ts +8 -37
  7. package/cjs/CamOverlayPainter/Frame.js +33 -0
  8. package/cjs/CamOverlayPainter/Painter.d.ts +16 -10
  9. package/cjs/CamOverlayPainter/Painter.js +6 -5
  10. package/cjs/CamOverlayPainter/ResourceManager.d.ts +3 -2
  11. package/cjs/CamOverlayPainter/ResourceManager.js +8 -11
  12. package/cjs/CamScripterAPI.d.ts +34 -16
  13. package/cjs/CamScripterAPI.js +50 -41
  14. package/cjs/CamScripterAPICameraEventsGenerator.d.ts +1 -1
  15. package/cjs/CamScripterAPICameraEventsGenerator.js +6 -3
  16. package/cjs/CamStreamerAPI.d.ts +17 -14
  17. package/cjs/CamStreamerAPI.js +32 -32
  18. package/cjs/CamSwitcherAPI.d.ts +43 -37
  19. package/cjs/CamSwitcherAPI.js +123 -114
  20. package/cjs/CamSwitcherEvents.d.ts +1 -1
  21. package/cjs/PlaneTrackerAPI.d.ts +43 -0
  22. package/cjs/PlaneTrackerAPI.js +211 -0
  23. package/cjs/VapixAPI.d.ts +56 -42
  24. package/cjs/VapixAPI.js +305 -216
  25. package/cjs/VapixEvents.d.ts +1 -1
  26. package/cjs/VapixEvents.js +3 -3
  27. package/cjs/errors/errors.d.ts +3 -0
  28. package/cjs/errors/errors.js +8 -1
  29. package/cjs/events/AxisCameraStationEvents.d.ts +7 -4
  30. package/cjs/events/AxisCameraStationEvents.js +23 -18
  31. package/cjs/events/GenetecAgent.d.ts +6 -3
  32. package/cjs/events/GenetecAgent.js +30 -19
  33. package/cjs/index.d.ts +14 -1
  34. package/cjs/index.js +23 -2
  35. package/cjs/internal/Digest.js +6 -6
  36. package/cjs/internal/ProxyClient.d.ts +8 -9
  37. package/cjs/internal/ProxyClient.js +25 -29
  38. package/cjs/internal/types.d.ts +42 -0
  39. package/cjs/internal/types.js +2 -0
  40. package/cjs/internal/utils.d.ts +4 -1
  41. package/cjs/internal/utils.js +22 -3
  42. package/cjs/internal/versionCompare.d.ts +2 -2
  43. package/cjs/node/DefaultClient.d.ts +5 -6
  44. package/cjs/node/DefaultClient.js +12 -14
  45. package/cjs/node/HttpRequestSender.d.ts +1 -0
  46. package/cjs/node/HttpRequestSender.js +13 -3
  47. package/cjs/node/HttpServer.js +1 -1
  48. package/cjs/node/WsClient.d.ts +2 -1
  49. package/cjs/node/index.d.ts +2 -0
  50. package/cjs/node/index.js +18 -1
  51. package/cjs/types/CamOverlayAPI/CamOverlayAPI.d.ts +3071 -0
  52. package/cjs/types/CamOverlayAPI/CamOverlayAPI.js +127 -0
  53. package/cjs/types/CamOverlayAPI/accuweatherSchema.d.ts +114 -0
  54. package/cjs/types/CamOverlayAPI/accuweatherSchema.js +50 -0
  55. package/cjs/types/CamOverlayAPI/customGraphicsSchema.d.ts +783 -0
  56. package/cjs/types/CamOverlayAPI/customGraphicsSchema.js +75 -0
  57. package/cjs/types/CamOverlayAPI/imagesSchema.d.ts +122 -0
  58. package/cjs/types/CamOverlayAPI/imagesSchema.js +12 -0
  59. package/cjs/types/CamOverlayAPI/index.d.ts +9 -0
  60. package/cjs/types/CamOverlayAPI/index.js +25 -0
  61. package/cjs/types/CamOverlayAPI/infotickerSchema.d.ts +130 -0
  62. package/cjs/types/CamOverlayAPI/infotickerSchema.js +29 -0
  63. package/cjs/types/CamOverlayAPI/pipSchema.d.ts +166 -0
  64. package/cjs/types/CamOverlayAPI/pipSchema.js +42 -0
  65. package/cjs/types/CamOverlayAPI/ptzCompassSchema.d.ts +126 -0
  66. package/cjs/types/CamOverlayAPI/ptzCompassSchema.js +28 -0
  67. package/cjs/types/CamOverlayAPI/ptzSchema.d.ts +146 -0
  68. package/cjs/types/CamOverlayAPI/ptzSchema.js +15 -0
  69. package/cjs/types/CamOverlayAPI/screenSharingSchema.d.ts +79 -0
  70. package/cjs/types/CamOverlayAPI/screenSharingSchema.js +11 -0
  71. package/cjs/types/CamOverlayAPI/webCameraSharingSchema.d.ts +79 -0
  72. package/cjs/types/CamOverlayAPI/webCameraSharingSchema.js +11 -0
  73. package/cjs/types/CamOverlayDrawingAPI.d.ts +58 -0
  74. package/cjs/types/CamOverlayDrawingAPI.js +2 -0
  75. package/cjs/types/CamOverlayPainter.d.ts +74 -0
  76. package/cjs/types/CamOverlayPainter.js +2 -0
  77. package/cjs/types/CamScripterAPI.d.ts +82 -17
  78. package/cjs/types/CamScripterAPI.js +22 -7
  79. package/cjs/types/CamStreamerAPI.d.ts +16 -5
  80. package/cjs/types/CamStreamerAPI.js +5 -1
  81. package/cjs/types/CamSwitcherAPI.d.ts +4 -6
  82. package/cjs/types/CamSwitcherEvents.d.ts +77 -0
  83. package/cjs/types/CamSwitcherEvents.js +8 -0
  84. package/cjs/types/PlaneTrackerAPI.d.ts +8 -0
  85. package/cjs/types/PlaneTrackerAPI.js +2 -0
  86. package/cjs/types/VapixAPI.d.ts +635 -520
  87. package/cjs/types/VapixAPI.js +62 -24
  88. package/cjs/types/common.d.ts +14 -5
  89. package/cjs/web/DefaultClient.d.ts +5 -5
  90. package/cjs/web/DefaultClient.js +22 -10
  91. package/cjs/web/WsClient.js +2 -2
  92. package/esm/CamOverlayAPI.d.ts +48 -26
  93. package/esm/CamOverlayAPI.js +167 -84
  94. package/esm/CamOverlayDrawingAPI.d.ts +2 -47
  95. package/esm/CamOverlayDrawingAPI.js +6 -3
  96. package/esm/CamOverlayPainter/Frame.d.ts +8 -37
  97. package/esm/CamOverlayPainter/Frame.js +33 -0
  98. package/esm/CamOverlayPainter/Painter.d.ts +16 -10
  99. package/esm/CamOverlayPainter/Painter.js +5 -3
  100. package/esm/CamOverlayPainter/ResourceManager.d.ts +3 -2
  101. package/esm/CamOverlayPainter/ResourceManager.js +7 -11
  102. package/esm/CamScripterAPI.d.ts +34 -16
  103. package/esm/CamScripterAPI.js +46 -37
  104. package/esm/CamScripterAPICameraEventsGenerator.d.ts +1 -1
  105. package/esm/CamScripterAPICameraEventsGenerator.js +6 -3
  106. package/esm/CamStreamerAPI.d.ts +17 -14
  107. package/esm/CamStreamerAPI.js +32 -32
  108. package/esm/CamSwitcherAPI.d.ts +43 -37
  109. package/esm/CamSwitcherAPI.js +116 -107
  110. package/esm/CamSwitcherEvents.d.ts +1 -1
  111. package/esm/PlaneTrackerAPI.d.ts +43 -0
  112. package/esm/PlaneTrackerAPI.js +207 -0
  113. package/esm/VapixAPI.d.ts +56 -42
  114. package/esm/VapixAPI.js +297 -208
  115. package/esm/VapixEvents.d.ts +1 -1
  116. package/esm/VapixEvents.js +3 -3
  117. package/esm/errors/errors.d.ts +3 -0
  118. package/esm/errors/errors.js +6 -0
  119. package/esm/events/AxisCameraStationEvents.d.ts +7 -4
  120. package/esm/events/AxisCameraStationEvents.js +18 -13
  121. package/esm/events/GenetecAgent.d.ts +6 -3
  122. package/esm/events/GenetecAgent.js +20 -9
  123. package/esm/index.d.ts +14 -1
  124. package/esm/index.js +14 -1
  125. package/esm/internal/Digest.js +6 -6
  126. package/esm/internal/ProxyClient.d.ts +8 -9
  127. package/esm/internal/ProxyClient.js +25 -29
  128. package/esm/internal/types.d.ts +42 -0
  129. package/esm/internal/types.js +1 -0
  130. package/esm/internal/utils.d.ts +4 -1
  131. package/esm/internal/utils.js +17 -1
  132. package/esm/internal/versionCompare.d.ts +2 -2
  133. package/esm/node/DefaultClient.d.ts +5 -6
  134. package/esm/node/DefaultClient.js +12 -14
  135. package/esm/node/HttpRequestSender.d.ts +1 -0
  136. package/esm/node/HttpRequestSender.js +13 -3
  137. package/esm/node/HttpServer.js +1 -1
  138. package/esm/node/WsClient.d.ts +2 -1
  139. package/esm/node/index.d.ts +2 -0
  140. package/esm/node/index.js +2 -0
  141. package/esm/types/CamOverlayAPI/CamOverlayAPI.d.ts +3071 -0
  142. package/esm/types/CamOverlayAPI/CamOverlayAPI.js +124 -0
  143. package/esm/types/CamOverlayAPI/accuweatherSchema.d.ts +114 -0
  144. package/esm/types/CamOverlayAPI/accuweatherSchema.js +46 -0
  145. package/esm/types/CamOverlayAPI/customGraphicsSchema.d.ts +783 -0
  146. package/esm/types/CamOverlayAPI/customGraphicsSchema.js +71 -0
  147. package/esm/types/CamOverlayAPI/imagesSchema.d.ts +122 -0
  148. package/esm/types/CamOverlayAPI/imagesSchema.js +8 -0
  149. package/esm/types/CamOverlayAPI/index.d.ts +9 -0
  150. package/esm/types/CamOverlayAPI/index.js +9 -0
  151. package/esm/types/CamOverlayAPI/infotickerSchema.d.ts +130 -0
  152. package/esm/types/CamOverlayAPI/infotickerSchema.js +25 -0
  153. package/esm/types/CamOverlayAPI/pipSchema.d.ts +166 -0
  154. package/esm/types/CamOverlayAPI/pipSchema.js +38 -0
  155. package/esm/types/CamOverlayAPI/ptzCompassSchema.d.ts +126 -0
  156. package/esm/types/CamOverlayAPI/ptzCompassSchema.js +24 -0
  157. package/esm/types/CamOverlayAPI/ptzSchema.d.ts +146 -0
  158. package/esm/types/CamOverlayAPI/ptzSchema.js +11 -0
  159. package/esm/types/CamOverlayAPI/screenSharingSchema.d.ts +79 -0
  160. package/esm/types/CamOverlayAPI/screenSharingSchema.js +7 -0
  161. package/esm/types/CamOverlayAPI/webCameraSharingSchema.d.ts +79 -0
  162. package/esm/types/CamOverlayAPI/webCameraSharingSchema.js +7 -0
  163. package/esm/types/CamOverlayDrawingAPI.d.ts +58 -0
  164. package/esm/types/CamOverlayDrawingAPI.js +1 -0
  165. package/esm/types/CamOverlayPainter.d.ts +74 -0
  166. package/esm/types/CamOverlayPainter.js +1 -0
  167. package/esm/types/CamScripterAPI.d.ts +82 -17
  168. package/esm/types/CamScripterAPI.js +21 -6
  169. package/esm/types/CamStreamerAPI.d.ts +16 -5
  170. package/esm/types/CamStreamerAPI.js +4 -0
  171. package/esm/types/CamSwitcherAPI.d.ts +4 -6
  172. package/esm/types/CamSwitcherEvents.d.ts +77 -0
  173. package/esm/types/CamSwitcherEvents.js +8 -0
  174. package/esm/types/PlaneTrackerAPI.d.ts +8 -0
  175. package/esm/types/PlaneTrackerAPI.js +1 -0
  176. package/esm/types/VapixAPI.d.ts +635 -520
  177. package/esm/types/VapixAPI.js +61 -23
  178. package/esm/types/common.d.ts +14 -5
  179. package/esm/web/DefaultClient.d.ts +5 -5
  180. package/esm/web/DefaultClient.js +22 -10
  181. package/esm/web/WsClient.js +2 -2
  182. package/package.json +9 -8
  183. package/cjs/internal/common.d.ts +0 -39
  184. package/cjs/internal/common.js +0 -27
  185. package/cjs/node/WsEventClient.d.ts +0 -13
  186. package/cjs/node/WsEventClient.js +0 -22
  187. package/cjs/types/CamOverlayAPI.d.ts +0 -188
  188. package/cjs/types/CamOverlayAPI.js +0 -47
  189. package/esm/internal/common.d.ts +0 -39
  190. package/esm/internal/common.js +0 -20
  191. package/esm/node/WsEventClient.d.ts +0 -13
  192. package/esm/node/WsEventClient.js +0 -18
  193. package/esm/types/CamOverlayAPI.d.ts +0 -188
  194. package/esm/types/CamOverlayAPI.js +0 -44
@@ -1,65 +1,103 @@
1
- import { isClient, responseStringify } from './internal/common';
2
- import { DefaultClient } from './node/DefaultClient';
3
- import { fileListSchema, ImageType, serviceSchema, storageSchema, } from './types/CamOverlayAPI';
1
+ import { paramToUrl, responseStringify } from './internal/utils';
4
2
  import { ParsingBlobError, ServiceNotFoundError } from './errors/errors';
5
3
  import { networkCameraListSchema } from './types/common';
4
+ import { z } from 'zod';
5
+ import { ProxyClient } from './internal/ProxyClient';
6
+ import { fileListSchema, ImageType, storageDataListSchema, widgetsSchema, WSResponseSchema, } from './types/CamOverlayAPI/CamOverlayAPI';
7
+ export const allowedWidgetNames = {
8
+ accuweather: 'accuweather',
9
+ infoticker: 'infoticker',
10
+ customGraphics: 'customGraphics',
11
+ ptzCompass: 'ptzCompass',
12
+ images: 'images',
13
+ ptz: 'ptz',
14
+ pip: 'pip',
15
+ screenSharing: 'screenSharing',
16
+ web_camera: 'web_camera',
17
+ };
18
+ const BASE_PATH = '/local/camoverlay/api';
6
19
  export class CamOverlayAPI {
7
20
  client;
8
- constructor(options = {}) {
9
- if (isClient(options)) {
10
- this.client = options;
11
- }
12
- else {
13
- this.client = new DefaultClient(options);
14
- }
21
+ constructor(client) {
22
+ this.client = client;
15
23
  }
16
- async checkCameraTime() {
17
- const cameraTime = await this.get('/local/camoverlay/api/camera_time.cgi');
18
- return cameraTime.state;
24
+ static getBasePath = () => BASE_PATH;
25
+ static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
26
+ static getFilePreviewPath = (path) => `${BASE_PATH}/image.cgi?path=${encodeURIComponent(path)}`;
27
+ getClient(proxyParams) {
28
+ return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
19
29
  }
20
- async getNetworkCameraList() {
21
- const response = await this.get('/local/camoverlay/api/network_camera_list.cgi');
22
- return networkCameraListSchema.parse(response.camera_list);
23
- }
24
- async wsAutoratization() {
25
- const response = await this.get(`/local/camoverlay/api/ws_authorization.cgi`);
26
- return response.data;
30
+ async checkCameraTime(options) {
31
+ const response = await this._get({ path: `${BASE_PATH}/camera_time.cgi` }, options);
32
+ return z.boolean().parse(response.state);
27
33
  }
28
- async getMjpegStreamImage(mjpegUrl) {
29
- const res = await this.get(`/local/camoverlay/api/fetch_mjpeg_image.cgi?mjpeg_url=${encodeURIComponent(decodeURIComponent(mjpegUrl))}`);
30
- return await this.parseBlobResponse(res);
34
+ async getNetworkCameraList(options) {
35
+ const response = await this._get({ path: `${BASE_PATH}/network_camera_list.cgi` }, options);
36
+ return networkCameraListSchema.parse(response.camera_list);
31
37
  }
32
- async listFiles(fileType) {
33
- const files = await this.get(`/local/camoverlay/api/upload_${fileType}.cgi?action=list`);
38
+ async wsAuthorization(options) {
39
+ const response = await this._get({ path: `${BASE_PATH}/ws_authorization.cgi` }, options);
40
+ return WSResponseSchema.parse(response).data;
41
+ }
42
+ async getMjpegStreamImage(mjpegUrl, options) {
43
+ return await this._getBlob({
44
+ path: `${BASE_PATH}/fetch_mjpeg_image.cgi?mjpeg_url=${encodeURIComponent(decodeURIComponent(mjpegUrl))}`,
45
+ }, options);
46
+ }
47
+ async listFiles(fileType, options) {
48
+ const files = await this._get({
49
+ path: `${BASE_PATH}/upload_${fileType}.cgi`,
50
+ parameters: {
51
+ action: 'list',
52
+ },
53
+ }, options);
34
54
  return fileListSchema.parse(files.list);
35
55
  }
36
- async uploadFile(fileType, file, fileName) {
37
- const formData = new FormData();
38
- formData.append('target', 'SD0');
39
- formData.append('uploadedFile[]', file, fileName);
40
- const path = `/local/camoverlay/api/upload_${fileType}.cgi?action=upload`;
41
- await this.post(path, formData);
42
- }
43
- async removeFile(fileType, file) {
44
- const path = `/local/camoverlay/api/upload_${fileType}.cgi?action=remove`;
45
- await this.post(path, JSON.stringify(file));
56
+ async uploadFile(fileType, formData, storage, options) {
57
+ await this._post({
58
+ path: `${BASE_PATH}/upload_${fileType}.cgi`,
59
+ data: formData,
60
+ parameters: {
61
+ action: 'upload',
62
+ storage: storage,
63
+ },
64
+ }, options);
65
+ }
66
+ async removeFile(fileType, fileParams, options) {
67
+ const path = `${BASE_PATH}/upload_${fileType}.cgi`;
68
+ await this._postUrlEncoded(path, {
69
+ action: 'remove',
70
+ ...fileParams,
71
+ }, undefined, options);
72
+ }
73
+ async getFileStorage(fileType, options) {
74
+ const data = await this._get({
75
+ path: `${BASE_PATH}/upload_${fileType}.cgi`,
76
+ parameters: {
77
+ action: 'get_storage',
78
+ },
79
+ }, options);
80
+ if (data.code !== 200) {
81
+ throw new Error('Error occured while fetching file storage data');
82
+ }
83
+ return storageDataListSchema.parse(data.list);
46
84
  }
47
- async getFileStorage(fileType) {
48
- const data = await this.get(`/local/camoverlay/api/upload_${fileType}.cgi?action=get_storage`);
49
- return storageSchema.parse(data);
85
+ async getFilePreviewFromCamera(path, options) {
86
+ return await this._getBlob({ path: CamOverlayAPI.getFilePreviewPath(path) }, options);
50
87
  }
51
- async updateInfoticker(serviceID, text) {
52
- await this.get(`/local/camoverlay/api/infoticker.cgi?service_id=${serviceID}&text=${text}`);
88
+ async updateInfoticker(serviceId, text, options) {
89
+ await this._get({ path: `${BASE_PATH}/infoticker.cgi?service_id=${serviceId}&text=${text}` }, options);
53
90
  }
54
- async setEnabled(serviceID, enabled) {
55
- await this.post(`/local/camoverlay/api/enabled.cgi?id_${serviceID}=${enabled ? 1 : 0}`, '');
91
+ async setEnabled(serviceId, enabled, options) {
92
+ await this._post({ path: `${BASE_PATH}/enabled.cgi?id_${serviceId}=${enabled ? 1 : 0}`, data: '' }, options);
56
93
  }
57
- async isEnabled(serviceID) {
58
- const res = await this.client.get('/local/camoverlay/api/services.cgi?action=get');
94
+ async isEnabled(serviceId, options) {
95
+ const agent = this.getClient(options?.proxyParams);
96
+ const res = await agent.get({ path: `${BASE_PATH}/services.cgi?action=get`, timeout: options?.timeout });
59
97
  if (res.ok) {
60
98
  const data = JSON.parse(await res.text());
61
99
  for (const service of data.services) {
62
- if (service.id === serviceID) {
100
+ if (service.id === serviceId) {
63
101
  return service.enabled === 1;
64
102
  }
65
103
  }
@@ -69,29 +107,46 @@ export class CamOverlayAPI {
69
107
  throw new Error(await responseStringify(res));
70
108
  }
71
109
  }
72
- async getSingleService(serviceId) {
73
- const data = await this.get('/local/camoverlay/api/services.cgi', {
74
- action: 'get',
75
- service_id: serviceId.toString(),
110
+ async getSingleWidget(serviceId, options) {
111
+ const data = await this._get({
112
+ path: `${BASE_PATH}/services.cgi`,
113
+ parameters: {
114
+ action: 'get',
115
+ service_id: serviceId.toString(),
116
+ },
117
+ }, options);
118
+ return widgetsSchema.parse(data);
119
+ }
120
+ async getWidgets(options) {
121
+ const widgetList = await this._get({
122
+ path: `${BASE_PATH}/services.cgi`,
123
+ parameters: {
124
+ action: 'get',
125
+ },
126
+ }, options);
127
+ const widgets = widgetList.services;
128
+ widgets.forEach((widget) => {
129
+ const parsedWidget = widgetsSchema.safeParse(widget);
130
+ if (!parsedWidget.success) {
131
+ console.warn(`[SERVICE SCHEMA MISMATCH]: Service ${widget.name} (${widget.id}) does not match the current schema, or is a hidden service.`);
132
+ }
76
133
  });
77
- return serviceSchema.parse(data);
134
+ return widgets;
78
135
  }
79
- async getServices() {
80
- const serviceList = await this.get('/local/camoverlay/api/services.cgi?action=get');
81
- return serviceSchema.parse(serviceList).services;
82
- }
83
- async updateSingleService(serviceId, serviceJson) {
84
- const path = '/local/camoverlay/api/services.cgi';
85
- await this.post(path, JSON.stringify(serviceJson), {
136
+ async updateSingleWidget(widget, options) {
137
+ const path = `${BASE_PATH}/services.cgi`;
138
+ await this._postJsonEncoded(path, JSON.stringify(widget), {
86
139
  action: 'set',
87
- service_id: serviceId.toString(),
88
- });
140
+ service_id: widget.id.toString(),
141
+ }, undefined, options);
89
142
  }
90
- async updateServices(servicesJson) {
91
- const path = '/local/camoverlay/api/services.cgi?action=set';
92
- await this.post(path, JSON.stringify(servicesJson));
143
+ async updateWidgets(widgets, options) {
144
+ const path = `${BASE_PATH}/services.cgi`;
145
+ await this._postJsonEncoded(path, JSON.stringify({ services: widgets }), {
146
+ action: 'set',
147
+ }, undefined, options);
93
148
  }
94
- updateCGText(serviceID, fields) {
149
+ updateCGText(serviceId, fields, options) {
95
150
  const params = {};
96
151
  for (const field of fields) {
97
152
  const name = field.field_name;
@@ -100,62 +155,81 @@ export class CamOverlayAPI {
100
155
  params[`${name}_color`] = field.color;
101
156
  }
102
157
  }
103
- return this.promiseCGUpdate(serviceID, 'update_text', params);
158
+ return this.promiseCGUpdate(serviceId, 'update_text', params, undefined, undefined, options);
104
159
  }
105
- updateCGImagePos(serviceID, coordinates = '', x = 0, y = 0) {
160
+ updateCGImagePos(serviceId, coordinates = '', x = 0, y = 0, options) {
106
161
  const params = {
107
162
  coord_system: coordinates,
108
163
  pos_x: x,
109
164
  pos_y: y,
110
165
  };
111
- return this.promiseCGUpdate(serviceID, 'update_image', params);
166
+ return this.promiseCGUpdate(serviceId, 'update_image', params, undefined, undefined, options);
112
167
  }
113
- updateCGImage(serviceID, path, coordinates = '', x = 0, y = 0) {
168
+ updateCGImage(serviceId, path, coordinates = '', x = 0, y = 0, options) {
114
169
  const params = {
115
170
  coord_system: coordinates,
116
171
  pos_x: x,
117
172
  pos_y: y,
118
173
  image: path,
119
174
  };
120
- return this.promiseCGUpdate(serviceID, 'update_image', params);
175
+ return this.promiseCGUpdate(serviceId, 'update_image', params, undefined, undefined, options);
121
176
  }
122
- updateCGImageFromData(serviceID, imageType, imageData, coordinates = '', x = 0, y = 0) {
177
+ updateCGImageFromData(serviceId, imageType, imageData, coordinates = '', x = 0, y = 0, options) {
123
178
  const contentType = imageType === ImageType.PNG ? 'image/png' : 'image/jpeg';
124
179
  const params = {
125
180
  coord_system: coordinates,
126
181
  pos_x: x,
127
182
  pos_y: y,
128
183
  };
129
- return this.promiseCGUpdate(serviceID, 'update_image', params, contentType, imageData);
184
+ return this.promiseCGUpdate(serviceId, 'update_image', params, contentType, imageData, options);
130
185
  }
131
- async promiseCGUpdate(serviceID, action, params = {}, contentType, data) {
132
- const path = `/local/camoverlay/api/customGraphics.cgi`;
186
+ async promiseCGUpdate(serviceId, action, params = {}, contentType, data, options) {
187
+ const path = `${BASE_PATH}/customGraphics.cgi`;
133
188
  let headers = {};
134
189
  if (contentType !== undefined && data) {
135
190
  headers = { 'Content-Type': contentType };
136
191
  }
137
- const res = await this.client.post(path, data ?? '', {
138
- action: action,
139
- service_id: serviceID.toString(),
140
- ...params,
141
- }, headers);
192
+ const agent = this.getClient(options?.proxyParams);
193
+ const res = await agent.post({
194
+ path,
195
+ data: data ?? '',
196
+ parameters: {
197
+ action: action,
198
+ service_id: serviceId.toString(),
199
+ ...params,
200
+ },
201
+ headers,
202
+ timeout: options?.timeout,
203
+ });
142
204
  if (!res.ok) {
143
205
  throw new Error(await responseStringify(res));
144
206
  }
145
207
  }
146
- async get(path, params) {
147
- const res = await this.client.get(path, params);
208
+ async _get(params, options) {
209
+ const agent = this.getClient(options?.proxyParams);
210
+ const res = await agent.get({ ...params, timeout: options?.timeout });
211
+ if (res.ok) {
212
+ return (await res.json());
213
+ }
214
+ else {
215
+ throw new Error(await responseStringify(res));
216
+ }
217
+ }
218
+ async _post(params, options) {
219
+ const agent = this.getClient(options?.proxyParams);
220
+ const res = await agent.post({ ...params, timeout: options?.timeout });
148
221
  if (res.ok) {
149
- return await res.json();
222
+ return (await res.json());
150
223
  }
151
224
  else {
152
225
  throw new Error(await responseStringify(res));
153
226
  }
154
227
  }
155
- async post(path, data, params) {
156
- const res = await this.client.post(path, data, params);
228
+ async _getBlob(params, options) {
229
+ const agent = this.getClient(options?.proxyParams);
230
+ const res = await agent.get({ ...params, timeout: options?.timeout });
157
231
  if (res.ok) {
158
- return await res.json();
232
+ return await this.parseBlobResponse(res);
159
233
  }
160
234
  else {
161
235
  throw new Error(await responseStringify(res));
@@ -163,10 +237,19 @@ export class CamOverlayAPI {
163
237
  }
164
238
  async parseBlobResponse(response) {
165
239
  try {
166
- return await response.blob();
240
+ return (await response.blob());
167
241
  }
168
242
  catch (err) {
169
243
  throw new ParsingBlobError(err);
170
244
  }
171
245
  }
246
+ async _postUrlEncoded(path, params, headers, options) {
247
+ const data = paramToUrl(params);
248
+ const baseHeaders = { 'Content-Type': 'application/x-www-form-urlencoded' };
249
+ return this._post({ path, data, headers: { ...baseHeaders, ...headers } }, options);
250
+ }
251
+ async _postJsonEncoded(path, data, parameters, headers, options) {
252
+ const baseHeaders = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
253
+ return this._post({ path, data, parameters, headers: { ...baseHeaders, ...headers } }, options);
254
+ }
172
255
  }
@@ -1,53 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
+ /// <reference types="node" />
3
4
  import * as EventEmitter from 'events';
4
- import { WsOptions } from './internal/common';
5
- export type CamOverlayDrawingOptions = WsOptions & {
6
- camera?: number | number[];
7
- zIndex?: number;
8
- };
9
- export type TCairoResponse = {
10
- message: string;
11
- call_id: number;
12
- };
13
- export type TCairoCreateResponse = {
14
- var: string;
15
- call_id: number;
16
- };
17
- export type TUploadImageResponse = {
18
- var: string;
19
- width: number;
20
- height: number;
21
- call_id: number;
22
- };
23
- export type TErrorResponse = {
24
- error: string;
25
- call_id?: number;
26
- };
27
- export type TService = {
28
- id: number;
29
- enabled: number;
30
- schedule: string;
31
- name: string;
32
- identifier: string;
33
- cameraList: number[];
34
- };
35
- export type TServiceList = {
36
- services: TService[];
37
- };
38
- export type TAlign = 'A_RIGHT' | 'A_LEFT' | 'A_CENTER';
39
- export type TextFit = 'TFM_SCALE' | 'TFM_TRUNCATE' | 'TFM_OVERFLOW';
40
- export type TWriteTextParams = [string, string, number, number, number, number, TAlign, TextFit?];
41
- export interface CamOverlayDrawingAPI {
42
- on(event: 'open', listener: () => void): this;
43
- on(event: 'close', listener: () => void): this;
44
- on(event: 'error', listener: (err: Error) => void): this;
45
- on(event: 'message', listener: (msg: string) => void): this;
46
- emit(event: 'open'): boolean;
47
- emit(event: 'close'): boolean;
48
- emit(event: 'error', err: Error): boolean;
49
- emit(event: 'message', msg: string): boolean;
50
- }
5
+ import { CamOverlayDrawingOptions, TCairoCreateResponse, TCairoResponse, TUploadImageResponse, TWriteTextParams } from './types/CamOverlayDrawingAPI';
51
6
  export declare class CamOverlayDrawingAPI extends EventEmitter {
52
7
  private tls;
53
8
  private tlsInsecure;
@@ -121,10 +121,10 @@ export class CamOverlayDrawingAPI extends EventEmitter {
121
121
  }
122
122
  if (dataJSON.call_id !== undefined) {
123
123
  if (errorResponse !== undefined) {
124
- this.sendMessages[dataJSON.call_id].reject(new Error(errorResponse.error));
124
+ this.sendMessages[dataJSON.call_id]?.reject(new Error(errorResponse.error));
125
125
  }
126
126
  else {
127
- this.sendMessages[dataJSON.call_id].resolve(dataJSON);
127
+ this.sendMessages[dataJSON.call_id]?.resolve(dataJSON);
128
128
  }
129
129
  delete this.sendMessages[dataJSON.call_id];
130
130
  }
@@ -194,6 +194,9 @@ export class CamOverlayDrawingAPI extends EventEmitter {
194
194
  const now = Date.now();
195
195
  for (const callId in this.sendMessages) {
196
196
  const msg = this.sendMessages[callId];
197
+ if (!msg) {
198
+ continue;
199
+ }
197
200
  if (now - msg.sentTimestamp > 10000) {
198
201
  reconnect = true;
199
202
  msg.reject(new Error('Message timeout'));
@@ -220,7 +223,7 @@ export class CamOverlayDrawingAPI extends EventEmitter {
220
223
  }
221
224
  reportClose() {
222
225
  for (const callId in this.sendMessages) {
223
- this.sendMessages[callId].reject(new Error('Connection lost'));
226
+ this.sendMessages[callId]?.reject(new Error('Connection lost'));
224
227
  }
225
228
  this.sendMessages = {};
226
229
  this.emit('close');
@@ -1,42 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
- import { CamOverlayDrawingAPI, TAlign, TCairoCreateResponse, TUploadImageResponse } from '../CamOverlayDrawingAPI';
4
- import ResourceManager from './ResourceManager';
5
- export type TRgb = [number, number, number];
6
- export type TRgba = [number, number, number, number];
7
- export type TTmf = 'TFM_OVERFLOW' | 'TFM_SCALE' | 'TFM_TRUNCATE';
8
- export type TObjectFitType = 'fill' | 'fit' | 'none';
9
- export type TFrameOptions = {
10
- enabled?: boolean;
11
- x: number;
12
- y: number;
13
- width: number;
14
- height: number;
15
- text?: string;
16
- fontColor?: TRgb;
17
- font?: string;
18
- bgColor?: TRgba;
19
- bgImage?: string;
20
- bgType?: TObjectFitType;
21
- borderRadius?: number;
22
- borderWidth?: number;
23
- borderColor?: TRgba;
24
- customDraw?: TDrawingCallback;
25
- layer?: number;
26
- };
27
- export type TFrameInfo = {
28
- width: number;
29
- height: number;
30
- };
31
- export type TDrawingCallback = (cod: CamOverlayDrawingAPI, cairo: string, info: TFrameInfo) => Promise<void>;
32
- export interface Frame {
33
- on(event: 'open', listener: () => void): this;
34
- on(event: 'close', listener: () => void): this;
35
- on(event: 'layoutChanged', listener: () => void): this;
36
- emit(event: 'open'): boolean;
37
- emit(event: 'close'): boolean;
38
- emit(event: 'layoutChanged'): boolean;
39
- }
3
+ import { CamOverlayDrawingAPI } from '../CamOverlayDrawingAPI';
4
+ import { TAlign, TCairoCreateResponse, TUploadImageResponse } from '../types/CamOverlayDrawingAPI';
5
+ import { ResourceManager } from './ResourceManager';
6
+ import { TBg, TBorder, TDrawingCallback, TFrame, TFrameOptions, TObjectFitType, TRgb, TRgba, TText, TTmf } from '../types/CamOverlayPainter';
40
7
  export declare class Frame extends EventEmitter {
41
8
  protected enabled: boolean;
42
9
  protected posX: number;
@@ -64,17 +31,21 @@ export declare class Frame extends EventEmitter {
64
31
  disable(): void;
65
32
  setFramePosition(x: number, y: number): void;
66
33
  setFrameSize(width: number, height: number): void;
34
+ getFrameInfo(): TFrame;
67
35
  setText(text: string, align: TAlign, textType?: TTmf, fontColor?: TRgb): void;
68
36
  setFontColor(fontColor: TRgb): void;
69
37
  setFont(fontName: string): void;
70
38
  setFontData(fontData: TCairoCreateResponse): void;
39
+ getTextInfo(): TText;
71
40
  setBgColor(color: TRgba): void;
72
41
  setBgImage(imageName: string, type?: TObjectFitType): void;
73
42
  setBgImageData(imageData: TUploadImageResponse, type?: TObjectFitType): void;
74
43
  setBgType(type: TObjectFitType): void;
44
+ getBgInfo(): TBg;
75
45
  setBorderRadius(radius: number): void;
76
46
  setBorderWidth(width: number): void;
77
47
  setBorderColor(color: TRgba): void;
48
+ getBorderInfo(): TBorder;
78
49
  setCustomDraw(customDraw: TDrawingCallback): void;
79
50
  resetFont(): void;
80
51
  resetBgColor(): void;
@@ -54,6 +54,14 @@ export class Frame extends EventEmitter {
54
54
  this.width = width;
55
55
  this.height = height;
56
56
  }
57
+ getFrameInfo() {
58
+ return {
59
+ x: this.posX,
60
+ y: this.posY,
61
+ width: this.width,
62
+ height: this.height,
63
+ };
64
+ }
57
65
  setText(text, align, textType = 'TFM_OVERFLOW', fontColor) {
58
66
  this.text = text;
59
67
  this.align = align;
@@ -73,6 +81,16 @@ export class Frame extends EventEmitter {
73
81
  this.fontName = undefined;
74
82
  this.font = fontData;
75
83
  }
84
+ getTextInfo() {
85
+ return {
86
+ text: this.text,
87
+ textAlign: this.align,
88
+ textType: this.textType,
89
+ fontColor: this.fontColor,
90
+ font: this.font,
91
+ fontName: this.fontName,
92
+ };
93
+ }
76
94
  setBgColor(color) {
77
95
  this.bgColor = color;
78
96
  }
@@ -89,6 +107,14 @@ export class Frame extends EventEmitter {
89
107
  setBgType(type) {
90
108
  this.bgType = type;
91
109
  }
110
+ getBgInfo() {
111
+ return {
112
+ bgColor: this.bgColor,
113
+ bgImage: this.bgImage,
114
+ bgImageName: this.bgImageName,
115
+ bgType: this.bgType,
116
+ };
117
+ }
92
118
  setBorderRadius(radius) {
93
119
  this.borderRadius = radius;
94
120
  }
@@ -98,6 +124,13 @@ export class Frame extends EventEmitter {
98
124
  setBorderColor(color) {
99
125
  this.borderColor = color;
100
126
  }
127
+ getBorderInfo() {
128
+ return {
129
+ borderRadius: this.borderRadius,
130
+ borderWidth: this.borderWidth,
131
+ borderColor: this.borderColor,
132
+ };
133
+ }
101
134
  setCustomDraw(customDraw) {
102
135
  this.customDraw = customDraw;
103
136
  }
@@ -1,11 +1,18 @@
1
- import { CamOverlayDrawingAPI, CamOverlayDrawingOptions } from '../CamOverlayDrawingAPI';
2
- import ResourceManager from './ResourceManager';
3
- import { Frame, TFrameOptions } from './Frame';
4
- export declare const COORD: Record<string, [number, number]>;
5
- export type TPainterOptions = TFrameOptions & {
6
- screenWidth: number;
7
- screenHeight: number;
8
- coAlignment: string;
1
+ import { CamOverlayDrawingAPI } from '../CamOverlayDrawingAPI';
2
+ import { CamOverlayDrawingOptions } from '../types/CamOverlayDrawingAPI';
3
+ import { ResourceManager } from './ResourceManager';
4
+ import { Frame } from './Frame';
5
+ import { TCoAlignment, TPainterOptions } from '../types/CamOverlayPainter';
6
+ export declare const COORD: {
7
+ readonly top_left: readonly [-1, -1];
8
+ readonly center_left: readonly [-1, 0];
9
+ readonly bottom_left: readonly [-1, 1];
10
+ readonly top_center: readonly [0, -1];
11
+ readonly center: readonly [0, 0];
12
+ readonly bottom_center: readonly [0, 1];
13
+ readonly top_right: readonly [1, -1];
14
+ readonly center_right: readonly [1, 0];
15
+ readonly bottom_right: readonly [1, 1];
9
16
  };
10
17
  export declare class Painter extends Frame {
11
18
  private screenWidth;
@@ -24,7 +31,7 @@ export declare class Painter extends Frame {
24
31
  registerImage(moniker: string, fileName: string): void;
25
32
  registerFont(moniker: string, fileName: string): void;
26
33
  setScreenSize(sw: number, sh: number): void;
27
- setCoAlignment(coAlignment: string): void;
34
+ setCoAlignment(coAlignment: TCoAlignment): void;
28
35
  protected layoutChanged(): void;
29
36
  display(scale?: number): Promise<void>;
30
37
  hide(): Promise<void>;
@@ -34,4 +41,3 @@ export declare class Painter extends Frame {
34
41
  private cleanupSurface;
35
42
  private positionConvertor;
36
43
  }
37
- export { Frame, TFrameOptions as FrameOptions, ResourceManager, CamOverlayDrawingOptions };
@@ -1,5 +1,5 @@
1
1
  import { CamOverlayDrawingAPI } from '../CamOverlayDrawingAPI';
2
- import ResourceManager from './ResourceManager';
2
+ import { ResourceManager } from './ResourceManager';
3
3
  import { Frame } from './Frame';
4
4
  export const COORD = {
5
5
  top_left: [-1, -1],
@@ -82,6 +82,9 @@ export class Painter extends Frame {
82
82
  let lastCachedLayer;
83
83
  for (let i = 0; i < this.layers.length; i++) {
84
84
  const layer = this.layers[i];
85
+ if (layer === undefined) {
86
+ continue;
87
+ }
85
88
  if (layer.cairoCache !== undefined &&
86
89
  layer.surfaceCache !== undefined &&
87
90
  surface === undefined &&
@@ -115,7 +118,7 @@ export class Painter extends Frame {
115
118
  }
116
119
  for (let i = layerIdx; i < this.layers.length; i++) {
117
120
  const currentLayer = this.layers[i];
118
- if (currentLayer.surfaceCache !== undefined && currentLayer.cairoCache !== undefined) {
121
+ if (currentLayer?.surfaceCache !== undefined && currentLayer.cairoCache !== undefined) {
119
122
  await this.cleanupSurface(currentLayer.surfaceCache, currentLayer.cairoCache);
120
123
  currentLayer.surfaceCache = undefined;
121
124
  currentLayer.cairoCache = undefined;
@@ -160,4 +163,3 @@ export class Painter extends Frame {
160
163
  }
161
164
  }
162
165
  }
163
- export { Frame, ResourceManager };
@@ -1,5 +1,6 @@
1
- import { CamOverlayDrawingAPI, TUploadImageResponse, TCairoCreateResponse } from '../CamOverlayDrawingAPI';
2
- export default class ResourceManager {
1
+ import { CamOverlayDrawingAPI } from '../CamOverlayDrawingAPI';
2
+ import { TUploadImageResponse, TCairoCreateResponse } from '../types/CamOverlayDrawingAPI';
3
+ export declare class ResourceManager {
3
4
  private co;
4
5
  private imgFileNames;
5
6
  private fontFileNames;