camstreamerlib 4.0.0-beta.47 → 4.0.0-beta.49

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 (70) hide show
  1. package/README.md +123 -30
  2. package/cjs/CamSwitcherAPI.js +1 -1
  3. package/cjs/PlaneTrackerAPI.js +7 -2
  4. package/cjs/index.js +18 -9
  5. package/cjs/internal/WsEvents.js +6 -5
  6. package/cjs/node/CamOverlayDrawingAPI.js +10 -10
  7. package/cjs/node/CamScripterAPICameraEventsGenerator.js +9 -9
  8. package/cjs/node/Digest.test.js +13 -0
  9. package/cjs/node/VapixEvents.js +9 -9
  10. package/cjs/node/WsClient.js +20 -13
  11. package/cjs/types/CamOverlayAPI/pipSchema.js +1 -1
  12. package/cjs/types/PlaneTrackerAPI.js +4 -1
  13. package/cjs/types/ws/CamOverlayEvents.js +19 -0
  14. package/cjs/types/ws/CamStreamerEvents.js +32 -0
  15. package/cjs/types/ws/PlaneTrackerEvents.js +103 -0
  16. package/cjs/web/DefaultClient.js +6 -2
  17. package/cjs/web/WsClient.js +13 -15
  18. package/cjs/ws/CamOverlayEvents.js +24 -0
  19. package/cjs/ws/CamStreamerEvents.js +24 -0
  20. package/cjs/ws/CamSwitcherEvents.js +24 -0
  21. package/cjs/ws/PlaneTrackerEvents.js +22 -0
  22. package/esm/CamSwitcherAPI.js +1 -1
  23. package/esm/PlaneTrackerAPI.js +8 -3
  24. package/esm/index.js +12 -6
  25. package/esm/internal/WsEvents.js +6 -5
  26. package/esm/node/CamOverlayDrawingAPI.js +10 -10
  27. package/esm/node/CamScripterAPICameraEventsGenerator.js +9 -9
  28. package/esm/node/Digest.test.js +11 -0
  29. package/esm/node/VapixEvents.js +9 -9
  30. package/esm/node/WsClient.js +20 -13
  31. package/esm/types/CamOverlayAPI/pipSchema.js +1 -1
  32. package/esm/types/PlaneTrackerAPI.js +3 -0
  33. package/esm/types/ws/CamOverlayEvents.js +16 -0
  34. package/esm/types/ws/CamStreamerEvents.js +29 -0
  35. package/esm/types/ws/PlaneTrackerEvents.js +100 -0
  36. package/esm/web/DefaultClient.js +6 -2
  37. package/esm/web/WsClient.js +13 -15
  38. package/esm/ws/CamOverlayEvents.js +20 -0
  39. package/esm/ws/CamStreamerEvents.js +20 -0
  40. package/esm/ws/CamSwitcherEvents.js +20 -0
  41. package/esm/ws/PlaneTrackerEvents.js +18 -0
  42. package/package.json +1 -1
  43. package/types/CamSwitcherAPI.d.ts +1 -1
  44. package/types/PlaneTrackerAPI.d.ts +4 -2
  45. package/types/index.d.ts +12 -6
  46. package/types/internal/WsEvents.d.ts +3 -5
  47. package/types/internal/types.d.ts +7 -6
  48. package/types/node/CamScripterAPICameraEventsGenerator.d.ts +2 -2
  49. package/types/node/Digest.test.d.ts +1 -0
  50. package/types/node/VapixEvents.d.ts +2 -2
  51. package/types/node/WsClient.d.ts +9 -19
  52. package/types/types/CamOverlayAPI/CamOverlayAPI.d.ts +5 -5
  53. package/types/types/CamOverlayAPI/pipSchema.d.ts +2 -2
  54. package/types/types/CamOverlayDrawingAPI.d.ts +2 -2
  55. package/types/types/PlaneTrackerAPI.d.ts +8 -0
  56. package/types/types/ws/CamOverlayEvents.d.ts +88 -0
  57. package/types/types/ws/CamStreamerEvents.d.ts +249 -0
  58. package/types/types/ws/PlaneTrackerEvents.d.ts +960 -0
  59. package/types/web/DefaultClient.d.ts +2 -0
  60. package/types/web/WsClient.d.ts +9 -5
  61. package/types/ws/CamOverlayEvents.d.ts +8 -0
  62. package/types/ws/CamStreamerEvents.d.ts +8 -0
  63. package/types/ws/CamSwitcherEvents.d.ts +8 -0
  64. package/types/ws/PlaneTrackerEvents.d.ts +9 -0
  65. package/cjs/CamSwitcherEvents.js +0 -11
  66. package/esm/CamSwitcherEvents.js +0 -7
  67. package/types/CamSwitcherEvents.d.ts +0 -8
  68. /package/cjs/types/{CamSwitcherEvents.js → ws/CamSwitcherEvents.js} +0 -0
  69. /package/esm/types/{CamSwitcherEvents.js → ws/CamSwitcherEvents.js} +0 -0
  70. /package/types/types/{CamSwitcherEvents.d.ts → ws/CamSwitcherEvents.d.ts} +0 -0
