camstreamerlib 4.0.0-beta.33 → 4.0.0-beta.34

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 (154) hide show
  1. package/cjs/CamOverlayAPI.js +2 -2
  2. package/cjs/CamStreamerAPI.js +54 -11
  3. package/cjs/CamSwitcherAPI.js +7 -7
  4. package/cjs/CamSwitcherEvents.js +4 -60
  5. package/cjs/PlaneTrackerAPI.js +52 -52
  6. package/cjs/VapixAPI.js +10 -7
  7. package/cjs/index.js +2 -11
  8. package/cjs/internal/ProxyClient.js +6 -6
  9. package/cjs/internal/WsEvents.js +72 -0
  10. package/cjs/node/DefaultClient.js +4 -4
  11. package/cjs/node/HttpRequestSender.js +1 -1
  12. package/cjs/node/WsClient.js +1 -1
  13. package/cjs/{events → node/events}/AxisCameraStationEvents.js +4 -4
  14. package/cjs/{events → node/events}/GenetecAgent.js +1 -1
  15. package/cjs/node/index.js +2 -2
  16. package/cjs/types/CamOverlayAPI/CamOverlayAPI.js +14 -1
  17. package/cjs/types/CamOverlayAPI/scoreBoardSchema.js +127 -0
  18. package/cjs/types/CamStreamerAPI.js +30 -3
  19. package/esm/CamOverlayAPI.js +2 -2
  20. package/esm/CamStreamerAPI.js +53 -11
  21. package/esm/CamSwitcherAPI.js +7 -7
  22. package/esm/CamSwitcherEvents.js +5 -61
  23. package/esm/PlaneTrackerAPI.js +52 -52
  24. package/esm/VapixAPI.js +10 -7
  25. package/esm/index.js +1 -6
  26. package/esm/internal/ProxyClient.js +6 -6
  27. package/esm/internal/WsEvents.js +68 -0
  28. package/esm/node/DefaultClient.js +4 -4
  29. package/esm/node/HttpRequestSender.js +1 -1
  30. package/esm/node/WsClient.js +1 -1
  31. package/esm/{events → node/events}/AxisCameraStationEvents.js +3 -3
  32. package/esm/{events → node/events}/GenetecAgent.js +1 -1
  33. package/esm/node/index.js +2 -2
  34. package/esm/types/CamOverlayAPI/CamOverlayAPI.js +9 -0
  35. package/esm/types/CamOverlayAPI/scoreBoardSchema.js +124 -0
  36. package/esm/types/CamStreamerAPI.js +29 -2
  37. package/package.json +22 -2
  38. package/{cjs → types}/CamOverlayAPI.d.ts +3 -5
  39. package/{esm → types}/CamScripterAPI.d.ts +4 -4
  40. package/types/CamStreamerAPI.d.ts +48 -0
  41. package/{esm → types}/CamSwitcherAPI.d.ts +8 -8
  42. package/types/CamSwitcherEvents.d.ts +8 -0
  43. package/types/PlaneTrackerAPI.d.ts +43 -0
  44. package/{cjs → types}/VapixAPI.d.ts +11 -7
  45. package/{cjs → types}/index.d.ts +1 -6
  46. package/{esm → types}/internal/ProxyClient.d.ts +4 -4
  47. package/types/internal/WsEvents.d.ts +41 -0
  48. package/{esm → types}/internal/types.d.ts +12 -9
  49. package/{cjs → types}/node/DefaultClient.d.ts +6 -4
  50. package/{esm → types/node}/events/AxisCameraStationEvents.d.ts +4 -4
  51. package/{esm → types}/node/index.d.ts +2 -2
  52. package/{cjs → types}/types/CamOverlayAPI/CamOverlayAPI.d.ts +1071 -7
  53. package/{esm → types}/types/CamOverlayAPI/infotickerSchema.d.ts +2 -2
  54. package/types/types/CamOverlayAPI/scoreBoardSchema.d.ts +357 -0
  55. package/types/types/CamStreamerAPI.d.ts +274 -0
  56. package/types/web/DefaultClient.d.ts +6 -0
  57. package/cjs/CamScripterAPI.d.ts +0 -37
  58. package/cjs/CamStreamerAPI.d.ts +0 -19
  59. package/cjs/CamSwitcherAPI.d.ts +0 -54
  60. package/cjs/CamSwitcherEvents.d.ts +0 -18
  61. package/cjs/PlaneTrackerAPI.d.ts +0 -43
  62. package/cjs/events/AxisCameraStationEvents.d.ts +0 -12
  63. package/cjs/internal/ProxyClient.d.ts +0 -10
  64. package/cjs/internal/types.d.ts +0 -42
  65. package/cjs/node/index.d.ts +0 -5
  66. package/cjs/types/CamOverlayAPI/infotickerSchema.d.ts +0 -96
  67. package/cjs/types/CamStreamerAPI.d.ts +0 -150
  68. package/cjs/web/DefaultClient.d.ts +0 -6
  69. package/esm/CamOverlayAPI.d.ts +0 -41
  70. package/esm/CamOverlayDrawingAPI.d.ts +0 -41
  71. package/esm/CamOverlayPainter/Frame.d.ts +0 -67
  72. package/esm/CamOverlayPainter/Painter.d.ts +0 -43
  73. package/esm/CamOverlayPainter/ResourceManager.d.ts +0 -15
  74. package/esm/CamScripterAPICameraEventsGenerator.d.ts +0 -74
  75. package/esm/CamStreamerAPI.d.ts +0 -19
  76. package/esm/CamSwitcherEvents.d.ts +0 -18
  77. package/esm/CreatePackage.d.ts +0 -1
  78. package/esm/PlaneTrackerAPI.d.ts +0 -43
  79. package/esm/VapixAPI.d.ts +0 -80
  80. package/esm/VapixEvents.d.ts +0 -43
  81. package/esm/errors/errors.d.ts +0 -37
  82. package/esm/events/GenetecAgent.d.ts +0 -159
  83. package/esm/index.d.ts +0 -23
  84. package/esm/internal/Digest.d.ts +0 -4
  85. package/esm/internal/constants.d.ts +0 -1
  86. package/esm/internal/transformers.d.ts +0 -5
  87. package/esm/internal/utils.d.ts +0 -14
  88. package/esm/internal/versionCompare.d.ts +0 -6
  89. package/esm/node/DefaultClient.d.ts +0 -14
  90. package/esm/node/HttpRequestSender.d.ts +0 -29
  91. package/esm/node/HttpServer.d.ts +0 -21
  92. package/esm/node/WsClient.d.ts +0 -40
  93. package/esm/types/CamOverlayAPI/CamOverlayAPI.d.ts +0 -3260
  94. package/esm/types/CamOverlayAPI/accuweatherSchema.d.ts +0 -84
  95. package/esm/types/CamOverlayAPI/customGraphicsSchema.d.ts +0 -700
  96. package/esm/types/CamOverlayAPI/imagesSchema.d.ts +0 -95
  97. package/esm/types/CamOverlayAPI/index.d.ts +0 -11
  98. package/esm/types/CamOverlayAPI/pipSchema.d.ts +0 -125
  99. package/esm/types/CamOverlayAPI/ptzCompassSchema.d.ts +0 -93
  100. package/esm/types/CamOverlayAPI/ptzSchema.d.ts +0 -118
  101. package/esm/types/CamOverlayAPI/screenSharingSchema.d.ts +0 -58
  102. package/esm/types/CamOverlayAPI/webCameraSharingSchema.d.ts +0 -58
  103. package/esm/types/CamOverlayAPI/widgetCommonTypes.d.ts +0 -141
  104. package/esm/types/CamOverlayDrawingAPI.d.ts +0 -58
  105. package/esm/types/CamOverlayPainter.d.ts +0 -74
  106. package/esm/types/CamScripterAPI.d.ts +0 -132
  107. package/esm/types/CamStreamerAPI.d.ts +0 -150
  108. package/esm/types/CamSwitcherAPI.d.ts +0 -812
  109. package/esm/types/CamSwitcherEvents.d.ts +0 -568
  110. package/esm/types/PlaneTrackerAPI.d.ts +0 -8
  111. package/esm/types/VapixAPI.d.ts +0 -1819
  112. package/esm/types/common.d.ts +0 -46
  113. package/esm/web/DefaultClient.d.ts +0 -6
  114. package/esm/web/WsClient.d.ts +0 -13
  115. package/esm/web/index.d.ts +0 -2
  116. /package/cjs/{internal → node}/Digest.js +0 -0
  117. /package/esm/{internal → node}/Digest.js +0 -0
  118. /package/{cjs → types}/CamOverlayDrawingAPI.d.ts +0 -0
  119. /package/{cjs → types}/CamOverlayPainter/Frame.d.ts +0 -0
  120. /package/{cjs → types}/CamOverlayPainter/Painter.d.ts +0 -0
  121. /package/{cjs → types}/CamOverlayPainter/ResourceManager.d.ts +0 -0
  122. /package/{cjs → types}/CamScripterAPICameraEventsGenerator.d.ts +0 -0
  123. /package/{cjs → types}/CreatePackage.d.ts +0 -0
  124. /package/{cjs → types}/VapixEvents.d.ts +0 -0
  125. /package/{cjs → types}/errors/errors.d.ts +0 -0
  126. /package/{cjs → types}/internal/constants.d.ts +0 -0
  127. /package/{cjs → types}/internal/transformers.d.ts +0 -0
  128. /package/{cjs → types}/internal/utils.d.ts +0 -0
  129. /package/{cjs → types}/internal/versionCompare.d.ts +0 -0
  130. /package/{cjs/internal → types/node}/Digest.d.ts +0 -0
  131. /package/{cjs → types}/node/HttpRequestSender.d.ts +0 -0
  132. /package/{cjs → types}/node/HttpServer.d.ts +0 -0
  133. /package/{cjs → types}/node/WsClient.d.ts +0 -0
  134. /package/{cjs → types/node}/events/GenetecAgent.d.ts +0 -0
  135. /package/{cjs → types}/types/CamOverlayAPI/accuweatherSchema.d.ts +0 -0
  136. /package/{cjs → types}/types/CamOverlayAPI/customGraphicsSchema.d.ts +0 -0
  137. /package/{cjs → types}/types/CamOverlayAPI/imagesSchema.d.ts +0 -0
  138. /package/{cjs → types}/types/CamOverlayAPI/index.d.ts +0 -0
  139. /package/{cjs → types}/types/CamOverlayAPI/pipSchema.d.ts +0 -0
  140. /package/{cjs → types}/types/CamOverlayAPI/ptzCompassSchema.d.ts +0 -0
  141. /package/{cjs → types}/types/CamOverlayAPI/ptzSchema.d.ts +0 -0
  142. /package/{cjs → types}/types/CamOverlayAPI/screenSharingSchema.d.ts +0 -0
  143. /package/{cjs → types}/types/CamOverlayAPI/webCameraSharingSchema.d.ts +0 -0
  144. /package/{cjs → types}/types/CamOverlayAPI/widgetCommonTypes.d.ts +0 -0
  145. /package/{cjs → types}/types/CamOverlayDrawingAPI.d.ts +0 -0
  146. /package/{cjs → types}/types/CamOverlayPainter.d.ts +0 -0
  147. /package/{cjs → types}/types/CamScripterAPI.d.ts +0 -0
  148. /package/{cjs → types}/types/CamSwitcherAPI.d.ts +0 -0
  149. /package/{cjs → types}/types/CamSwitcherEvents.d.ts +0 -0
  150. /package/{cjs → types}/types/PlaneTrackerAPI.d.ts +0 -0
  151. /package/{cjs → types}/types/VapixAPI.d.ts +0 -0
  152. /package/{cjs → types}/types/common.d.ts +0 -0
  153. /package/{cjs → types}/web/WsClient.d.ts +0 -0
  154. /package/{cjs → types}/web/index.d.ts +0 -0
