camstreamerlib 4.0.0-beta.1 → 4.0.0-beta.11

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 (227) hide show
  1. package/README.md +5 -1
  2. package/cjs/CamOverlayAPI.d.ts +629 -0
  3. package/cjs/CamOverlayAPI.js +255 -0
  4. package/{CamOverlayDrawingAPI.d.ts → cjs/CamOverlayDrawingAPI.d.ts} +1 -1
  5. package/cjs/CamOverlayDrawingAPI.js +235 -0
  6. package/cjs/CamOverlayPainter/Frame.js +301 -0
  7. package/{CamOverlayPainter → cjs/CamOverlayPainter}/Painter.d.ts +14 -3
  8. package/cjs/CamOverlayPainter/Painter.js +171 -0
  9. package/cjs/CamOverlayPainter/ResourceManager.js +46 -0
  10. package/{CamScripterAPI.d.ts → cjs/CamScripterAPI.d.ts} +5 -5
  11. package/cjs/CamScripterAPI.js +64 -0
  12. package/{CamScripterAPICameraEventsGenerator.d.ts → cjs/CamScripterAPICameraEventsGenerator.d.ts} +1 -1
  13. package/cjs/CamScripterAPICameraEventsGenerator.js +162 -0
  14. package/{CamStreamerAPI.d.ts → cjs/CamStreamerAPI.d.ts} +5 -5
  15. package/cjs/CamStreamerAPI.js +59 -0
  16. package/{CamSwitcherAPI.d.ts → cjs/CamSwitcherAPI.d.ts} +10 -6
  17. package/cjs/CamSwitcherAPI.js +351 -0
  18. package/{CamSwitcherEvents.d.ts → cjs/CamSwitcherEvents.d.ts} +2 -2
  19. package/cjs/CamSwitcherEvents.js +67 -0
  20. package/cjs/CreatePackage.js +106 -0
  21. package/{VapixAPI.d.ts → cjs/VapixAPI.d.ts} +18 -6
  22. package/cjs/VapixAPI.js +479 -0
  23. package/{VapixEvents.d.ts → cjs/VapixEvents.d.ts} +1 -1
  24. package/cjs/VapixEvents.js +88 -0
  25. package/{errors → cjs/errors}/errors.d.ts +3 -0
  26. package/cjs/errors/errors.js +86 -0
  27. package/{events → cjs/events}/AxisCameraStationEvents.d.ts +3 -2
  28. package/cjs/events/AxisCameraStationEvents.js +48 -0
  29. package/cjs/events/GenetecAgent.js +123 -0
  30. package/cjs/index.d.ts +14 -0
  31. package/cjs/index.js +35 -0
  32. package/cjs/internal/Digest.js +42 -0
  33. package/cjs/internal/ProxyClient.d.ts +11 -0
  34. package/cjs/internal/ProxyClient.js +46 -0
  35. package/cjs/internal/constants.js +4 -0
  36. package/cjs/internal/transformers.js +32 -0
  37. package/cjs/internal/types.d.ts +35 -0
  38. package/cjs/internal/types.js +2 -0
  39. package/{internal → cjs/internal}/utils.d.ts +5 -1
  40. package/cjs/internal/utils.js +69 -0
  41. package/{internal → cjs/internal}/versionCompare.d.ts +2 -2
  42. package/cjs/internal/versionCompare.js +53 -0
  43. package/cjs/models/CamOverlayAPI/accuweatherSchema.d.ts +84 -0
  44. package/cjs/models/CamOverlayAPI/accuweatherSchema.js +48 -0
  45. package/cjs/models/CamOverlayAPI/constants.d.ts +11 -0
  46. package/cjs/models/CamOverlayAPI/constants.js +14 -0
  47. package/cjs/models/CamOverlayAPI/customGraphicsSchema.d.ts +699 -0
  48. package/cjs/models/CamOverlayAPI/customGraphicsSchema.js +73 -0
  49. package/cjs/models/CamOverlayAPI/fileSchema.d.ts +28 -0
  50. package/cjs/models/CamOverlayAPI/fileSchema.js +17 -0
  51. package/cjs/models/CamOverlayAPI/imagesSchema.d.ts +95 -0
  52. package/cjs/models/CamOverlayAPI/imagesSchema.js +10 -0
  53. package/cjs/models/CamOverlayAPI/index.d.ts +13 -0
  54. package/cjs/models/CamOverlayAPI/index.js +29 -0
  55. package/cjs/models/CamOverlayAPI/infotickerSchema.d.ts +96 -0
  56. package/cjs/models/CamOverlayAPI/infotickerSchema.js +27 -0
  57. package/cjs/models/CamOverlayAPI/pipSchema.d.ts +125 -0
  58. package/cjs/models/CamOverlayAPI/pipSchema.js +40 -0
  59. package/cjs/models/CamOverlayAPI/ptzCompassSchema.d.ts +93 -0
  60. package/cjs/models/CamOverlayAPI/ptzCompassSchema.js +26 -0
  61. package/cjs/models/CamOverlayAPI/ptzSchema.d.ts +118 -0
  62. package/cjs/models/CamOverlayAPI/ptzSchema.js +13 -0
  63. package/cjs/models/CamOverlayAPI/screenSharingSchema.d.ts +58 -0
  64. package/cjs/models/CamOverlayAPI/screenSharingSchema.js +9 -0
  65. package/cjs/models/CamOverlayAPI/webCameraSharingSchema.d.ts +58 -0
  66. package/cjs/models/CamOverlayAPI/webCameraSharingSchema.js +9 -0
  67. package/cjs/models/CamOverlayAPI/widgetCommonSchema.d.ts +126 -0
  68. package/cjs/models/CamOverlayAPI/widgetCommonSchema.js +76 -0
  69. package/cjs/models/CamOverlayAPI/widgetsSchema.d.ts +2823 -0
  70. package/cjs/models/CamOverlayAPI/widgetsSchema.js +27 -0
  71. package/cjs/node/DefaultClient.d.ts +16 -0
  72. package/cjs/node/DefaultClient.js +56 -0
  73. package/cjs/node/HttpRequestSender.js +89 -0
  74. package/cjs/node/HttpServer.js +96 -0
  75. package/{node → cjs/node}/WsClient.d.ts +1 -1
  76. package/cjs/node/WsClient.js +149 -0
  77. package/{node → cjs/node}/WsEventClient.d.ts +1 -1
  78. package/cjs/node/WsEventClient.js +22 -0
  79. package/cjs/node/index.d.ts +2 -0
  80. package/cjs/node/index.js +7 -0
  81. package/cjs/types/CamOverlayAPI.d.ts +328 -0
  82. package/cjs/types/CamOverlayAPI.js +26 -0
  83. package/{types → cjs/types}/CamScripterAPI.d.ts +1 -1
  84. package/cjs/types/CamScripterAPI.js +20 -0
  85. package/{types → cjs/types}/CamStreamerAPI.d.ts +5 -5
  86. package/cjs/types/CamStreamerAPI.js +28 -0
  87. package/{types → cjs/types}/CamSwitcherAPI.d.ts +5 -5
  88. package/cjs/types/CamSwitcherAPI.js +137 -0
  89. package/{types/CamswitcherEvents.d.ts → cjs/types/CamSwitcherEvents.d.ts} +110 -0
  90. package/cjs/types/CamSwitcherEvents.js +70 -0
  91. package/{types → cjs/types}/VapixAPI.d.ts +442 -521
  92. package/cjs/types/VapixAPI.js +125 -0
  93. package/cjs/types/common.js +14 -0
  94. package/cjs/web/DefaultClient.d.ts +6 -0
  95. package/cjs/web/DefaultClient.js +22 -0
  96. package/cjs/web/WsClient.js +62 -0
  97. package/cjs/web/index.d.ts +2 -0
  98. package/cjs/web/index.js +7 -0
  99. package/esm/CamOverlayAPI.d.ts +629 -0
  100. package/esm/CamOverlayAPI.js +251 -0
  101. package/esm/CamOverlayDrawingAPI.d.ts +86 -0
  102. package/{CamOverlayDrawingAPI.js → esm/CamOverlayDrawingAPI.js} +6 -3
  103. package/esm/CamOverlayPainter/Frame.d.ts +96 -0
  104. package/esm/CamOverlayPainter/Painter.d.ts +48 -0
  105. package/{CamOverlayPainter → esm/CamOverlayPainter}/Painter.js +4 -1
  106. package/esm/CamOverlayPainter/ResourceManager.d.ts +14 -0
  107. package/{CamOverlayPainter → esm/CamOverlayPainter}/ResourceManager.js +6 -10
  108. package/esm/CamScripterAPI.d.ts +19 -0
  109. package/{CamScripterAPI.js → esm/CamScripterAPI.js} +3 -9
  110. package/esm/CamScripterAPICameraEventsGenerator.d.ts +74 -0
  111. package/{CamScripterAPICameraEventsGenerator.js → esm/CamScripterAPICameraEventsGenerator.js} +6 -3
  112. package/esm/CamStreamerAPI.d.ts +16 -0
  113. package/{CamStreamerAPI.js → esm/CamStreamerAPI.js} +4 -10
  114. package/esm/CamSwitcherAPI.d.ts +52 -0
  115. package/{CamSwitcherAPI.js → esm/CamSwitcherAPI.js} +24 -27
  116. package/esm/CamSwitcherEvents.d.ts +18 -0
  117. package/{CamSwitcherEvents.js → esm/CamSwitcherEvents.js} +1 -1
  118. package/esm/CreatePackage.d.ts +1 -0
  119. package/esm/VapixAPI.d.ts +78 -0
  120. package/{VapixAPI.js → esm/VapixAPI.js} +76 -56
  121. package/esm/VapixEvents.d.ts +43 -0
  122. package/{VapixEvents.js → esm/VapixEvents.js} +3 -3
  123. package/esm/errors/errors.d.ts +37 -0
  124. package/{errors → esm/errors}/errors.js +6 -0
  125. package/esm/events/AxisCameraStationEvents.d.ts +10 -0
  126. package/{events → esm/events}/AxisCameraStationEvents.js +1 -1
  127. package/esm/events/GenetecAgent.d.ts +174 -0
  128. package/{events → esm/events}/GenetecAgent.js +1 -1
  129. package/esm/index.d.ts +14 -0
  130. package/esm/index.js +14 -0
  131. package/esm/internal/Digest.d.ts +4 -0
  132. package/{internal → esm/internal}/Digest.js +6 -6
  133. package/esm/internal/ProxyClient.d.ts +11 -0
  134. package/{internal → esm/internal}/ProxyClient.js +4 -2
  135. package/esm/internal/constants.d.ts +1 -0
  136. package/esm/internal/transformers.d.ts +5 -0
  137. package/esm/internal/types.d.ts +35 -0
  138. package/esm/internal/types.js +1 -0
  139. package/esm/internal/utils.d.ts +15 -0
  140. package/{internal → esm/internal}/utils.js +21 -2
  141. package/esm/internal/versionCompare.d.ts +6 -0
  142. package/esm/models/CamOverlayAPI/accuweatherSchema.d.ts +84 -0
  143. package/esm/models/CamOverlayAPI/accuweatherSchema.js +45 -0
  144. package/esm/models/CamOverlayAPI/constants.d.ts +11 -0
  145. package/esm/models/CamOverlayAPI/constants.js +11 -0
  146. package/esm/models/CamOverlayAPI/customGraphicsSchema.d.ts +699 -0
  147. package/esm/models/CamOverlayAPI/customGraphicsSchema.js +70 -0
  148. package/esm/models/CamOverlayAPI/fileSchema.d.ts +28 -0
  149. package/esm/models/CamOverlayAPI/fileSchema.js +14 -0
  150. package/esm/models/CamOverlayAPI/imagesSchema.d.ts +95 -0
  151. package/esm/models/CamOverlayAPI/imagesSchema.js +7 -0
  152. package/esm/models/CamOverlayAPI/index.d.ts +13 -0
  153. package/esm/models/CamOverlayAPI/index.js +13 -0
  154. package/esm/models/CamOverlayAPI/infotickerSchema.d.ts +96 -0
  155. package/esm/models/CamOverlayAPI/infotickerSchema.js +24 -0
  156. package/esm/models/CamOverlayAPI/pipSchema.d.ts +125 -0
  157. package/esm/models/CamOverlayAPI/pipSchema.js +37 -0
  158. package/esm/models/CamOverlayAPI/ptzCompassSchema.d.ts +93 -0
  159. package/esm/models/CamOverlayAPI/ptzCompassSchema.js +23 -0
  160. package/esm/models/CamOverlayAPI/ptzSchema.d.ts +118 -0
  161. package/esm/models/CamOverlayAPI/ptzSchema.js +10 -0
  162. package/esm/models/CamOverlayAPI/screenSharingSchema.d.ts +58 -0
  163. package/esm/models/CamOverlayAPI/screenSharingSchema.js +6 -0
  164. package/esm/models/CamOverlayAPI/webCameraSharingSchema.d.ts +58 -0
  165. package/esm/models/CamOverlayAPI/webCameraSharingSchema.js +6 -0
  166. package/esm/models/CamOverlayAPI/widgetCommonSchema.d.ts +126 -0
  167. package/esm/models/CamOverlayAPI/widgetCommonSchema.js +73 -0
  168. package/esm/models/CamOverlayAPI/widgetsSchema.d.ts +2823 -0
  169. package/esm/models/CamOverlayAPI/widgetsSchema.js +24 -0
  170. package/esm/node/DefaultClient.d.ts +16 -0
  171. package/{node → esm/node}/DefaultClient.js +9 -7
  172. package/esm/node/HttpRequestSender.d.ts +28 -0
  173. package/esm/node/HttpServer.d.ts +21 -0
  174. package/{node → esm/node}/HttpServer.js +1 -1
  175. package/esm/node/WsClient.d.ts +39 -0
  176. package/esm/node/WsEventClient.d.ts +13 -0
  177. package/esm/node/index.d.ts +2 -0
  178. package/esm/node/index.js +2 -0
  179. package/esm/types/CamOverlayAPI.d.ts +328 -0
  180. package/esm/types/CamOverlayAPI.js +14 -0
  181. package/esm/types/CamScripterAPI.d.ts +67 -0
  182. package/esm/types/CamStreamerAPI.d.ts +139 -0
  183. package/esm/types/CamSwitcherAPI.d.ts +814 -0
  184. package/esm/types/CamSwitcherEvents.d.ts +568 -0
  185. package/{types/CamswitcherEvents.js → esm/types/CamSwitcherEvents.js} +12 -0
  186. package/esm/types/VapixAPI.d.ts +1625 -0
  187. package/{types → esm/types}/VapixAPI.js +16 -23
  188. package/esm/types/common.d.ts +37 -0
  189. package/esm/web/DefaultClient.d.ts +6 -0
  190. package/{web → esm/web}/DefaultClient.js +6 -4
  191. package/esm/web/WsClient.d.ts +13 -0
  192. package/esm/web/index.d.ts +2 -0
  193. package/esm/web/index.js +2 -0
  194. package/package.json +6 -6
  195. package/CamOverlayAPI.d.ts +0 -31
  196. package/CamOverlayAPI.js +0 -172
  197. package/internal/ProxyClient.d.ts +0 -11
  198. package/internal/common.d.ts +0 -40
  199. package/internal/common.js +0 -23
  200. package/node/DefaultClient.d.ts +0 -15
  201. package/types/CamOverlayAPI.d.ts +0 -188
  202. package/types/CamOverlayAPI.js +0 -44
  203. package/web/DefaultClient.d.ts +0 -6
  204. package/{CamOverlayPainter → cjs/CamOverlayPainter}/Frame.d.ts +0 -0
  205. package/{CamOverlayPainter → cjs/CamOverlayPainter}/ResourceManager.d.ts +0 -0
  206. package/{CreatePackage.d.ts → cjs/CreatePackage.d.ts} +0 -0
  207. package/{events → cjs/events}/GenetecAgent.d.ts +0 -0
  208. package/{internal → cjs/internal}/Digest.d.ts +0 -0
  209. package/{internal → cjs/internal}/constants.d.ts +0 -0
  210. package/{internal → cjs/internal}/transformers.d.ts +0 -0
  211. package/{node → cjs/node}/HttpRequestSender.d.ts +0 -0
  212. package/{node → cjs/node}/HttpServer.d.ts +0 -0
  213. package/{types → cjs/types}/common.d.ts +2 -2
  214. /package/{web → cjs/web}/WsClient.d.ts +0 -0
  215. /package/{CamOverlayPainter → esm/CamOverlayPainter}/Frame.js +0 -0
  216. /package/{CreatePackage.js → esm/CreatePackage.js} +0 -0
  217. /package/{internal → esm/internal}/constants.js +0 -0
  218. /package/{internal → esm/internal}/transformers.js +0 -0
  219. /package/{internal → esm/internal}/versionCompare.js +0 -0
  220. /package/{node → esm/node}/HttpRequestSender.js +0 -0
  221. /package/{node → esm/node}/WsClient.js +0 -0
  222. /package/{node → esm/node}/WsEventClient.js +0 -0
  223. /package/{types → esm/types}/CamScripterAPI.js +0 -0
  224. /package/{types → esm/types}/CamStreamerAPI.js +0 -0
  225. /package/{types → esm/types}/CamSwitcherAPI.js +0 -0
  226. /package/{types → esm/types}/common.js +0 -0
  227. /package/{web → esm/web}/WsClient.js +0 -0
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VapixEvents = void 0;
4
+ const eventemitter2_1 = require("eventemitter2");
5
+ const WsClient_1 = require("./node/WsClient");
6
+ class VapixEvents extends eventemitter2_1.EventEmitter2 {
7
+ tls;
8
+ tlsInsecure;
9
+ ip;
10
+ port;
11
+ user;
12
+ pass;
13
+ ws;
14
+ constructor(options = {}) {
15
+ super();
16
+ this.tls = options.tls ?? false;
17
+ this.tlsInsecure = options.tlsInsecure ?? false;
18
+ this.ip = options.ip ?? '127.0.0.1';
19
+ this.port = options.port ?? (this.tls ? 443 : 80);
20
+ this.user = options.user ?? 'root';
21
+ this.pass = options.pass ?? '';
22
+ this.createWsClient();
23
+ eventemitter2_1.EventEmitter2.call(this);
24
+ }
25
+ connect() {
26
+ this.ws.open();
27
+ }
28
+ disconnect() {
29
+ this.ws.close();
30
+ }
31
+ createWsClient() {
32
+ const options = {
33
+ tls: this.tls,
34
+ tlsInsecure: this.tlsInsecure,
35
+ user: this.user,
36
+ pass: this.pass,
37
+ ip: this.ip,
38
+ port: this.port,
39
+ address: '/vapix/ws-data-stream?sources=events',
40
+ };
41
+ this.ws = new WsClient_1.WsClient(options);
42
+ this.ws.on('open', () => {
43
+ const topics = [];
44
+ const eventNames = this.eventNames();
45
+ for (const eventName of eventNames) {
46
+ if (!this.isReservedEventName(eventName)) {
47
+ const topic = {
48
+ topicFilter: eventName,
49
+ };
50
+ topics.push(topic);
51
+ }
52
+ }
53
+ const topicFilter = {
54
+ apiVersion: '1.0',
55
+ method: 'events:configure',
56
+ params: {
57
+ eventFilterList: topics,
58
+ },
59
+ };
60
+ this.ws.send(JSON.stringify(topicFilter));
61
+ });
62
+ this.ws.on('message', (data) => {
63
+ const dataJSON = JSON.parse(data.toString());
64
+ if (dataJSON.method === 'events:configure') {
65
+ if (dataJSON.error === undefined) {
66
+ this.emit('open');
67
+ }
68
+ else {
69
+ this.emit('error', dataJSON.error);
70
+ this.disconnect();
71
+ }
72
+ return;
73
+ }
74
+ const eventName = dataJSON.params.notification.topic;
75
+ this.emit(eventName, dataJSON);
76
+ });
77
+ this.ws.on('error', (error) => {
78
+ this.emit('error', error);
79
+ });
80
+ this.ws.on('close', () => {
81
+ this.emit('close');
82
+ });
83
+ }
84
+ isReservedEventName(eventName) {
85
+ return eventName === 'open' || eventName === 'close' || eventName === 'error';
86
+ }
87
+ }
88
+ exports.VapixEvents = VapixEvents;
@@ -31,4 +31,7 @@ export declare class FetchDeviceInfoError extends Error {
31
31
  export declare class AddNewClipError extends Error {
32
32
  constructor(message: string);
33
33
  }
34
+ export declare class PtzNotSupportedError extends Error {
35
+ constructor();
36
+ }
34
37
  export {};
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PtzNotSupportedError = exports.AddNewClipError = exports.FetchDeviceInfoError = exports.NoDeviceInfoError = exports.MaxFPSError = exports.SDCardJobError = exports.SDCardActionError = exports.ApplicationAPIError = exports.ParsingBlobError = exports.ServiceNotFoundError = exports.ServiceUnavailableError = void 0;
4
+ class ServiceUnavailableError extends Error {
5
+ constructor() {
6
+ super('Service is unavailable.');
7
+ this.name = 'ServiceUnavailableError';
8
+ }
9
+ }
10
+ exports.ServiceUnavailableError = ServiceUnavailableError;
11
+ class ServiceNotFoundError extends Error {
12
+ constructor() {
13
+ super('Service not found.');
14
+ this.name = 'ServiceNotFoundError';
15
+ }
16
+ }
17
+ exports.ServiceNotFoundError = ServiceNotFoundError;
18
+ class ParsingBlobError extends Error {
19
+ constructor(err) {
20
+ super('Error parsing response as Blob: ' + err);
21
+ this.name = 'ParsingBlobError';
22
+ }
23
+ }
24
+ exports.ParsingBlobError = ParsingBlobError;
25
+ class ApplicationAPIError extends Error {
26
+ constructor(action, res) {
27
+ super(`[APP ${action}] Error: ` + res);
28
+ this.name = 'ApplicationAPIError';
29
+ }
30
+ }
31
+ exports.ApplicationAPIError = ApplicationAPIError;
32
+ class SDCardActionError extends Error {
33
+ constructor(action, res) {
34
+ super(`[SD_CARD ${action}] Error: ` + res);
35
+ this.name = 'SDCardActionError';
36
+ }
37
+ }
38
+ exports.SDCardActionError = SDCardActionError;
39
+ class SDCardJobError extends Error {
40
+ constructor() {
41
+ super('Error while fetching SD card job progress');
42
+ this.name = 'SDCardJobError';
43
+ }
44
+ }
45
+ exports.SDCardJobError = SDCardJobError;
46
+ const MAX_FPS_ERROR_MESSAGES = {
47
+ MALFORMED_REPLY: 'Malformed reply from camera',
48
+ CHANNEL_NOT_FOUND: 'Video channel not found.',
49
+ CAPTURE_MODE_NOT_FOUND: 'No enabled capture mode found.',
50
+ FPS_NOT_SPECIFIED: 'Max fps not specified for given capture mode.',
51
+ };
52
+ class MaxFPSError extends Error {
53
+ constructor(state) {
54
+ super(`[MAX_FPS ${state}] Error: ` + MAX_FPS_ERROR_MESSAGES[state]);
55
+ this.name = 'MaxFPSError';
56
+ }
57
+ }
58
+ exports.MaxFPSError = MaxFPSError;
59
+ class NoDeviceInfoError extends Error {
60
+ constructor() {
61
+ super('Did not get any data from remote camera');
62
+ this.name = 'NoDeviceInfoError';
63
+ }
64
+ }
65
+ exports.NoDeviceInfoError = NoDeviceInfoError;
66
+ class FetchDeviceInfoError extends Error {
67
+ constructor(err) {
68
+ super('Error fetching remote camera data: ' + err);
69
+ this.name = 'NoDeviceInfoFromCameraError';
70
+ }
71
+ }
72
+ exports.FetchDeviceInfoError = FetchDeviceInfoError;
73
+ class AddNewClipError extends Error {
74
+ constructor(message) {
75
+ super('Error adding new clip: ' + message);
76
+ this.name = 'AddNewClipError';
77
+ }
78
+ }
79
+ exports.AddNewClipError = AddNewClipError;
80
+ class PtzNotSupportedError extends Error {
81
+ constructor() {
82
+ super('Ptz not supported.');
83
+ this.name = 'PtzNotSupportedError';
84
+ }
85
+ }
86
+ exports.PtzNotSupportedError = PtzNotSupportedError;
@@ -1,9 +1,10 @@
1
- import { IClient, HttpOptions } from '../internal/common';
1
+ import { IClient, HttpOptions } from '../internal/types';
2
+ import { Response } from 'undici';
2
3
  export type AcsEventsOptions = HttpOptions;
3
4
  export declare class AxisCameraStationEvents {
4
5
  private sourceKey;
5
6
  private client;
6
- constructor(sourceKey: string, opt?: AcsEventsOptions | IClient);
7
+ constructor(sourceKey: string, opt?: AcsEventsOptions | IClient<Response>);
7
8
  sendEvent(data: Record<string, string>, eventType: string): Promise<void>;
8
9
  private getDate;
9
10
  }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AxisCameraStationEvents = void 0;
4
+ const DefaultClient_1 = require("../node/DefaultClient");
5
+ const utils_1 = require("../internal/utils");
6
+ class AxisCameraStationEvents {
7
+ sourceKey;
8
+ client;
9
+ constructor(sourceKey, opt = {}) {
10
+ this.sourceKey = sourceKey;
11
+ if ((0, utils_1.isClient)(opt)) {
12
+ this.client = opt;
13
+ }
14
+ else {
15
+ this.client = new DefaultClient_1.DefaultClient(opt);
16
+ }
17
+ }
18
+ async sendEvent(data, eventType) {
19
+ const dateString = this.getDate();
20
+ const event = {
21
+ addExternalDataRequest: {
22
+ occurrenceTime: dateString,
23
+ source: this.sourceKey,
24
+ externalDataType: eventType,
25
+ data: data,
26
+ },
27
+ };
28
+ const eventData = JSON.stringify(event);
29
+ const res = await this.client.post('/Acs/Api/ExternalDataFacade/AddExternalData', eventData, undefined, {
30
+ 'Content-Type': 'application/json',
31
+ 'Content-Length': eventData.length.toString(),
32
+ });
33
+ if (!res.ok) {
34
+ throw new Error(`ACS status code: ${res.status}`);
35
+ }
36
+ }
37
+ getDate() {
38
+ const date = new Date();
39
+ const year = date.getUTCFullYear();
40
+ const month = (0, utils_1.pad)(date.getUTCMonth() + 1, 2);
41
+ const day = (0, utils_1.pad)(date.getUTCDate(), 2);
42
+ const hours = (0, utils_1.pad)(date.getUTCHours(), 2);
43
+ const minutes = (0, utils_1.pad)(date.getUTCMinutes(), 2);
44
+ const seconds = (0, utils_1.pad)(date.getUTCSeconds(), 2);
45
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
46
+ }
47
+ }
48
+ exports.AxisCameraStationEvents = AxisCameraStationEvents;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GenetecAgent = exports.cameraDetailsResponseSchema = exports.cameraDetailSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const utils_1 = require("../internal/utils");
6
+ const ACTION = 'AddCameraBookmark';
7
+ const GET_CAMERAS_URL = 'report/EntityConfiguration?q=EntityTypes@Camera';
8
+ const GET_CAMERAS_DETAILS_URL = '/entity?q=';
9
+ const cameraGuidsResponseSchema = zod_1.z.object({
10
+ Rsp: zod_1.z.object({
11
+ Status: zod_1.z.string(),
12
+ Result: zod_1.z.array(zod_1.z.object({ Guid: zod_1.z.string() })),
13
+ }),
14
+ });
15
+ const connectionResponseSchema = zod_1.z.object({
16
+ Rsp: zod_1.z.object({
17
+ Status: zod_1.z.string(),
18
+ }),
19
+ });
20
+ exports.cameraDetailSchema = zod_1.z.object({
21
+ Guid: zod_1.z.string().optional(),
22
+ Name: zod_1.z.string().optional(),
23
+ EntityType: zod_1.z.string().optional(),
24
+ });
25
+ exports.cameraDetailsResponseSchema = zod_1.z.object({
26
+ Rsp: zod_1.z.object({
27
+ Status: zod_1.z.string(),
28
+ Result: zod_1.z.union([zod_1.z.array(exports.cameraDetailSchema), exports.cameraDetailSchema]),
29
+ }),
30
+ });
31
+ class GenetecAgent {
32
+ settings;
33
+ baseUrl;
34
+ credentials;
35
+ constructor(options = {}) {
36
+ this.settings = {
37
+ protocol: options.protocol ?? 'http',
38
+ ip: options.ip ?? '127.0.0.1',
39
+ port: options.port ?? 80,
40
+ base_uri: options.base_uri ?? 'WebSdk',
41
+ user: options.user ?? 'root',
42
+ pass: options.pass ?? '',
43
+ app_id: options.app_id ?? '',
44
+ };
45
+ this.baseUrl = `${this.settings.protocol}://${this.settings.ip}:${this.settings.port}/${this.settings.base_uri}`;
46
+ this.credentials = btoa(`${this.settings.user};${this.settings.app_id}:${this.settings.pass}`);
47
+ }
48
+ async checkConnection() {
49
+ const requestOptions = this.getRequestOptions('GET');
50
+ const res = await fetch(`${this.baseUrl}/`, requestOptions);
51
+ if (!res.ok) {
52
+ throw new Error(await (0, utils_1.responseStringify)(res));
53
+ }
54
+ return connectionResponseSchema.parse(await res.json());
55
+ }
56
+ async getAllCameraGuids() {
57
+ const requestOptions = this.getRequestOptions('GET');
58
+ const res = await fetch(`${this.baseUrl}/${GET_CAMERAS_URL}`, requestOptions);
59
+ if (!res.ok) {
60
+ throw new Error(await (0, utils_1.responseStringify)(res));
61
+ }
62
+ return cameraGuidsResponseSchema.parse(await res.json());
63
+ }
64
+ async getCameraDetails(guids, parameters) {
65
+ const params = parameters.join(',');
66
+ let camerasGuids = [];
67
+ const requestOptions = this.getRequestOptions('GET');
68
+ const allCameras = [];
69
+ const chunkSize = 10;
70
+ while (guids.length > 0) {
71
+ const chunk = guids.slice(0, chunkSize);
72
+ guids.splice(0, chunkSize);
73
+ camerasGuids = chunk.map((item) => item.Guid);
74
+ const camerasDetailsUrl = [];
75
+ for (const guid of camerasGuids) {
76
+ camerasDetailsUrl.push(`entity=${guid},${params}`);
77
+ }
78
+ const res = await fetch(`${this.baseUrl}/${GET_CAMERAS_DETAILS_URL}${camerasDetailsUrl.join(',')}`, requestOptions);
79
+ if (!res.ok) {
80
+ throw new Error(await (0, utils_1.responseStringify)(res));
81
+ }
82
+ const data = exports.cameraDetailsResponseSchema.parse(await res.json());
83
+ const resultArray = Array.isArray(data.Rsp.Result) ? data.Rsp.Result : [data.Rsp.Result];
84
+ allCameras.push(...resultArray);
85
+ }
86
+ return allCameras;
87
+ }
88
+ async sendBookmark(guids, bookmarkText) {
89
+ const cameraEntitiesUrl = [];
90
+ const timeStamp = this.getTimeStamp();
91
+ const requestOptions = this.getRequestOptions('POST');
92
+ for (const guid of guids) {
93
+ cameraEntitiesUrl.push(`${ACTION}(${guid},${timeStamp},${bookmarkText})`);
94
+ }
95
+ const res = await fetch(`${this.baseUrl}/action?q=${cameraEntitiesUrl.join(',')}`, requestOptions);
96
+ if (!res.ok) {
97
+ throw new Error(await (0, utils_1.responseStringify)(res));
98
+ }
99
+ return res;
100
+ }
101
+ getRequestOptions(method) {
102
+ return {
103
+ method,
104
+ headers: new Headers({
105
+ Authorization: `Basic ${this.credentials}`,
106
+ Accept: 'text/json',
107
+ }),
108
+ redirect: 'follow',
109
+ };
110
+ }
111
+ getTimeStamp() {
112
+ const date = new Date();
113
+ const year = date.getUTCFullYear();
114
+ const month = (0, utils_1.pad)(date.getUTCMonth() + 1, 2);
115
+ const day = (0, utils_1.pad)(date.getUTCDate(), 2);
116
+ const hours = (0, utils_1.pad)(date.getUTCHours(), 2);
117
+ const minutes = (0, utils_1.pad)(date.getUTCMinutes(), 2);
118
+ const seconds = (0, utils_1.pad)(date.getUTCSeconds(), 2);
119
+ const miliSeconds = (0, utils_1.pad)(date.getUTCMilliseconds(), 2);
120
+ return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${miliSeconds}Z`;
121
+ }
122
+ }
123
+ exports.GenetecAgent = GenetecAgent;
package/cjs/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export * from './internal/types';
2
+ export * from './internal/constants';
3
+ export * from './internal/utils';
4
+ export * from './internal/versionCompare';
5
+ export * from './types/common';
6
+ export { CamSwitcherAPI } from './CamSwitcherAPI';
7
+ export { CamSwitcherEvents } from './CamSwitcherEvents';
8
+ export { VapixAPI } from './VapixAPI';
9
+ export { CamOverlayAPI } from './CamOverlayAPI';
10
+ export * from './types/CamSwitcherEvents';
11
+ export * from './types/CamSwitcherAPI';
12
+ export * from './types/VapixAPI';
13
+ export * from './types/CamOverlayAPI';
14
+ export * from './models/CamOverlayAPI';
package/cjs/index.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.CamOverlayAPI = exports.VapixAPI = exports.CamSwitcherEvents = exports.CamSwitcherAPI = void 0;
18
+ __exportStar(require("./internal/types"), exports);
19
+ __exportStar(require("./internal/constants"), exports);
20
+ __exportStar(require("./internal/utils"), exports);
21
+ __exportStar(require("./internal/versionCompare"), exports);
22
+ __exportStar(require("./types/common"), exports);
23
+ var CamSwitcherAPI_1 = require("./CamSwitcherAPI");
24
+ Object.defineProperty(exports, "CamSwitcherAPI", { enumerable: true, get: function () { return CamSwitcherAPI_1.CamSwitcherAPI; } });
25
+ var CamSwitcherEvents_1 = require("./CamSwitcherEvents");
26
+ Object.defineProperty(exports, "CamSwitcherEvents", { enumerable: true, get: function () { return CamSwitcherEvents_1.CamSwitcherEvents; } });
27
+ var VapixAPI_1 = require("./VapixAPI");
28
+ Object.defineProperty(exports, "VapixAPI", { enumerable: true, get: function () { return VapixAPI_1.VapixAPI; } });
29
+ var CamOverlayAPI_1 = require("./CamOverlayAPI");
30
+ Object.defineProperty(exports, "CamOverlayAPI", { enumerable: true, get: function () { return CamOverlayAPI_1.CamOverlayAPI; } });
31
+ __exportStar(require("./types/CamSwitcherEvents"), exports);
32
+ __exportStar(require("./types/CamSwitcherAPI"), exports);
33
+ __exportStar(require("./types/VapixAPI"), exports);
34
+ __exportStar(require("./types/CamOverlayAPI"), exports);
35
+ __exportStar(require("./models/CamOverlayAPI"), exports);
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Digest = void 0;
4
+ const crypto = require("crypto");
5
+ class Digest {
6
+ nonceCount = 1;
7
+ getAuthHeader(user, pass, method, uri, wwwAuthenticateHeader) {
8
+ const digestItems = {};
9
+ const digestArr = wwwAuthenticateHeader.substring(wwwAuthenticateHeader.indexOf('Digest') + 6).split(',');
10
+ for (const arg of digestArr) {
11
+ const pos = arg.indexOf('=');
12
+ const key = arg.substring(0, pos).trim();
13
+ const value = arg.substring(pos + 1).trim();
14
+ digestItems[key] = value.replace(/"/g, '');
15
+ }
16
+ const HA1 = crypto.createHash('md5').update(`${user}:${digestItems['realm']}:${pass}`).digest('hex');
17
+ const HA2 = crypto.createHash('md5').update(`${method}:${uri}`).digest('hex');
18
+ const ncValue = ('00000000' + this.nonceCount.toString(16)).slice(-8);
19
+ let response;
20
+ if (digestItems['qop'] !== undefined) {
21
+ response = crypto
22
+ .createHash('md5')
23
+ .update(`${HA1}:${digestItems['nonce']}:${ncValue}:162d50aa594e9648:auth:${HA2}`)
24
+ .digest('hex');
25
+ }
26
+ else {
27
+ response = crypto.createHash('md5').update(`${HA1}:${digestItems['nonce']}:${HA2}`).digest('hex');
28
+ }
29
+ let header = 'Digest ' +
30
+ `username="${user}",` +
31
+ `realm="${digestItems['realm']}",` +
32
+ `nonce="${digestItems['nonce']}",` +
33
+ `uri="${uri}",` +
34
+ `response="${response}"`;
35
+ if (digestItems['qop'] !== undefined) {
36
+ header += `,qop=auth,nc=${ncValue},cnonce="162d50aa594e9648"`;
37
+ }
38
+ this.nonceCount++;
39
+ return header;
40
+ }
41
+ }
42
+ exports.Digest = Digest;
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import { IClient, TResponse } from './types';
3
+ import { TProxyParam } from '../types/common';
4
+ export declare class ProxyClient<Client extends IClient<TResponse> = IClient<TResponse>> {
5
+ client: Client;
6
+ getProxyUrl: () => string;
7
+ constructor(client: Client, getProxyUrl: () => string);
8
+ get: (proxy: TProxyParam, url: string, parameters?: import("./types").TParameters | undefined, headers?: Record<string, string> | undefined) => Promise<TResponse>;
9
+ post: (proxy: TProxyParam, url: string, data: string | Buffer | FormData, parameters?: import("./types").TParameters | undefined, headers?: Record<string, string> | undefined) => Promise<TResponse>;
10
+ private getReal;
11
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProxyClient = void 0;
4
+ const utils_1 = require("./utils");
5
+ class ProxyClient {
6
+ client;
7
+ getProxyUrl;
8
+ constructor(client, getProxyUrl) {
9
+ this.client = client;
10
+ this.getProxyUrl = getProxyUrl;
11
+ }
12
+ get = (proxy, ...args) => {
13
+ const [path, parameters, headers] = args;
14
+ const url = (0, utils_1.addParametersToPath)(path, parameters);
15
+ const { realUrl, realHeaders } = this.getReal(proxy, url, headers);
16
+ return this.client.get(realUrl, {}, realHeaders);
17
+ };
18
+ post = (proxy, ...args) => {
19
+ const [path, data, parameters, headers] = args;
20
+ const url = (0, utils_1.addParametersToPath)(path, parameters);
21
+ const { realUrl, realHeaders } = this.getReal(proxy, url, headers);
22
+ return this.client.post(realUrl, data, {}, realHeaders);
23
+ };
24
+ getReal = (proxy, url, headers) => {
25
+ if (proxy !== null) {
26
+ return {
27
+ realUrl: this.getProxyUrl(),
28
+ realHeaders: {
29
+ ...(headers ?? {}),
30
+ 'x-target-camera-protocol': proxy.port === 443 ? 'https' : 'http',
31
+ 'x-target-camera-path': url,
32
+ 'x-target-camera-ip': proxy.ip,
33
+ 'x-target-camera-mdns': proxy.mdnsName,
34
+ 'x-target-camera-port': String(proxy.port),
35
+ 'x-target-camera-pass': encodeURIComponent(proxy.pass),
36
+ 'x-target-camera-user': encodeURIComponent(proxy.user),
37
+ },
38
+ };
39
+ }
40
+ return {
41
+ realUrl: url,
42
+ realHeaders: headers,
43
+ };
44
+ };
45
+ }
46
+ exports.ProxyClient = ProxyClient;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FIRMWARE_WITH_BITRATE_MODES_SUPPORT = void 0;
4
+ exports.FIRMWARE_WITH_BITRATE_MODES_SUPPORT = '11.11.73';
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toSnakeCaseDeep = exports.toSnakeCase = exports.toCamelCaseDeep = exports.toCamelCase = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const toCamelCase = (o) => (0, lodash_1.mapKeys)(o, camelCaseKey);
6
+ exports.toCamelCase = toCamelCase;
7
+ const toCamelCaseDeep = (o) => {
8
+ return mapKeysDeep(o, camelCaseKey);
9
+ };
10
+ exports.toCamelCaseDeep = toCamelCaseDeep;
11
+ const toSnakeCase = (o) => (0, lodash_1.mapKeys)(o, snakeCaseKey);
12
+ exports.toSnakeCase = toSnakeCase;
13
+ const toSnakeCaseDeep = (o) => {
14
+ return mapKeysDeep(o, snakeCaseKey);
15
+ };
16
+ exports.toSnakeCaseDeep = toSnakeCaseDeep;
17
+ const camelCaseKey = (_, key) => (0, lodash_1.camelCase)(key);
18
+ const snakeCaseKey = (_, key) => (0, lodash_1.snakeCase)(key);
19
+ const mapKeysDeep = (obj, cb) => {
20
+ if (Array.isArray(obj)) {
21
+ return obj.map((item) => {
22
+ return mapKeysDeep(item, cb);
23
+ });
24
+ }
25
+ if (typeof obj !== 'object' || (0, lodash_1.isPlainObject)(obj) === false) {
26
+ return obj;
27
+ }
28
+ const result = (0, lodash_1.mapKeys)(obj, cb);
29
+ return (0, lodash_1.mapValues)(result, (value) => {
30
+ return mapKeysDeep(value, cb);
31
+ });
32
+ };
@@ -0,0 +1,35 @@
1
+ /// <reference types="node" />
2
+ import { Response as UndiciResponse } from 'undici';
3
+ export type Options = {
4
+ ip?: string;
5
+ port?: number;
6
+ user?: string;
7
+ pass?: string;
8
+ tls?: boolean;
9
+ tlsInsecure?: boolean;
10
+ };
11
+ export type HttpOptions = Options & {
12
+ keepAlive?: boolean;
13
+ };
14
+ export type WsOptions = Options;
15
+ export type TParameters = Record<string, string | number | boolean | null | undefined>;
16
+ export type TResponse = Response | UndiciResponse;
17
+ export type TGetParams = [url: string, parameters?: TParameters, headers?: Record<string, string>];
18
+ export type TPostParams = [
19
+ url: string,
20
+ data: string | Buffer | FormData,
21
+ parameters?: TParameters,
22
+ headers?: Record<string, string>
23
+ ];
24
+ export interface IClient<TRes extends TResponse> {
25
+ get: (...params: TGetParams) => Promise<TRes>;
26
+ post: (...params: TPostParams) => Promise<TRes>;
27
+ }
28
+ export type TBlobResponse<Client extends IClient<TResponse>> = Awaited<ReturnType<Awaited<ReturnType<Client['get']>>['blob']>>;
29
+ export interface IWebsocket<Event extends {
30
+ readonly data: string;
31
+ }> {
32
+ destroy: () => void;
33
+ onmessage: null | ((event: Event) => void);
34
+ send: (data: string) => void;
35
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
1
  import { TPlaylistPlayType } from '../types/CamSwitcherAPI';
2
- import { TParameters } from './common';
2
+ import { IClient, Options, TParameters, TResponse } from './types';
3
3
  export declare const addParametersToPath: (path: string, params?: TParameters) => string;
4
4
  export declare const paramToUrl: (params?: TParameters) => string;
5
5
  export declare const arrayToUrl: (arr: string | string[]) => string;
@@ -9,3 +9,7 @@ export declare const isClip: (id?: string) => boolean;
9
9
  export declare const isTracker: (id?: string) => boolean;
10
10
  export declare const isPlaylist: (id?: string) => boolean;
11
11
  export declare const isLoopPlayType: (playType: TPlaylistPlayType) => boolean;
12
+ export declare function isClient(arg?: Options | IClient<TResponse>): arg is IClient<TResponse>;
13
+ export declare function responseStringify(res: TResponse): Promise<string>;
14
+ export declare function pad(num: number, size: number): string;
15
+ export declare function isNullish<T>(value: T | undefined | null): value is undefined | null;