package/README.md CHANGED
@@ -17,61 +17,154 @@ npm install camstreamerlib
17
17
 
18
18
  ## Documentation for ACAP and Camera API
19
19
 
20
-
21
- | API | Description |
22
- | ------------- | ------------- |
23
- | [VapixAPI](doc/VapixAPI.md) | Module to access Axis camera VAPIX interface. |
24
- | [CamStreamerAPI](doc/CamStreamerAPI.md) | Module for easy control of video streaming in the CamStreamer ACAP application (RTMP, HLS, SRT and MPEG-TS protocols). |
25
- | [CamOverlayAPI](doc/CamOverlayAPI.md) | Module to access CamOverlay API. |
26
- | [CamScripterAPI](doc/CamScripterAPI.md) | Module to access CamScripter API. |
27
- | [CamSwitcherAPI](doc/CamSwitcherAPI.md) | Module to access CamSwitcher API. |
28
- | [PlaneTrackerAPI](doc/PlaneTrackerAPI.md) | Module to access PlaneTracker API. |
20
+ | API | Description |
21
+ | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
22
+ | [VapixAPI](doc/VapixAPI.md) | Module to access Axis camera VAPIX interface. |
23
+ | [CamStreamerAPI](doc/CamStreamerAPI.md) | Module for easy control of video streaming in the CamStreamer ACAP application (RTMP, HLS, SRT and MPEG-TS protocols). |
24
+ | [CamOverlayAPI](doc/CamOverlayAPI.md) | Module to access CamOverlay API. |
25
+ | [CamScripterAPI](doc/CamScripterAPI.md) | Module to access CamScripter API. |
26
+ | [CamSwitcherAPI](doc/CamSwitcherAPI.md) | Module to access CamSwitcher API. |
27
+ | [PlaneTrackerAPI](doc/PlaneTrackerAPI.md) | Module to access PlaneTracker API. |
28
+ | [CamStreamerEvents](doc/ws/CamStreamerEvents.md) | Module which allows receiving events from CamStreamer ACAP application. |
29
+ | [OverlayEvents](doc/ws/OverlayEvents.md) | Module which allows receiving events from Overlay ACAP application. |
30
+ | [CamSwitcherEvents](doc/ws/CamSwitcherEvents.md) | Module which allows receiving events from CamSwitcher ACAP application. |
31
+ | [PlaneTrackerEvents](doc/ws/PlaneTrackerEvents.md) | Module which allows receiving events from PlaneTracker ACAP application. |
29
32
 
30
33
  ## Documentation for Node.js modules
31
34
 
32
- | Module | Description |
33
- | ------------- | ------------- |
34
- | [HttpServer](doc/HttpServer.md) | Module for processing HTTP requests in your scripts. It also automatically serves up the content from html directory or you can register paths which you can process by your own (e.g. `http://$CAMERA_IP/local/camscripter/proxy/$MY_PACKAGE_NAME/control.cgi`). |
35
- | [VapixEvents](doc/VapixEvents.md) | Module which allows receiving camera events from the VAPIX API. |
36
- | [CamOverlayDrawingAPI](doc/CamOverlayDrawingAPI.md) | Module for easy control of CamOverlay drawing API. For more details on supported video overlay drawing functions see https://camstreamer.com/camoverlay-api1 |
37
- | [CamOverlayPainter](doc/CamOverlayPainter.md) | Contains three modules which makes easier to use CamOverlayDrawingAPI. |
38
- | [CamScripterAPICameraEventsGenerator](doc/CamScripterAPICameraEventsGenerator.md) | Module which allows generating events on an Axis camera. These events can be used for triggers in the Axis camera rule engine (events/actions). It is also an easy way how to integrate events and metadata in VMS systems which support Axis camera events. |
39
- | [CamSwitcherEvents](doc/CamSwitcherEvents.md) | Module which allows receiving events from CamSwitcher ACAP application. |
40
- | [GenetecAgent](doc/GenetecAgent.md) | Module which allows receiving and sending data to Genetec VMS. |
35
+ | Module | Description |
36
+ | --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
37
+ | [HttpServer](doc/HttpServer.md) | Module for processing HTTP requests in your scripts. It also automatically serves up the content from html directory or you can register paths which you can process by your own (e.g. `http://$CAMERA_IP/local/camscripter/proxy/$MY_PACKAGE_NAME/control.cgi`). |
38
+ | [VapixEvents](doc/ws/VapixEvents.md) | Module which allows receiving camera events from the VAPIX API. |
39
+ | [CamOverlayDrawingAPI](doc/CamOverlayDrawingAPI.md) | Module for easy control of CamOverlay drawing API. For more details on supported video overlay drawing functions see https://camstreamer.com/camoverlay-api1 |
40
+ | [CamOverlayPainter](doc/CamOverlayPainter.md) | Contains three modules which makes easier to use CamOverlayDrawingAPI. |
41
+ | [CamScripterAPICameraEventsGenerator](doc/CamScripterAPICameraEventsGenerator.md) | Module which allows generating events on an Axis camera. These events can be used for triggers in the Axis camera rule engine (events/actions). It is also an easy way how to integrate events and metadata in VMS systems which support Axis camera events. |
42
+ | [GenetecAgent](doc/GenetecAgent.md) | Module which allows receiving and sending data to Genetec VMS. |
43
+
44
+ </br>
45
+
46
+ # Breaking Changes
47
+
48
+ <details open>
49
+
50
+ <summary>from version 3.\*.\* to 4.\*.\* (latest)</summary>
51
+
52
+ ### Breaking changes when moving from version 3.\*.\* to 4.\*.\* (latest)
53
+
54
+ <hr/>
55
+
56
+ ### ACAP API Class Constructors Updated
57
+
58
+ All ACAP API classes now **require a client instance to be passed into their constructors** instead of options object.
41
59
 