@@ -201,7 +201,7 @@ class CamOverlayAPI {
201
201
  const agent = this.getClient(options?.proxyParams);
202
202
  const res = await agent.get({ ...params, timeout: options?.timeout });
203
203
  if (res.ok) {
204
- return (await res.json());
204
+ return await res.json();
205
205
  }
206
206
  else {
207
207
  throw new Error(await (0, utils_1.responseStringify)(res));
@@ -211,7 +211,7 @@ class CamOverlayAPI {
211
211
  const agent = this.getClient(options?.proxyParams);
212
212
  const res = await agent.post({ ...params, timeout: options?.timeout });
213
213
  if (res.ok) {
214
- return (await res.json());
214
+ return await res.json();
215
215
  }
216
216
  else {
217
217
  throw new Error(await (0, utils_1.responseStringify)(res));
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CamStreamerAPI = void 0;
3
+ exports.parseCameraStreamResponse = exports.CamStreamerAPI = void 0;
4
+ const zod_1 = require("zod");
4
5
  const ProxyClient_1 = require("./internal/ProxyClient");
5
6
  const utils_1 = require("./internal/utils");
6
7
  const CamStreamerAPI_1 = require("./types/CamStreamerAPI");
@@ -15,11 +16,18 @@ class CamStreamerAPI {
15
16
  }
16
17
  async getStreamList(options) {
17
18
  const streamListRes = await this.get(`${BASE_PATH}/stream/list.cgi`, undefined, options);
18
- return CamStreamerAPI_1.streamListSchema.parse(streamListRes.data);
19
+ const list = zod_1.default.record(zod_1.default.string(), CamStreamerAPI_1.cameraStreamSchema).parse(streamListRes.data);
20
+ const res = {};
21
+ for (const [key, data] of Object.entries(list)) {
22
+ const streamId = parseInt(key);
23
+ res[streamId] = (0, exports.parseCameraStreamResponse)(data);
24
+ }
25
+ return res;
19
26
  }
20
27
  async getStream(streamId, options) {
21
28
  const stream = await this.get(`${BASE_PATH}/stream/get.cgi?stream_id=${streamId}`, undefined, options);
22
- return CamStreamerAPI_1.streamAttributesSchema.parse(stream.data);
29
+ const cameraData = CamStreamerAPI_1.cameraStreamSchema.parse(stream.data);
30
+ return (0, exports.parseCameraStreamResponse)(cameraData);
23
31
  }
24
32
  async getStreamParameter(streamId, paramName, options) {
25
33
  const stream = await this.get(`${BASE_PATH}/stream/get.cgi?stream_id=${streamId}`, undefined, options);
@@ -27,29 +35,38 @@ class CamStreamerAPI {
27
35
  }
28
36
  async setStream(streamId, params, options) {
29
37
  const { streamDelay, startTime, stopTime, ...rest } = params;
30
- await this.get(`${BASE_PATH}/stream/set.cgi`, {
38
+ return await this.get(`${BASE_PATH}/stream/set.cgi`, {
31
39
  stream_id: streamId,
32
40
  streamDelay: streamDelay ?? '',
33
- startTime: startTime ?? 'null',
34
- stopTime: stopTime ?? 'null',
41
+ startTime: startTime ?? null,
42
+ stopTime: stopTime ?? null,
35
43
  ...rest,
36
44
  }, options);
37
45
  }
38
46
  async setStreamParameter(streamId, paramName, value, options) {
39
- await this.get(`${BASE_PATH}/stream/set.cgi?stream_id=${streamId}&${paramName}=${value}`, undefined, options);
47
+ return await this.get(`${BASE_PATH}/stream/set.cgi?stream_id=${streamId}&${paramName}=${value}`, undefined, options);
40
48
  }
41
49
  async isStreaming(streamId, options) {
42
50
  const response = await this.get(`${BASE_PATH}/get_streamstat.cgi?stream_id=${streamId}`, undefined, options);
43
51
  return response.data.is_streaming === 1;
44
52
  }
45
53
  async deleteStream(streamId, options) {
46
- await this.get(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
54
+ const res = await this.get(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
55
+ return res.data.status === 200;
47
56
  }
48
- wsAuthorization(options) {
49
- return this.get(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
57
+ async getWsAuthorization(options) {
58
+ const res = await this.get(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
59
+ if (res.status !== 200) {
60
+ throw new Error(`Server error on ws authorization: ${res.message}`);
61
+ }
62
+ return res.data;
50
63
  }
51
64
  async getUtcTime(options) {
52
- return await this.get(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
65
+ const res = await this.get(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
66
+ if (res.status !== 200) {
67
+ throw new Error(`Server error on get UTC time: ${res.message}`);
68
+ }
69
+ return res.data;
53
70
  }
54
71
  async get(path, parameters, options) {
55
72
  const agent = this.getClient(options?.proxyParams);
@@ -63,3 +80,29 @@ class CamStreamerAPI {
63
80
  }
64
81
  }
65
82
  exports.CamStreamerAPI = CamStreamerAPI;
83
+ const parseCameraStreamResponse = (cameraStreamData) => {
84
+ return {
85
+ enabled: parseInt(cameraStreamData.enabled),
86
+ active: parseInt(cameraStreamData.active),
87
+ audioSource: cameraStreamData.audioSource,
88
+ avSyncMsec: parseInt(cameraStreamData.avSyncMsec),
89
+ internalVapixParameters: cameraStreamData.internalVapixParameters,
90
+ userVapixParameters: cameraStreamData.userVapixParameters,
91
+ outputParameters: cameraStreamData.outputParameters,
92
+ outputType: cameraStreamData.outputType,
93
+ mediaServerUrl: cameraStreamData.mediaServerUrl,
94
+ inputType: cameraStreamData.inputType,
95
+ inputUrl: cameraStreamData.inputUrl,
96
+ forceStereo: parseInt(cameraStreamData.forceStereo),
97
+ streamDelay: isNaN(parseInt(cameraStreamData.streamDelay)) ? null : parseInt(cameraStreamData.streamDelay),
98
+ statusLed: parseInt(cameraStreamData.statusLed),
99
+ statusPort: cameraStreamData.statusPort,
100
+ callApi: parseInt(cameraStreamData.callApi),
101
+ trigger: cameraStreamData.trigger,
102
+ schedule: cameraStreamData.schedule,
103
+ prepareAhead: parseInt(cameraStreamData.prepareAhead),
104
+ startTime: isNaN(parseInt(cameraStreamData.startTime)) ? null : parseInt(cameraStreamData.startTime),
105
+ stopTime: isNaN(parseInt(cameraStreamData.stopTime)) ? null : parseInt(cameraStreamData.stopTime),
106
+ };
107
+ };
108
+ exports.parseCameraStreamResponse = parseCameraStreamResponse;
@@ -111,10 +111,10 @@ class CamSwitcherAPI {
111
111
  async playlistQueuePlayNext(options) {
112
112
  await this.get(`${BASE_PATH}/playlist_queue_play_next.cgi`, undefined, options);
113
113
  }
114
- async addNewClip(file, clipType, storage, id, fileName, options) {
114
+ async addNewClip(file, clipType, storage, clipId, fileName, options) {
115
115
  const path = `${BASE_PATH}/clip_upload.cgi?storage=${storage}`;
116
116
  const formData = new this.CustomFormData();
117
- formData.append('clip_name', id);
117
+ formData.append('clip_name', clipId);
118
118
  formData.append('clip_type', clipType);
119
119
  formData.append('file', file, fileName);
120
120
  const agent = this.getClient(options?.proxyParams);
@@ -124,8 +124,8 @@ class CamSwitcherAPI {
124
124
  throw new errors_1.AddNewClipError(output.message);
125
125
  }
126
126
  }
127
- removeClip(id, storage, options) {
128
- return this.get(`${BASE_PATH}/clip_remove.cgi`, { clip_name: id, storage }, options);
127
+ removeClip(clipId, storage, options) {
128
+ return this.get(`${BASE_PATH}/clip_remove.cgi`, { clip_name: clipId, storage }, options);
129
129
  }
130
130
  async getClipList(options) {
131
131
  const data = await this.get(`${BASE_PATH}/clip_list.cgi`, undefined, options);
@@ -180,8 +180,8 @@ class CamSwitcherAPI {
180
180
  };
181
181
  return this.setParamFromCameraJSON(CSW_PARAM_NAMES.SECONDARY_AUDIO, data, options);
182
182
  }
183
- setDefaultPlaylist(id, options) {
184
- const value = JSON.stringify({ default_playlist_id: id });
183
+ setDefaultPlaylist(playlistId, options) {
184
+ const value = JSON.stringify({ default_playlist_id: playlistId });
185
185
  return this.vapixAgent.setParameter({
186
186
  [CSW_PARAM_NAMES.DEFAULT_PLAYLIST]: value,
187
187
  }, options);
@@ -253,7 +253,7 @@ class CamSwitcherAPI {
253
253
  const agent = this.getClient(options?.proxyParams);
254
254
  const res = await agent.get({ path, parameters, timeout: options?.timeout });
255
255
  if (res.ok) {
256
- const d = (await res.json());
256
+ const d = await res.json();
257
257
  return d.data;
258
258
  }
259
259
  else {
@@ -1,67 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CamSwitcherEvents = void 0;
4
+ const WsEvents_1 = require("./internal/WsEvents");
4
5
  const CamSwitcherEvents_1 = require("./types/CamSwitcherEvents");
5
- class CamSwitcherEvents {
6
- isDestroyed = false;
7
- ws = null;
8
- listeners = {};
9
- setWebsocket(ws) {
10
- if (this.ws) {
11
- this.ws.destroy();
12
- }
13
- this.ws = ws;
14
- this.ws.onmessage = (e) => this.onMessage(e);
15
- }
16
- resendInitData() {
17
- const request = {
18
- command: 'sendInitData',
19
- };
20
- this.ws?.send(JSON.stringify(request));
21
- }
22
- addListener(type, listener, id) {
23
- const typeList = this.listeners[type];
24
- if (typeList === undefined) {
25
- this.listeners[type] = { [id]: listener };
26
- return;
27
- }
28
- typeList[id] = listener;
29
- }
30
- removeListener(type, id) {
31
- const typeList = this.listeners[type];
32
- if (typeList) {
33
- delete typeList[id];
34
- }
35
- }
36
- onMessage(evt) {
37
- if (this.isDestroyed) {
38
- return;
39
- }
40
- try {
41
- const eventData = JSON.parse(evt.data);
42
- const data = CamSwitcherEvents_1.cswEventsSchema.parse(eventData);
43
- if (data.type === 'init') {
44
- this.processMessage(data.data, true);
45
- return;
46
- }
47
- this.processMessage(data, false);
48
- }
49
- catch (error) {
50
- console.error('Error parsing event data:', evt.data, error);
51
- }
52
- }
53
- processMessage(event, isInit) {
54
- const listeners = this.listeners[event.type];
55
- const list = Object.values(listeners ?? {});
56
- list.forEach((listener) => listener(event, isInit));
57
- }
58
- destroy() {
59
- this.isDestroyed = true;
60
- if (this.ws) {
61
- this.ws.destroy();
62
- this.ws = null;
63
- }
64
- this.listeners = {};
6
+ class CamSwitcherEvents extends WsEvents_1.WsEvents {
7
+ constructor(ws) {
8
+ super(CamSwitcherEvents_1.cswEventsSchema, ws);
65
9
  }
66
10
  }
67
11
  exports.CamSwitcherEvents = CamSwitcherEvents;
@@ -21,49 +21,49 @@ class PlaneTrackerAPI {
21
21
  const response = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
22
22
  return zod_1.z.boolean().parse(response.state);
23
23
  }
24
- resetPtzCalibration = async (options) => {
24
+ async resetPtzCalibration(options) {
25
25
  const agent = this.getClient(options?.proxyParams);
26
26
  return await agent.get({
27
27
  path: `${BASE_PATH}/package/resetPtzCalibration.cgi`,
28
28
  parameters: this.apiUser,
29
29
  timeout: options?.timeout,
30
30
  });
31
- };
32
- resetFocusCalibration = async (options) => {
31
+ }
32
+ async resetFocusCalibration(options) {
33
33
  const agent = this.getClient(options?.proxyParams);
34
34
  return await agent.get({
35
35
  path: `${BASE_PATH}/package/resetFocusCalibration.cgi`,
36
36
  parameters: this.apiUser,
37
37
  timeout: options?.timeout,
38
38
  });
39
- };
40
- serverRunCheck = async (options) => {
39
+ }
40
+ async serverRunCheck(options) {
41
41
  const agent = this.getClient(options?.proxyParams);
42
42
  return await agent.get({ path: `${BASE_PATH}/package/serverRunCheck.cgi`, timeout: options?.timeout });
43
- };
44
- getLiveViewAlias = async (rtspUrl, options) => {
43
+ }
44
+ async getLiveViewAlias(rtspUrl, options) {
45
45
  const agent = this.getClient(options?.proxyParams);
46
46
  return await agent.get({
47
47
  path: `${BASE_PATH}/getLiveViewAlias.cgi`,
48
48
  parameters: { rtsp_url: rtspUrl },
49
49
  timeout: options?.timeout,
50
50
  });
51
- };
52
- fetchCameraSettings = async (options) => {
51
+ }
52
+ async fetchCameraSettings(options) {
53
53
  return await this._getJson(`${BASE_PATH}/package_camera_settings.cgi`, { action: 'get' }, options);
54
- };
55
- setCameraSettings = async (settingsJsonString, options) => {
54
+ }
55
+ async setCameraSettings(settingsJsonString, options) {
56
56
  return await this._postJsonEncoded(`${BASE_PATH}/package_camera_settings.cgi`, settingsJsonString, {
57
57
  action: 'set',
58
58
  }, options);
59
- };
60
- fetchServerSettings = async (options) => {
59
+ }
60
+ async fetchServerSettings(options) {
61
61
  return await this._getJson(`${BASE_PATH}/package_server_settings.cgi`, { action: 'get' }, options);
62
- };
63
- exportAppSettings = async (dataType, options) => {
62
+ }
63
+ async exportAppSettings(dataType, options) {
64
64
  return await this._getBlob(`${BASE_PATH}/package_data.cgi`, { action: 'EXPORT', dataType }, options);
65
- };
66
- importAppSettings = async (dataType, formData, options) => {
65
+ }
66
+ async importAppSettings(dataType, formData, options) {
67
67
  const agent = this.getClient(options?.proxyParams);
68
68
  return await agent.post({
69
69
  path: `${BASE_PATH}/package_data.cgi`,
@@ -71,74 +71,74 @@ class PlaneTrackerAPI {
71
71
  parameters: { action: 'IMPORT', dataType },
72
72
  timeout: options?.timeout,
73
73
  });
74
- };
75
- fetchFlightInfo = async (icao, options) => {
74
+ }
75
+ async fetchFlightInfo(icao, options) {
76
76
  return await this._getJson(`${BASE_PATH}/package/flightInfo.cgi`, { icao: encodeURIComponent(icao) }, options);
77
- };
78
- getTrackingMode = async (options) => {
77
+ }
78
+ async getTrackingMode(options) {
79
79
  return await this._getJson(`${BASE_PATH}/package/getTrackingMode.cgi`, undefined, options);
80
- };
81
- setTrackingMode = async (modeJsonString, options) => {
80
+ }
81
+ async setTrackingMode(modeJsonString, options) {
82
82
  return await this._postJsonEncoded(`${BASE_PATH}/package/setTrackingMode.cgi`, modeJsonString, this.apiUser, options);
83
- };
84
- startTrackingPlane = async (icao, options) => {
83
+ }
84
+ async startTrackingPlane(icao, options) {
85
85
  const agent = this.getClient(options?.proxyParams);
86
86
  return await agent.get({
87
87
  path: `${BASE_PATH}/package/trackIcao.cgi`,
88
88
  parameters: { icao, ...this.apiUser },
89
89
  timeout: options?.timeout,
90
90
  });
91
- };
92
- stopTrackingPlane = async (options) => {
91
+ }
92
+ async stopTrackingPlane(options) {
93
93
  const agent = this.getClient(options?.proxyParams);
94
94
  return await agent.get({
95
95
  path: `${BASE_PATH}/package/resetIcao.cgi`,
96
96
  parameters: this.apiUser,
97
97
  timeout: options?.timeout,
98
98
  });
99
- };
100
- getPriorityList = async (options) => {
99
+ }
100
+ async getPriorityList(options) {
101
101
  return await this._getJson(`${BASE_PATH}/package/getPriorityList.cgi`, undefined, options);
102
- };
103
- setPriorityList = async (priorityListJsonString, options) => {
102
+ }
103
+ async setPriorityList(priorityListJsonString, options) {
104
104
  return await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`, priorityListJsonString, this.apiUser, options);
105
- };
106
- getWhiteList = async (options) => {
105
+ }
106
+ async getWhiteList(options) {
107
107
  return await this._getJson(`${BASE_PATH}/package/getWhiteList.cgi`, undefined, options);
108
- };
109
- setWhiteList = async (whiteListJsonString, options) => {
108
+ }
109
+ async setWhiteList(whiteListJsonString, options) {
110
110
  return await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`, whiteListJsonString, this.apiUser, options);
111
- };
112
- getBlackList = async (options) => {
111
+ }
112
+ async getBlackList(options) {
113
113
  return await this._getJson(`${BASE_PATH}/package/getBlackList.cgi`, undefined, options);
114
- };
115
- setBlackList = async (blackListJsonString, options) => {
114
+ }
115
+ async setBlackList(blackListJsonString, options) {
116
116
  return await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`, blackListJsonString, this.apiUser, options);
117
- };
118
- fetchMapInfo = async (options) => {
117
+ }
118
+ async fetchMapInfo(options) {
119
119
  return await this._getJson(`${BASE_PATH}/package/getMapInfo.cgi`, undefined, options);
120
- };
121
- getZones = async (options) => {
120
+ }
121
+ async getZones(options) {
122
122
  return await this._getJson(`${BASE_PATH}/package/getZones.cgi`, undefined, options);
123
- };
124
- setZones = async (zonesJsonString, options) => {
123
+ }
124
+ async setZones(zonesJsonString, options) {
125
125
  return await this._postJsonEncoded(`${BASE_PATH}/package/setZones.cgi`, zonesJsonString, this.apiUser, options);
126
- };
127
- goToCoordinates = async (lat, lon, alt, options) => {
126
+ }
127
+ async goToCoordinates(lat, lon, alt, options) {
128
128
  const agent = this.getClient(options?.proxyParams);
129
129
  return await agent.get({
130
130
  path: `${BASE_PATH}/package/goToCoordinates.cgi`,
131
131
  parameters: { lat, lon, alt, ...this.apiUser },
132
132
  timeout: options?.timeout,
133
133
  });
134
- };
135
- checkGenetecConnection = async (params, options) => {
134
+ }
135
+ async checkGenetecConnection(params, options) {
136
136
  return await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
137
- };
138
- getGenetecCameraList = async (params, options) => {
137
+ }
138
+ async getGenetecCameraList(params, options) {
139
139
  const res = await this._postUrlEncoded(`${BASE_PATH}/package/getGenetecCameraList.cgi`, params, options);
140
140
  return await res.json();
141
- };
141
+ }
142
142
  async _getJson(path, parameters, options) {
143
143
  const agent = this.getClient(options?.proxyParams);
144
144
  const res = await agent.get({
package/cjs/VapixAPI.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VapixAPI = void 0;
4
- const prettifyXml = require("prettify-xml");
5
4
  const utils_1 = require("./internal/utils");
6
5
  const VapixAPI_1 = require("./types/VapixAPI");
7
6
  const errors_1 = require("./errors/errors");
@@ -10,8 +9,10 @@ const zod_1 = require("zod");
10
9
  const fast_xml_parser_1 = require("fast-xml-parser");
11
10
  class VapixAPI {
12
11
  client;
13
- constructor(client) {
12
+ CustomFormData;
13
+ constructor(client, CustomFormData = FormData) {
14
14
  this.client = client;
15
+ this.CustomFormData = CustomFormData;
15
16
  }
16
17
  getClient(proxyParams) {
17
18
  return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
@@ -38,7 +39,11 @@ class VapixAPI {
38
39
  }
39
40
  async getCameraImage(parameters, options) {
40
41
  const agent = this.getClient(options?.proxyParams);
41
- return await agent.get({ path: '/axis-cgi/jpg/image.cgi', parameters, timeout: options?.timeout });
42
+ return (await agent.get({
43
+ path: '/axis-cgi/jpg/image.cgi',
44
+ parameters,
45
+ timeout: options?.timeout,
46
+ }));
42
47
  }
43
48
  async getEventDeclarations(options) {
44
49
  const data = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">' +
@@ -56,8 +61,7 @@ class VapixAPI {
56
61
  if (!res.ok) {
57
62
  throw new Error(await (0, utils_1.responseStringify)(res));
58
63
  }
59
- const declarations = await res.text();
60
- return prettifyXml(declarations);
64
+ return await res.text();
61
65
  }
62
66
  async getSupportedAudioSampleRate(options) {
63
67
  const path = '/axis-cgi/audio/streamingcapabilities.cgi';
@@ -253,7 +257,6 @@ class VapixAPI {
253
257
  if (responseText.startsWith('# Error')) {
254
258
  throw new Error(responseText);
255
259
  }
256
- return true;
257
260
  }
258
261
  async getGuardTourList(options) {
259
262
  const gTourList = new Array();
@@ -458,7 +461,7 @@ class VapixAPI {
458
461
  }
459
462
  }
460
463
  async installApplication(data, fileName, options) {
461
- const formData = new FormData();
464
+ const formData = new this.CustomFormData();
462
465
  formData.append('packfil', data, fileName);
463
466
  const agent = this.getClient(options?.proxyParams);
464
467
  const res = await agent.post({
package/cjs/index.js CHANGED
@@ -14,11 +14,12 @@ 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.CamOverlayDrawingAPI = exports.ResourceManager = exports.Painter = exports.Frame = exports.PlaneTrackerAPI = exports.CamStreamerAPI = exports.CamScripterAPI = exports.CamOverlayAPI = exports.VapixAPI = exports.CamSwitcherEvents = exports.CamSwitcherAPI = void 0;
17
+ exports.PlaneTrackerAPI = exports.CamStreamerAPI = exports.CamScripterAPI = exports.CamOverlayAPI = exports.VapixAPI = exports.CamSwitcherEvents = exports.CamSwitcherAPI = 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
+ __exportStar(require("./internal/ProxyClient"), exports);
22
23
  __exportStar(require("./types/common"), exports);
23
24
  var CamSwitcherAPI_1 = require("./CamSwitcherAPI");
24
25
  Object.defineProperty(exports, "CamSwitcherAPI", { enumerable: true, get: function () { return CamSwitcherAPI_1.CamSwitcherAPI; } });
@@ -39,13 +40,3 @@ __exportStar(require("./types/CamSwitcherAPI"), exports);
39
40
  __exportStar(require("./types/VapixAPI"), exports);
40
41
  __exportStar(require("./types/CamOverlayAPI"), exports);
41
42
  __exportStar(require("./types/PlaneTrackerAPI"), exports);
42
- var Frame_1 = require("./CamOverlayPainter/Frame");
43
- Object.defineProperty(exports, "Frame", { enumerable: true, get: function () { return Frame_1.Frame; } });
44
- var Painter_1 = require("./CamOverlayPainter/Painter");
45
- Object.defineProperty(exports, "Painter", { enumerable: true, get: function () { return Painter_1.Painter; } });
46
- var ResourceManager_1 = require("./CamOverlayPainter/ResourceManager");
47
- Object.defineProperty(exports, "ResourceManager", { enumerable: true, get: function () { return ResourceManager_1.ResourceManager; } });
48
- __exportStar(require("./types/CamOverlayPainter"), exports);
49
- var CamOverlayDrawingAPI_1 = require("./CamOverlayDrawingAPI");
50
- Object.defineProperty(exports, "CamOverlayDrawingAPI", { enumerable: true, get: function () { return CamOverlayDrawingAPI_1.CamOverlayDrawingAPI; } });
51
- __exportStar(require("./types/CamOverlayDrawingAPI"), exports);
@@ -9,19 +9,19 @@ class ProxyClient {
9
9
  this.client = client;
10
10
  this.proxyParams = proxyParams;
11
11
  }
12
- get = (params) => {
12
+ get(params) {
13
13
  const { path, parameters, headers, timeout } = params;
14
14
  const targetPath = (0, utils_1.addParametersToPath)(path, parameters);
15
15
  const { realPath, realHeaders } = this.getReal(targetPath, headers);
16
16
  return this.client.get({ path: realPath, headers: realHeaders, timeout });
17
- };
18
- post = (params) => {
17
+ }
18
+ post(params) {
19
19
  const { path, data, parameters, headers, timeout } = params;
20
20
  const targetPath = (0, utils_1.addParametersToPath)(path, parameters);
21
21
  const { realPath, realHeaders } = this.getReal(targetPath, headers);
22
22
  return this.client.post({ path: realPath, data, headers: realHeaders, timeout });
23
- };
24
- getReal = (targetPath, headers) => {
23
+ }
24
+ getReal(targetPath, headers) {
25
25
  return {
26
26
  realPath: this.proxyParams.path,
27
27
  realHeaders: {
@@ -35,6 +35,6 @@ class ProxyClient {
35
35
  'x-target-camera-user': this.proxyParams.target.user,
36
36
  },
37
37
  };
38
- };
38
+ }
39
39
  }
40
40
  exports.ProxyClient = ProxyClient;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WsEvents = void 0;
4
+ class WsEvents {
5
+ zodSchema;
6
+ ws;
7
+ _isDestroyed = false;
8
+ listeners = {};
9
+ constructor(zodSchema, ws) {
10
+ this.zodSchema = zodSchema;
11
+ this.ws = ws;
12
+ this.ws.onmessage = (e) => this.onMessage(e);
13
+ }
14
+ get isDestroyed() {
15
+ return this._isDestroyed;
16
+ }
17
+ resendInitData() {
18
+ const request = {
19
+ command: 'sendInitData',
20
+ };
21
+ this.ws.send(JSON.stringify(request));
22
+ }
23
+ addListener(type, listener, id) {
24
+ const typeList = this.listeners[type];
25
+ if (typeList === undefined) {
26
+ this.listeners[type] = { [id]: listener };
27
+ return;
28
+ }
29
+ typeList[id] = listener;
30
+ }
31
+ removeListener(type, id) {
32
+ const typeList = this.listeners[type];
33
+ if (typeList) {
34
+ delete typeList[id];
35
+ if (Object.keys(typeList).length === 0) {
36
+ delete this.listeners[type];
37
+ }
38
+ }
39
+ }
40
+ onMessage(evt) {
41
+ if (this.isDestroyed) {
42
+ return;
43
+ }
44
+ try {
45
+ const eventData = JSON.parse(evt.data);
46
+ const data = this.zodSchema.parse(eventData);
47
+ if (isInitEvent(data)) {
48
+ this.processMessage(data.data, true);
49
+ return;
50
+ }
51
+ this.processMessage(data, false);
52
+ }
53
+ catch (error) {
54
+ console.error('Error parsing event data:', evt.data, error);
55
+ }
56
+ }
57
+ processMessage(event, isInit) {
58
+ const listeners = this.listeners[event.type];
59
+ const list = Object.values(listeners ?? {});
60
+ list.forEach((listener) => listener(event, isInit));
61
+ }
62
+ destroy() {
63
+ this._isDestroyed = true;
64
+ this.ws.onmessage = () => { };
65
+ this.ws.destroy();
66
+ this.listeners = {};
67
+ }
68
+ }
69
+ exports.WsEvents = WsEvents;
70
+ const isInitEvent = (event) => {
71
+ return event.type === 'init';
72
+ };
@@ -25,16 +25,16 @@ class DefaultClient {
25
25
  }
26
26
  this.httpRequestSender = new HttpRequestSender_1.HttpRequestSender(agentOptions);
27
27
  }
28
- get = (params) => {
28
+ get(params) {
29
29
  const { path, parameters, headers, timeout } = params;
30
30
  const options = this.getBaseConnectionParams('GET', path, parameters, headers, timeout);
31
31
  return this.httpRequestSender.sendRequest(options);
32
- };
33
- post = (params) => {
32
+ }
33
+ post(params) {
34
34
  const { path, data, parameters, headers, timeout } = params;
35
35
  const options = this.getBaseConnectionParams('POST', path, parameters, headers, timeout);
36
36
  return this.httpRequestSender.sendRequest(options, data);
37
- };
37
+ }
38
38
  getBaseConnectionParams(method, path, params, headers, timeout) {
39
39
  return {
40
40
  method: method,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpRequestSender = void 0;
4
- const Digest_1 = require("../internal/Digest");
4
+ const Digest_1 = require("./Digest");
5
5
  const undici_1 = require("undici");
6
6
  class HttpRequestSender {
7
7
  agent;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WsClient = void 0;
4
4
  const EventEmitter = require("events");
5
5
  const WebSocket = require("ws");
6
- const Digest_1 = require("../internal/Digest");
6
+ const Digest_1 = require("./Digest");
7
7
  class WsClient extends EventEmitter {
8
8
  user;
9
9
  pass;