60
+ - This change improves flexibility by allowing you to use either the Node or Web client, depending on your environment.
42
61
 
43
- ## Breaking changes when moving from version 3.\*.\* to 4.\*.\* (latest)
62
+ Example (before now):
44
63
 
45
- ...
64
+ ```typescript
65
+ // Before
66
+ const coApi = new CamOverlayAPI({
67
+ ip?: string;
68
+ port?: number;
69
+ user?: string;
70
+ pass?: string;
71
+ tls?: boolean;
72
+ tlsInsecure?: boolean;
73
+ keepAlive?: boolean
74
+ });
75
+
76
+ // Now
77
+ import { DefaultClient } from 'camstreamerlib/web';
78
+ import { CamOverlayAPI } from 'camstreamerlib';
79
+
80
+ const coApi = new CamOverlayAPI(
81
+ new DefaultClient({
82
+ tls: false,
83
+ tlsInsecure: false,
84
+ ip: '127.0.0.1',
85
+ port: 80,
86
+ user: '',
87
+ pass: '',
88
+ })
89
+ );
90
+ ```
91
+
92
+ ### Imports Simplified
93
+
94
+ Importing from the camstreamerlib is now much easier -> all exports are now re-exported from the root index.js.
95
+ You no longer need to import from subpaths.
96
+
97
+ Example:
98
+
99
+ ```typescript
100
+ // Before
101
+ import { CamScripterAPI } from 'camstreamerlib/CamScripterAPI';
102
+ import { Painter } from 'camstreamerlib/CamOverlayPainter/Painter';
103
+ import { DefaultAgent } from 'camstreamerlib/DefaultAgent';
104
+
105
+ // Now
106
+ import { CamScripterAPI } from 'camstreamerlib';
107
+ import { Painter } from 'camstreamerlib/node';
108
+ import { DefaultClient } from 'camstreamerlib/web';
109
+ ```
46
110
 
111
+ > Note: To ensure compatibility, set the module resolution in your projects tsconfig.json to `"moduleResolution": "bundler"`.
47
112
 
48
- ## Breaking changes when moving from version 2.\*.\* to 3.\*.\*
113
+ ### Class and Method Refactored
114
+
115
+ - **CameraVapix API** has been renamed to [**VapixAPI**](doc/VapixAPI.md).
116
+ - **DefaultAgent** has been refactored into two separate classes - one for node, one for web as [**DefaultClient**](doc/Client.md)
117
+ - Several method names and parameter names across the library have been updated for consistency and clarity.
118
+
119
+ > Please refer to [the documentation](#documentation-for-acap-and-camera-api).
120
+
121
+ - New API modules and endpoints have been introduced, providing extended functionality and better coverage of the underlying service.
122
+
123
+ <hr/>
124
+ </details>
125
+
126
+ <details>
127
+
128
+ <summary>from version 2.\*.\* to 3.\*.\*</summary>
129
+
130
+ ### Breaking changes when moving from version 2.\*.\* to 3.\*.\*
49
131
 
50
132
  - CamStreamerlib requiers Node.js version 18 or higher.
51
133
  - CamOverlayDrawingAPI tries to reconnect when the websocket is closed. You don't have to do it manually.
52
- > [!NOTE]
53
- > However, events `open` and `close` are still emitted in case you need to react to them.
134
+
135
+ > However, events `open` and `close` are still emitted in case you need to react to them.
136
+
54
137
  - Files `common.ts`, `Digest.ts`, `HttpRequest.ts` and `WsClient.ts` moved to a folder internal.
55
138
  - Removed function `httpRequest()`. Use `sendRequest()` instead. It uses the same interface except for the "noWaitForData" parameter.
56
- > [!IMPORTANT]
139
+
57
140
  > It returns (Response object)[https://developer.mozilla.org/en-US/docs/Web/API/Response] which doesn't contain data by default.
58
141
  > If you need to wait for data, you can call for example the function `await res.text()`.
59
142
  > This change affects the function `vapixGet` from (CameraVapix)[doc/CameraVapix.md] too.
60
143
 
61
- ## Breaking changes when moving from version 1.\*.\* to 2.\*.\*
144
+ <hr/>
145
+ </details>
146
+
147
+ <details>
148
+
149
+ <summary>from version 1.\*.\* to 2.\*.\**</summary>
150
+
151
+ ### Breaking changes when moving from version 1.\*.\* to 2.\*.\*
62
152
 
63
153
  - Renamed file HTTPRequest.ts to HttpRequest.ts
64
154
  - Removed deprecated protocol attribute from all options objects (use tls instead).
65
155
  - Removed RTSP
66
- > [!IMPORTANT]
67
- > Previously CameraVapix.ts supported both WebSocket and RTSP.
68
- > Starting with version 2.0.0, it supports WebSocket only.
156
+
157
+ > Previously CameraVapix.ts supported both WebSocket and RTSP.
158
+ > Starting with version 2.0.0, it supports WebSocket only.
159
+
69
160
  - ServiceID shouldn't be passed to CamOverlayAPI by the options object. Pass it as a parameter.
70
161
  - Renamed CamOverlayDrawingAPI event msg to message.
71
162
  - Drawing services extracted from CamOverlayAPI.ts to a separate file.
72
- > [!IMPORTANT]
163
+
73
164
  > Please read [CamOverlayAPI](doc/CamOverlayAPI.md) and [CamOverlayDrawingAPI](doc/CamOverlayDrawingAPI.md) for more information.
74
165
 
166
+ </details>
167
+ </br>
75
168
 
76
169
  # For Developers
77
170
 
@@ -109,4 +202,4 @@ The zip package is created in the current directory. You can choose different lo
109
202
  "scripts": {
110
203
  "create-package": "node node_modules/camstreamerlib/bin/CreatePackage.js -i -e=react"
111
204
  }
112
- ```
205
+ ```
@@ -22,7 +22,7 @@ class CamSwitcherAPI {
22
22
  }
23
23
  static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
24
24
  static getWsEventsPath = () => `/local/camswitcher/events`;
25
- static getClipPreviewPath = (id, storage) => `${BASE_PATH}/clip_preview.cgi?clip_name=${id}&storage=${storage}`;
25
+ static getClipPreviewPath = (clipId, storage) => `${BASE_PATH}/clip_preview.cgi?clip_name=${clipId}&storage=${storage}`;
26
26
  getClient(proxyParams) {
27
27
  return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
28
28
  }
@@ -16,6 +16,7 @@ class PlaneTrackerAPI {
16
16
  this.apiUser = apiUser;
17
17
  }
18
18
  static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
19
+ static getWsEventsPath = () => `${BASE_PATH}/package/ws`;
19
20
  getClient(proxyParams) {
20
21
  return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
21
22
  }
@@ -113,6 +114,10 @@ class PlaneTrackerAPI {
113
114
  timeout: options?.timeout,
114
115
  });
115
116
  }
117
+ async getIcao(by, value, options) {
118
+ const res = await this._getJson(`${BASE_PATH}/package/getIcao.cgi`, { [by]: value }, options);
119
+ return PlaneTrackerAPI_1.getIcaoSchema.parse(res).icao;
120
+ }
116
121
  async getPriorityList(options) {
117
122
  const res = await this._getJson(`${BASE_PATH}/package/getPriorityList.cgi`, undefined, options);
118
123
  return PlaneTrackerAPI_1.priorityListSchema.parse(res);
@@ -147,11 +152,11 @@ class PlaneTrackerAPI {
147
152
  }
148
153
  async goToCoordinates(lat, lon, alt, options) {
149
154
  const agent = this.getClient(options?.proxyParams);
150
- return await agent.get({
155
+ return (await agent.get({
151
156
  path: `${BASE_PATH}/package/goToCoordinates.cgi`,
152
157
  parameters: { lat, lon, alt, ...this.apiUser },
153
158
  timeout: options?.timeout,
154
- });
159
+ }));
155
160
  }
156
161
  async checkGenetecConnection(params, options) {
157
162
  return await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
package/cjs/index.js CHANGED
@@ -14,31 +14,40 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.VapixAPI = exports.PlaneTrackerAPI = exports.CamSwitcherEvents = exports.CamSwitcherAPI = exports.CamStreamerAPI = exports.CamScripterAPI = exports.CamOverlayAPI = void 0;
17
+ exports.VapixAPI = exports.CamScripterAPI = exports.PlaneTrackerEvents = exports.PlaneTrackerAPI = exports.CamSwitcherEvents = exports.CamSwitcherAPI = exports.CamOverlayEvents = exports.CamOverlayAPI = exports.CamStreamerEvents = exports.CamStreamerAPI = void 0;
18
18
  __exportStar(require("./internal/types"), exports);
19
19
  __exportStar(require("./internal/constants"), exports);
20
20
  __exportStar(require("./internal/utils"), exports);
21
21
  __exportStar(require("./internal/versionCompare"), exports);
22
22
  __exportStar(require("./internal/ProxyClient"), exports);
23
23
  __exportStar(require("./types/common"), exports);
24
- var CamOverlayAPI_1 = require("./CamOverlayAPI");
25
- Object.defineProperty(exports, "CamOverlayAPI", { enumerable: true, get: function () { return CamOverlayAPI_1.CamOverlayAPI; } });
26
- __exportStar(require("./types/CamOverlayAPI"), exports);
27
- var CamScripterAPI_1 = require("./CamScripterAPI");
28
- Object.defineProperty(exports, "CamScripterAPI", { enumerable: true, get: function () { return CamScripterAPI_1.CamScripterAPI; } });
29
- __exportStar(require("./types/CamScripterAPI"), exports);
30
24
  var CamStreamerAPI_1 = require("./CamStreamerAPI");
31
25
  Object.defineProperty(exports, "CamStreamerAPI", { enumerable: true, get: function () { return CamStreamerAPI_1.CamStreamerAPI; } });
32
26
  __exportStar(require("./types/CamStreamerAPI"), exports);
27
+ var CamStreamerEvents_1 = require("./ws/CamStreamerEvents");
28
+ Object.defineProperty(exports, "CamStreamerEvents", { enumerable: true, get: function () { return CamStreamerEvents_1.CamStreamerEvents; } });
29
+ __exportStar(require("./types/ws/CamStreamerEvents"), exports);
30
+ var CamOverlayAPI_1 = require("./CamOverlayAPI");
31
+ Object.defineProperty(exports, "CamOverlayAPI", { enumerable: true, get: function () { return CamOverlayAPI_1.CamOverlayAPI; } });
32
+ __exportStar(require("./types/CamOverlayAPI"), exports);
33
+ var CamOverlayEvents_1 = require("./ws/CamOverlayEvents");
34
+ Object.defineProperty(exports, "CamOverlayEvents", { enumerable: true, get: function () { return CamOverlayEvents_1.CamOverlayEvents; } });
35
+ __exportStar(require("./types/ws/CamOverlayEvents"), exports);
33
36
  var CamSwitcherAPI_1 = require("./CamSwitcherAPI");
34
37
  Object.defineProperty(exports, "CamSwitcherAPI", { enumerable: true, get: function () { return CamSwitcherAPI_1.CamSwitcherAPI; } });
35
38
  __exportStar(require("./types/CamSwitcherAPI"), exports);
36
- var CamSwitcherEvents_1 = require("./CamSwitcherEvents");
39
+ var CamSwitcherEvents_1 = require("./ws/CamSwitcherEvents");
37
40
  Object.defineProperty(exports, "CamSwitcherEvents", { enumerable: true, get: function () { return CamSwitcherEvents_1.CamSwitcherEvents; } });
38
- __exportStar(require("./types/CamSwitcherEvents"), exports);
41
+ __exportStar(require("./types/ws/CamSwitcherEvents"), exports);
39
42
  var PlaneTrackerAPI_1 = require("./PlaneTrackerAPI");
40
43
  Object.defineProperty(exports, "PlaneTrackerAPI", { enumerable: true, get: function () { return PlaneTrackerAPI_1.PlaneTrackerAPI; } });
41
44
  __exportStar(require("./types/PlaneTrackerAPI"), exports);
45
+ var PlaneTrackerEvents_1 = require("./ws/PlaneTrackerEvents");
46
+ Object.defineProperty(exports, "PlaneTrackerEvents", { enumerable: true, get: function () { return PlaneTrackerEvents_1.PlaneTrackerEvents; } });
47
+ __exportStar(require("./types/ws/PlaneTrackerEvents"), exports);
48
+ var CamScripterAPI_1 = require("./CamScripterAPI");
49
+ Object.defineProperty(exports, "CamScripterAPI", { enumerable: true, get: function () { return CamScripterAPI_1.CamScripterAPI; } });
50
+ __exportStar(require("./types/CamScripterAPI"), exports);
42
51
  var VapixAPI_1 = require("./VapixAPI");
43
52
  Object.defineProperty(exports, "VapixAPI", { enumerable: true, get: function () { return VapixAPI_1.VapixAPI; } });
44
53
  __exportStar(require("./types/VapixAPI"), exports);
@@ -9,7 +9,7 @@ class WsEvents {
9
9
  constructor(zodSchema, ws) {
10
10
  this.zodSchema = zodSchema;
11
11
  this.ws = ws;
12
- this.ws.onmessage = (e) => this.onMessage(e);
12
+ this.ws.onMessage = (e) => this.onMessage(e);
13
13
  }
14
14
  get isDestroyed() {
15
15
  return this._isDestroyed;
@@ -37,12 +37,12 @@ class WsEvents {
37
37
  }
38
38
  }
39
39
  }
40
- onMessage(evt) {
40
+ onMessage(incomeData) {
41
41
  if (this.isDestroyed) {
42
42
  return;
43
43
  }
44
44
  try {
45
- const eventData = JSON.parse(evt.data);
45
+ const eventData = JSON.parse(incomeData.toString());
46
46
  const data = this.zodSchema.parse(eventData);
47
47
  if (isInitEvent(data)) {
48
48
  this.processMessage(data.data, true);
@@ -51,7 +51,7 @@ class WsEvents {
51
51
  this.processMessage(data, false);
52
52
  }
53
53
  catch (error) {
54
- console.error('Error parsing event data:', evt.data, error);
54
+ console.error('Error parsing event data:', incomeData.toString(), error);
55
55
  }
56
56
  }
57
57
  processMessage(event, isInit) {
@@ -61,7 +61,8 @@ class WsEvents {
61
61
  }
62
62
  destroy() {
63
63
  this._isDestroyed = true;
64
- this.ws.onmessage = () => { };
64
+ this.ws.onMessage = () => { };
65
+ this.ws.onOpen = () => Promise.reject(new Error('Websocket is destroyed'));
65
66
  this.ws.destroy();
66
67
  this.listeners = {};
67
68
  }
@@ -47,7 +47,7 @@ class CamOverlayDrawingAPI extends events_1.default {
47
47
  this.startMsgsTimeoutCheck();
48
48
  }
49
49
  disconnect() {
50
- this.ws.close();
50
+ this.ws.destroy();
51
51
  this.stopMsgsTimeoutCheck();
52
52
  }
53
53
  isConnected() {
@@ -104,23 +104,23 @@ class CamOverlayDrawingAPI extends events_1.default {
104
104
  tlsInsecure: this.tlsInsecure,
105
105
  };
106
106
  this.ws = new WsClient_1.WsClient(options);
107
- this.ws.on('open', () => {
107
+ this.ws.onOpen = () => {
108
108
  console.log('CamOverlay connection opened');
109
109
  this.wsConnected = true;
110
110
  this.emit('open');
111
- });
112
- this.ws.on('message', (msgData) => this.incomingWsMessageHandler(msgData));
113
- this.ws.on('error', (error) => {
111
+ };
112
+ this.ws.onMessage = (data) => this.incomingWsMessageHandler(data.toString());
113
+ this.ws.onError = (error) => {
114
114
  this.reportError(error);
115
- });
116
- this.ws.on('close', () => {
115
+ };
116
+ this.ws.onClose = () => {
117
117
  console.log('CamOverlay connection closed');
118
118
  this.wsConnected = false;
119
119
  this.reportClose();
120
- });
120
+ };
121
121
  }
122
122
  incomingWsMessageHandler(msgData) {
123
- const dataJSON = JSON.parse(msgData.toString());
123
+ const dataJSON = JSON.parse(msgData);
124
124
  let errorResponse;
125
125
  if ('error' in dataJSON) {
126
126
  errorResponse = dataJSON;
@@ -177,7 +177,7 @@ class CamOverlayDrawingAPI extends events_1.default {
177
177
  headerView.setInt8(0, 1);
178
178
  headerView.setInt32(1, jsonBuffer.byteLength);
179
179
  const msgBuffer = Buffer.concat([Buffer.from(header), jsonBuffer, data]);
180
- this.ws.send(msgBuffer);
180
+ this.ws.send(msgBuffer.buffer);
181
181
  this.sendMessages[this.callId] = { resolve, reject, sentTimestamp: Date.now() };
182
182
  }
183
183
  catch (err) {
@@ -37,7 +37,7 @@ class CamScripterAPICameraEventsGenerator extends events_1.default {
37
37
  this.startMsgsTimeoutCheck();
38
38
  }
39
39
  disconnect() {
40
- this.ws.close();
40
+ this.ws.destroy();
41
41
  this.stopMsgsTimeoutCheck();
42
42
  }
43
43
  declareEvent(eventDeclaration) {
@@ -73,21 +73,21 @@ class CamScripterAPICameraEventsGenerator extends events_1.default {
73
73
  protocol: 'camera-events',
74
74
  };
75
75
  this.ws = new WsClient_1.WsClient(options);
76
- this.ws.on('open', () => {
76
+ this.ws.onOpen = () => {
77
77
  this.wsConnected = true;
78
78
  this.emit('open');
79
- });
80
- this.ws.on('message', (msgData) => this.incomingWsMessageHandler(msgData));
81
- this.ws.on('error', (error) => {
79
+ };
80
+ this.ws.onMessage = (data) => this.incomingWsMessageHandler(data.toString());
81
+ this.ws.onError = (error) => {
82
82
  this.reportErr(error);
83
- });
84
- this.ws.on('close', () => {
83
+ };
84
+ this.ws.onClose = () => {
85
85
  this.wsConnected = false;
86
86
  this.reportClose();
87
- });
87
+ };
88
88
  }
89
89
  incomingWsMessageHandler(msgData) {
90
- const dataJSON = JSON.parse(msgData.toString());
90
+ const dataJSON = JSON.parse(msgData);
91
91
  let errorResponse;
92
92
  if ('error' in dataJSON) {
93
93
  errorResponse = dataJSON;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Digest_1 = require("./Digest");
4
+ const globals_1 = require("@jest/globals");
5
+ (0, globals_1.describe)('Digest', () => {
6
+ (0, globals_1.describe)('getAuthHeader', () => {
7
+ (0, globals_1.test)('Checks, that Digest.getAuthHeader() returns correct value.', () => {
8
+ const testString = 'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"';
9
+ const value = 'Digest username="root",realm="testrealm@host.com",nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",uri="www.cz",response="63f54af3ce5cf193a7435d5c68625472",qop=auth,nc=00000001,cnonce="162d50aa594e9648"';
10
+ (0, globals_1.expect)(new Digest_1.Digest().getAuthHeader('root', 'pass', 'GET', 'www.cz', testString)).toBe(value);
11
+ });
12
+ });
13
+ });
@@ -26,7 +26,7 @@ class VapixEvents extends eventemitter2_1.EventEmitter2 {
26
26
  this.ws.open();
27
27
  }
28
28
  disconnect() {
29
- this.ws.close();
29
+ this.ws.destroy();
30
30
  }
31
31
  createWsClient() {
32
32
  const options = {
@@ -39,7 +39,7 @@ class VapixEvents extends eventemitter2_1.EventEmitter2 {
39
39
  address: '/vapix/ws-data-stream?sources=events',
40
40
  };
41
41
  this.ws = new WsClient_1.WsClient(options);
42
- this.ws.on('open', () => {
42
+ this.ws.onOpen = () => {
43
43
  const topics = [];
44
44
  const eventNames = this.eventNames();
45
45
  for (const eventName of eventNames) {
@@ -58,8 +58,8 @@ class VapixEvents extends eventemitter2_1.EventEmitter2 {
58
58
  },
59
59
  };
60
60
  this.ws.send(JSON.stringify(topicFilter));
61
- });
62
- this.ws.on('message', (data) => {
61
+ };
62
+ this.ws.onMessage = (data) => {
63
63
  const dataJSON = JSON.parse(data.toString());
64
64
  if (dataJSON.method === 'events:configure') {
65
65
  if (dataJSON.error === undefined) {
@@ -73,13 +73,13 @@ class VapixEvents extends eventemitter2_1.EventEmitter2 {
73
73
  }
74
74
  const eventName = dataJSON.params.notification.topic;
75
75
  this.emit(eventName, dataJSON);
76
- });
77
- this.ws.on('error', (error) => {
76
+ };
77
+ this.ws.onError = (error) => {
78
78
  this.emit('error', error);
79
- });
80
- this.ws.on('close', () => {
79
+ };
80
+ this.ws.onClose = () => {
81
81
  this.emit('close');
82
- });
82
+ };
83
83
  }
84
84
  isReservedEventName(eventName) {
85
85
  return eventName === 'open' || eventName === 'close' || eventName === 'error';
@@ -4,10 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.WsClient = void 0;
7
- const events_1 = __importDefault(require("events"));
8
7
  const ws_1 = __importDefault(require("ws"));
9
8
  const Digest_1 = require("./Digest");
10
- class WsClient extends events_1.default {
9
+ class WsClient {
11
10
  user;
12
11
  pass;
13
12
  address;
@@ -20,7 +19,6 @@ class WsClient extends events_1.default {
20
19
  ws;
21
20
  isClosed = false;
22
21
  constructor(options) {
23
- super();
24
22
  const tls = options.tls ?? false;
25
23
  const tlsInsecure = options.tlsInsecure ?? false;
26
24
  const ip = options.ip ?? '127.0.0.1';
@@ -52,10 +50,10 @@ class WsClient extends events_1.default {
52
50
  }
53
51
  this.ws.binaryType = 'arraybuffer';
54
52
  this.isAlive = true;
55
- this.pingTimer = setInterval(async () => {
53
+ this.pingTimer = setInterval(() => {
56
54
  if ((this.ws && this.ws.readyState !== ws_1.default.OPEN) || this.isAlive === false) {
57
- this.emit('error', new Error('Connection timeout'));
58
- await this.closeWsConnection();
55
+ this.onError(new Error('Connection timeout'));
56
+ this.closeWsConnection();
59
57
  }
60
58
  else {
61
59
  this.isAlive = false;
@@ -78,23 +76,32 @@ class WsClient extends events_1.default {
78
76
  this.open(res.headers['www-authenticate']);
79
77
  }
80
78
  else {
81
- this.emit('error', new Error('Status code: ' + res.statusCode));
79
+ this.onError(new Error('Status code: ' + res.statusCode));
82
80
  this.closeWsConnection();
83
81
  }
84
82
  });
85
- this.ws.on('open', () => this.emit('open'));
86
- this.ws.on('message', (data) => this.emit('message', data));
83
+ this.ws.on('open', () => this.onOpen());
84
+ this.ws.on('message', (data, isBinary) => {
85
+ const message = isBinary ? data : data.toString();
86
+ this.onMessage(message);
87
+ });
87
88
  this.ws.on('error', (error) => {
88
- this.emit('error', error);
89
+ this.onError(error);
89
90
  this.closeWsConnection();
90
91
  });
91
92
  this.ws.on('close', () => this.closeWsConnection());
92
93
  }
93
94
  catch (error) {
94
- this.emit('error', error instanceof Error ? error : new Error('Unknown error'));
95
+ this.onError(error instanceof Error ? error : new Error('Unknown error'));
95
96
  this.closeWsConnection();
96
97
  }
97
98
  }
99
+ onMessage = (_) => { };
100
+ onOpen = () => { };
101
+ onClose = () => { };
102
+ onError = (error) => {
103
+ console.error(error);
104
+ };
98
105
  send(data) {
99
106
  if (this.ws === undefined) {
100
107
  throw new Error("This websocket hasn't been opened yet.");
@@ -103,7 +110,7 @@ class WsClient extends events_1.default {
103
110
  this.ws.send(data);
104
111
  }
105
112
  }
106
- close() {
113
+ destroy() {
107
114
  if (this.isClosed) {
108
115
  return;
109
116
  }
@@ -133,7 +140,7 @@ class WsClient extends events_1.default {
133
140
  wsCopy.terminate();
134
141
  }
135
142
  }, 5000);
136
- this.emit('close');
143
+ this.onClose();
137
144
  }
138
145
  catch (err) {
139
146
  console.error(err);
@@ -27,7 +27,7 @@ exports.pipSchema = serviceCommonTypes_1.serviceCommonSchema.extend({
27
27
  zod_1.z.literal('overlays=image'),
28
28
  zod_1.z.literal('overlays=application'),
29
29
  ]),
30
- rotate: zod_1.z.union([zod_1.z.literal(0), zod_1.z.literal(90), zod_1.z.literal(180), zod_1.z.literal(270)]),
30
+ rotate: zod_1.z.union([zod_1.z.literal(0), zod_1.z.literal(90), zod_1.z.literal(180), zod_1.z.literal(270)]).default(0),
31
31
  dewarping: zod_1.z.object({
32
32
  enabled: zod_1.z.boolean(),
33
33
  rectangle: zod_1.z.array(zod_1.z.tuple([zod_1.z.number(), zod_1.z.number()])),
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zonesSchema = exports.mapInfoSchema = exports.mapTypeSchema = exports.blackListSchema = exports.whiteListSchema = exports.priorityListSchema = exports.flightInfoSchema = exports.trackingModeSchema = exports.serverSettingsSchema = exports.cameraSettingsSchema = exports.widgetSchema = exports.connectionSchema = exports.wsAliasResponseSchema = void 0;
3
+ exports.zonesSchema = exports.mapInfoSchema = exports.mapTypeSchema = exports.blackListSchema = exports.whiteListSchema = exports.priorityListSchema = exports.flightInfoSchema = exports.trackingModeSchema = exports.getIcaoSchema = exports.serverSettingsSchema = exports.cameraSettingsSchema = exports.widgetSchema = exports.connectionSchema = exports.wsAliasResponseSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  exports.wsAliasResponseSchema = zod_1.z.object({
6
6
  alias: zod_1.z.string(),
@@ -234,6 +234,9 @@ exports.serverSettingsSchema = zod_1.z.object({
234
234
  tiltRealKnownPoint: 90,
235
235
  }),
236
236
  });
237
+ exports.getIcaoSchema = zod_1.z.object({
238
+ icao: zod_1.z.string(),
239
+ });
237
240
  exports.trackingModeSchema = zod_1.z.object({
238
241
  mode: zod_1.z.union([zod_1.z.literal('MANUAL'), zod_1.z.literal('AUTOMATIC')]),
239
242
  });
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.coEventsSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const coEventsDataSchema = zod_1.z.discriminatedUnion('type', [
6
+ zod_1.z.object({ type: zod_1.z.literal('authorization'), state: zod_1.z.string() }),
7
+ zod_1.z.object({
8
+ type: zod_1.z.literal('ServiceStart'),
9
+ serviceId: zod_1.z.number(),
10
+ }),
11
+ zod_1.z.object({
12
+ type: zod_1.z.literal('ServiceStop'),
13
+ serviceId: zod_1.z.number(),
14
+ }),
15
+ ]);
16
+ exports.coEventsSchema = zod_1.z.discriminatedUnion('type', [
17
+ zod_1.z.object({ type: zod_1.z.literal('init'), data: coEventsDataSchema }),
18
+ ...coEventsDataSchema.options,
19
+ ]);