camstreamerlib 4.0.0-beta.32 → 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 (155) 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 +43 -32
  15. package/cjs/node/index.js +5 -8
  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 +41 -30
  33. package/esm/node/index.js +5 -4
  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}/events/GenetecAgent.d.ts +14 -32
  52. package/types/node/index.d.ts +5 -0
  53. package/{cjs → types}/types/CamOverlayAPI/CamOverlayAPI.d.ts +1071 -7
  54. package/{esm → types}/types/CamOverlayAPI/infotickerSchema.d.ts +2 -2
  55. package/types/types/CamOverlayAPI/scoreBoardSchema.d.ts +357 -0
  56. package/types/types/CamStreamerAPI.d.ts +274 -0
  57. package/types/web/DefaultClient.d.ts +6 -0
  58. package/cjs/CamScripterAPI.d.ts +0 -37
  59. package/cjs/CamStreamerAPI.d.ts +0 -19
  60. package/cjs/CamSwitcherAPI.d.ts +0 -54
  61. package/cjs/CamSwitcherEvents.d.ts +0 -18
  62. package/cjs/PlaneTrackerAPI.d.ts +0 -43
  63. package/cjs/events/AxisCameraStationEvents.d.ts +0 -12
  64. package/cjs/events/GenetecAgent.d.ts +0 -177
  65. package/cjs/internal/ProxyClient.d.ts +0 -10
  66. package/cjs/internal/types.d.ts +0 -42
  67. package/cjs/node/index.d.ts +0 -4
  68. package/cjs/types/CamOverlayAPI/infotickerSchema.d.ts +0 -96
  69. package/cjs/types/CamStreamerAPI.d.ts +0 -150
  70. package/cjs/web/DefaultClient.d.ts +0 -6
  71. package/esm/CamOverlayAPI.d.ts +0 -41
  72. package/esm/CamOverlayDrawingAPI.d.ts +0 -41
  73. package/esm/CamOverlayPainter/Frame.d.ts +0 -67
  74. package/esm/CamOverlayPainter/Painter.d.ts +0 -43
  75. package/esm/CamOverlayPainter/ResourceManager.d.ts +0 -15
  76. package/esm/CamScripterAPICameraEventsGenerator.d.ts +0 -74
  77. package/esm/CamStreamerAPI.d.ts +0 -19
  78. package/esm/CamSwitcherEvents.d.ts +0 -18
  79. package/esm/CreatePackage.d.ts +0 -1
  80. package/esm/PlaneTrackerAPI.d.ts +0 -43
  81. package/esm/VapixAPI.d.ts +0 -80
  82. package/esm/VapixEvents.d.ts +0 -43
  83. package/esm/errors/errors.d.ts +0 -37
  84. package/esm/index.d.ts +0 -23
  85. package/esm/internal/Digest.d.ts +0 -4
  86. package/esm/internal/constants.d.ts +0 -1
  87. package/esm/internal/transformers.d.ts +0 -5
  88. package/esm/internal/utils.d.ts +0 -14
  89. package/esm/internal/versionCompare.d.ts +0 -6
  90. package/esm/node/DefaultClient.d.ts +0 -14
  91. package/esm/node/HttpRequestSender.d.ts +0 -29
  92. package/esm/node/HttpServer.d.ts +0 -21
  93. package/esm/node/WsClient.d.ts +0 -40
  94. package/esm/node/index.d.ts +0 -4
  95. package/esm/types/CamOverlayAPI/CamOverlayAPI.d.ts +0 -3260
  96. package/esm/types/CamOverlayAPI/accuweatherSchema.d.ts +0 -84
  97. package/esm/types/CamOverlayAPI/customGraphicsSchema.d.ts +0 -700
  98. package/esm/types/CamOverlayAPI/imagesSchema.d.ts +0 -95
  99. package/esm/types/CamOverlayAPI/index.d.ts +0 -11
  100. package/esm/types/CamOverlayAPI/pipSchema.d.ts +0 -125
  101. package/esm/types/CamOverlayAPI/ptzCompassSchema.d.ts +0 -93
  102. package/esm/types/CamOverlayAPI/ptzSchema.d.ts +0 -118
  103. package/esm/types/CamOverlayAPI/screenSharingSchema.d.ts +0 -58
  104. package/esm/types/CamOverlayAPI/webCameraSharingSchema.d.ts +0 -58
  105. package/esm/types/CamOverlayAPI/widgetCommonTypes.d.ts +0 -141
  106. package/esm/types/CamOverlayDrawingAPI.d.ts +0 -58
  107. package/esm/types/CamOverlayPainter.d.ts +0 -74
  108. package/esm/types/CamScripterAPI.d.ts +0 -132
  109. package/esm/types/CamStreamerAPI.d.ts +0 -150
  110. package/esm/types/CamSwitcherAPI.d.ts +0 -812
  111. package/esm/types/CamSwitcherEvents.d.ts +0 -568
  112. package/esm/types/PlaneTrackerAPI.d.ts +0 -8
  113. package/esm/types/VapixAPI.d.ts +0 -1819
  114. package/esm/types/common.d.ts +0 -46
  115. package/esm/web/DefaultClient.d.ts +0 -6
  116. package/esm/web/WsClient.d.ts +0 -13
  117. package/esm/web/index.d.ts +0 -2
  118. /package/cjs/{internal → node}/Digest.js +0 -0
  119. /package/esm/{internal → node}/Digest.js +0 -0
  120. /package/{cjs → types}/CamOverlayDrawingAPI.d.ts +0 -0
  121. /package/{cjs → types}/CamOverlayPainter/Frame.d.ts +0 -0
  122. /package/{cjs → types}/CamOverlayPainter/Painter.d.ts +0 -0
  123. /package/{cjs → types}/CamOverlayPainter/ResourceManager.d.ts +0 -0
  124. /package/{cjs → types}/CamScripterAPICameraEventsGenerator.d.ts +0 -0
  125. /package/{cjs → types}/CreatePackage.d.ts +0 -0
  126. /package/{cjs → types}/VapixEvents.d.ts +0 -0
  127. /package/{cjs → types}/errors/errors.d.ts +0 -0
  128. /package/{cjs → types}/internal/constants.d.ts +0 -0
  129. /package/{cjs → types}/internal/transformers.d.ts +0 -0
  130. /package/{cjs → types}/internal/utils.d.ts +0 -0
  131. /package/{cjs → types}/internal/versionCompare.d.ts +0 -0
  132. /package/{cjs/internal → types/node}/Digest.d.ts +0 -0
  133. /package/{cjs → types}/node/HttpRequestSender.d.ts +0 -0
  134. /package/{cjs → types}/node/HttpServer.d.ts +0 -0
  135. /package/{cjs → types}/node/WsClient.d.ts +0 -0
  136. /package/{cjs → types}/types/CamOverlayAPI/accuweatherSchema.d.ts +0 -0
  137. /package/{cjs → types}/types/CamOverlayAPI/customGraphicsSchema.d.ts +0 -0
  138. /package/{cjs → types}/types/CamOverlayAPI/imagesSchema.d.ts +0 -0
  139. /package/{cjs → types}/types/CamOverlayAPI/index.d.ts +0 -0
  140. /package/{cjs → types}/types/CamOverlayAPI/pipSchema.d.ts +0 -0
  141. /package/{cjs → types}/types/CamOverlayAPI/ptzCompassSchema.d.ts +0 -0
  142. /package/{cjs → types}/types/CamOverlayAPI/ptzSchema.d.ts +0 -0
  143. /package/{cjs → types}/types/CamOverlayAPI/screenSharingSchema.d.ts +0 -0
  144. /package/{cjs → types}/types/CamOverlayAPI/webCameraSharingSchema.d.ts +0 -0
  145. /package/{cjs → types}/types/CamOverlayAPI/widgetCommonTypes.d.ts +0 -0
  146. /package/{cjs → types}/types/CamOverlayDrawingAPI.d.ts +0 -0
  147. /package/{cjs → types}/types/CamOverlayPainter.d.ts +0 -0
  148. /package/{cjs → types}/types/CamScripterAPI.d.ts +0 -0
  149. /package/{cjs → types}/types/CamSwitcherAPI.d.ts +0 -0
  150. /package/{cjs → types}/types/CamSwitcherEvents.d.ts +0 -0
  151. /package/{cjs → types}/types/PlaneTrackerAPI.d.ts +0 -0
  152. /package/{cjs → types}/types/VapixAPI.d.ts +0 -0
  153. /package/{cjs → types}/types/common.d.ts +0 -0
  154. /package/{cjs → types}/web/WsClient.d.ts +0 -0
  155. /package/{cjs → types}/web/index.d.ts +0 -0
@@ -18,49 +18,49 @@ export class PlaneTrackerAPI {
18
18
  const response = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
19
19
  return z.boolean().parse(response.state);
20
20
  }
21
- resetPtzCalibration = async (options) => {
21
+ async resetPtzCalibration(options) {
22
22
  const agent = this.getClient(options?.proxyParams);
23
23
  return await agent.get({
24
24
  path: `${BASE_PATH}/package/resetPtzCalibration.cgi`,
25
25
  parameters: this.apiUser,
26
26
  timeout: options?.timeout,
27
27
  });
28
- };
29
- resetFocusCalibration = async (options) => {
28
+ }
29
+ async resetFocusCalibration(options) {
30
30
  const agent = this.getClient(options?.proxyParams);
31
31
  return await agent.get({
32
32
  path: `${BASE_PATH}/package/resetFocusCalibration.cgi`,
33
33
  parameters: this.apiUser,
34
34
  timeout: options?.timeout,
35
35
  });
36
- };
37
- serverRunCheck = async (options) => {
36
+ }
37
+ async serverRunCheck(options) {
38
38
  const agent = this.getClient(options?.proxyParams);
39
39
  return await agent.get({ path: `${BASE_PATH}/package/serverRunCheck.cgi`, timeout: options?.timeout });
40
- };
41
- getLiveViewAlias = async (rtspUrl, options) => {
40
+ }
41
+ async getLiveViewAlias(rtspUrl, options) {
42
42
  const agent = this.getClient(options?.proxyParams);
43
43
  return await agent.get({
44
44
  path: `${BASE_PATH}/getLiveViewAlias.cgi`,
45
45
  parameters: { rtsp_url: rtspUrl },
46
46
  timeout: options?.timeout,
47
47
  });
48
- };
49
- fetchCameraSettings = async (options) => {
48
+ }
49
+ async fetchCameraSettings(options) {
50
50
  return await this._getJson(`${BASE_PATH}/package_camera_settings.cgi`, { action: 'get' }, options);
51
- };
52
- setCameraSettings = async (settingsJsonString, options) => {
51
+ }
52
+ async setCameraSettings(settingsJsonString, options) {
53
53
  return await this._postJsonEncoded(`${BASE_PATH}/package_camera_settings.cgi`, settingsJsonString, {
54
54
  action: 'set',
55
55
  }, options);
56
- };
57
- fetchServerSettings = async (options) => {
56
+ }
57
+ async fetchServerSettings(options) {
58
58
  return await this._getJson(`${BASE_PATH}/package_server_settings.cgi`, { action: 'get' }, options);
59
- };
60
- exportAppSettings = async (dataType, options) => {
59
+ }
60
+ async exportAppSettings(dataType, options) {
61
61
  return await this._getBlob(`${BASE_PATH}/package_data.cgi`, { action: 'EXPORT', dataType }, options);
62
- };
63
- importAppSettings = async (dataType, formData, options) => {
62
+ }
63
+ async importAppSettings(dataType, formData, options) {
64
64
  const agent = this.getClient(options?.proxyParams);
65
65
  return await agent.post({
66
66
  path: `${BASE_PATH}/package_data.cgi`,
@@ -68,74 +68,74 @@ export class PlaneTrackerAPI {
68
68
  parameters: { action: 'IMPORT', dataType },
69
69
  timeout: options?.timeout,
70
70
  });
71
- };
72
- fetchFlightInfo = async (icao, options) => {
71
+ }
72
+ async fetchFlightInfo(icao, options) {
73
73
  return await this._getJson(`${BASE_PATH}/package/flightInfo.cgi`, { icao: encodeURIComponent(icao) }, options);
74
- };
75
- getTrackingMode = async (options) => {
74
+ }
75
+ async getTrackingMode(options) {
76
76
  return await this._getJson(`${BASE_PATH}/package/getTrackingMode.cgi`, undefined, options);
77
- };
78
- setTrackingMode = async (modeJsonString, options) => {
77
+ }
78
+ async setTrackingMode(modeJsonString, options) {
79
79
  return await this._postJsonEncoded(`${BASE_PATH}/package/setTrackingMode.cgi`, modeJsonString, this.apiUser, options);
80
- };
81
- startTrackingPlane = async (icao, options) => {
80
+ }
81
+ async startTrackingPlane(icao, options) {
82
82
  const agent = this.getClient(options?.proxyParams);
83
83
  return await agent.get({
84
84
  path: `${BASE_PATH}/package/trackIcao.cgi`,
85
85
  parameters: { icao, ...this.apiUser },
86
86
  timeout: options?.timeout,
87
87
  });
88
- };
89
- stopTrackingPlane = async (options) => {
88
+ }
89
+ async stopTrackingPlane(options) {
90
90
  const agent = this.getClient(options?.proxyParams);
91
91
  return await agent.get({
92
92
  path: `${BASE_PATH}/package/resetIcao.cgi`,
93
93
  parameters: this.apiUser,
94
94
  timeout: options?.timeout,
95
95
  });
96
- };
97
- getPriorityList = async (options) => {
96
+ }
97
+ async getPriorityList(options) {
98
98
  return await this._getJson(`${BASE_PATH}/package/getPriorityList.cgi`, undefined, options);
99
- };
100
- setPriorityList = async (priorityListJsonString, options) => {
99
+ }
100
+ async setPriorityList(priorityListJsonString, options) {
101
101
  return await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`, priorityListJsonString, this.apiUser, options);
102
- };
103
- getWhiteList = async (options) => {
102
+ }
103
+ async getWhiteList(options) {
104
104
  return await this._getJson(`${BASE_PATH}/package/getWhiteList.cgi`, undefined, options);
105
- };
106
- setWhiteList = async (whiteListJsonString, options) => {
105
+ }
106
+ async setWhiteList(whiteListJsonString, options) {
107
107
  return await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`, whiteListJsonString, this.apiUser, options);
108
- };
109
- getBlackList = async (options) => {
108
+ }
109
+ async getBlackList(options) {
110
110
  return await this._getJson(`${BASE_PATH}/package/getBlackList.cgi`, undefined, options);
111
- };
112
- setBlackList = async (blackListJsonString, options) => {
111
+ }
112
+ async setBlackList(blackListJsonString, options) {
113
113
  return await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`, blackListJsonString, this.apiUser, options);
114
- };
115
- fetchMapInfo = async (options) => {
114
+ }
115
+ async fetchMapInfo(options) {
116
116
  return await this._getJson(`${BASE_PATH}/package/getMapInfo.cgi`, undefined, options);
117
- };
118
- getZones = async (options) => {
117
+ }
118
+ async getZones(options) {
119
119
  return await this._getJson(`${BASE_PATH}/package/getZones.cgi`, undefined, options);
120
- };
121
- setZones = async (zonesJsonString, options) => {
120
+ }
121
+ async setZones(zonesJsonString, options) {
122
122
  return await this._postJsonEncoded(`${BASE_PATH}/package/setZones.cgi`, zonesJsonString, this.apiUser, options);
123
- };
124
- goToCoordinates = async (lat, lon, alt, options) => {
123
+ }
124
+ async goToCoordinates(lat, lon, alt, options) {
125
125
  const agent = this.getClient(options?.proxyParams);
126
126
  return await agent.get({
127
127
  path: `${BASE_PATH}/package/goToCoordinates.cgi`,
128
128
  parameters: { lat, lon, alt, ...this.apiUser },
129
129
  timeout: options?.timeout,
130
130
  });
131
- };
132
- checkGenetecConnection = async (params, options) => {
131
+ }
132
+ async checkGenetecConnection(params, options) {
133
133
  return await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
134
- };
135
- getGenetecCameraList = async (params, options) => {
134
+ }
135
+ async getGenetecCameraList(params, options) {
136
136
  const res = await this._postUrlEncoded(`${BASE_PATH}/package/getGenetecCameraList.cgi`, params, options);
137
137
  return await res.json();
138
- };
138
+ }
139
139
  async _getJson(path, parameters, options) {
140
140
  const agent = this.getClient(options?.proxyParams);
141
141
  const res = await agent.get({
package/esm/VapixAPI.js CHANGED
@@ -1,4 +1,3 @@
1
- import * as prettifyXml from 'prettify-xml';
2
1
  import { arrayToUrl, isNullish, paramToUrl, responseStringify } from './internal/utils';
3
2
  import { sdCardWatchedStatuses, APP_IDS, maxFpsResponseSchema, dateTimeinfoSchema, audioDeviceRequestSchema, audioSampleRatesResponseSchema, timeZoneSchema, getPortsResponseSchema, } from './types/VapixAPI';
4
3
  import { ApplicationAPIError, MaxFPSError, NoDeviceInfoError, PtzNotSupportedError, SDCardActionError, SDCardJobError, } from './errors/errors';
@@ -7,8 +6,10 @@ import { z } from 'zod';
7
6
  import { XMLParser } from 'fast-xml-parser';
8
7
  export class VapixAPI {
9
8
  client;
10
- constructor(client) {
9
+ CustomFormData;
10
+ constructor(client, CustomFormData = FormData) {
11
11
  this.client = client;
12
+ this.CustomFormData = CustomFormData;
12
13
  }
13
14
  getClient(proxyParams) {
14
15
  return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
@@ -35,7 +36,11 @@ export class VapixAPI {
35
36
  }
36
37
  async getCameraImage(parameters, options) {
37
38
  const agent = this.getClient(options?.proxyParams);
38
- return await agent.get({ path: '/axis-cgi/jpg/image.cgi', parameters, timeout: options?.timeout });
39
+ return (await agent.get({
40
+ path: '/axis-cgi/jpg/image.cgi',
41
+ parameters,
42
+ timeout: options?.timeout,
43
+ }));
39
44
  }
40
45
  async getEventDeclarations(options) {
41
46
  const data = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">' +
@@ -53,8 +58,7 @@ export class VapixAPI {
53
58
  if (!res.ok) {
54
59
  throw new Error(await responseStringify(res));
55
60
  }
56
- const declarations = await res.text();
57
- return prettifyXml(declarations);
61
+ return await res.text();
58
62
  }
59
63
  async getSupportedAudioSampleRate(options) {
60
64
  const path = '/axis-cgi/audio/streamingcapabilities.cgi';
@@ -250,7 +254,6 @@ export class VapixAPI {
250
254
  if (responseText.startsWith('# Error')) {
251
255
  throw new Error(responseText);
252
256
  }
253
- return true;
254
257
  }
255
258
  async getGuardTourList(options) {
256
259
  const gTourList = new Array();
@@ -455,7 +458,7 @@ export class VapixAPI {
455
458
  }
456
459
  }
457
460
  async installApplication(data, fileName, options) {
458
- const formData = new FormData();
461
+ const formData = new this.CustomFormData();
459
462
  formData.append('packfil', data, fileName);
460
463
  const agent = this.getClient(options?.proxyParams);
461
464
  const res = await agent.post({
package/esm/index.js CHANGED
@@ -2,6 +2,7 @@ export * from './internal/types';
2
2
  export * from './internal/constants';
3
3
  export * from './internal/utils';
4
4
  export * from './internal/versionCompare';
5
+ export * from './internal/ProxyClient';
5
6
  export * from './types/common';
6
7
  export { CamSwitcherAPI } from './CamSwitcherAPI';
7
8
  export { CamSwitcherEvents } from './CamSwitcherEvents';
@@ -15,9 +16,3 @@ export * from './types/CamSwitcherAPI';
15
16
  export * from './types/VapixAPI';
16
17
  export * from './types/CamOverlayAPI';
17
18
  export * from './types/PlaneTrackerAPI';
18
- export { Frame } from './CamOverlayPainter/Frame';
19
- export { Painter } from './CamOverlayPainter/Painter';
20
- export { ResourceManager } from './CamOverlayPainter/ResourceManager';
21
- export * from './types/CamOverlayPainter';
22
- export { CamOverlayDrawingAPI } from './CamOverlayDrawingAPI';
23
- export * from './types/CamOverlayDrawingAPI';
@@ -6,19 +6,19 @@ export class ProxyClient {
6
6
  this.client = client;
7
7
  this.proxyParams = proxyParams;
8
8
  }
9
- get = (params) => {
9
+ get(params) {
10
10
  const { path, parameters, headers, timeout } = params;
11
11
  const targetPath = addParametersToPath(path, parameters);
12
12
  const { realPath, realHeaders } = this.getReal(targetPath, headers);
13
13
  return this.client.get({ path: realPath, headers: realHeaders, timeout });
14
- };
15
- post = (params) => {
14
+ }
15
+ post(params) {
16
16
  const { path, data, parameters, headers, timeout } = params;
17
17
  const targetPath = addParametersToPath(path, parameters);
18
18
  const { realPath, realHeaders } = this.getReal(targetPath, headers);
19
19
  return this.client.post({ path: realPath, data, headers: realHeaders, timeout });
20
- };
21
- getReal = (targetPath, headers) => {
20
+ }
21
+ getReal(targetPath, headers) {
22
22
  return {
23
23
  realPath: this.proxyParams.path,
24
24
  realHeaders: {
@@ -32,5 +32,5 @@ export class ProxyClient {
32
32
  'x-target-camera-user': this.proxyParams.target.user,
33
33
  },
34
34
  };
35
- };
35
+ }
36
36
  }
@@ -0,0 +1,68 @@
1
+ export class WsEvents {
2
+ zodSchema;
3
+ ws;
4
+ _isDestroyed = false;
5
+ listeners = {};
6
+ constructor(zodSchema, ws) {
7
+ this.zodSchema = zodSchema;
8
+ this.ws = ws;
9
+ this.ws.onmessage = (e) => this.onMessage(e);
10
+ }
11
+ get isDestroyed() {
12
+ return this._isDestroyed;
13
+ }
14
+ resendInitData() {
15
+ const request = {
16
+ command: 'sendInitData',
17
+ };
18
+ this.ws.send(JSON.stringify(request));
19
+ }
20
+ addListener(type, listener, id) {
21
+ const typeList = this.listeners[type];
22
+ if (typeList === undefined) {
23
+ this.listeners[type] = { [id]: listener };
24
+ return;
25
+ }
26
+ typeList[id] = listener;
27
+ }
28
+ removeListener(type, id) {
29
+ const typeList = this.listeners[type];
30
+ if (typeList) {
31
+ delete typeList[id];
32
+ if (Object.keys(typeList).length === 0) {
33
+ delete this.listeners[type];
34
+ }
35
+ }
36
+ }
37
+ onMessage(evt) {
38
+ if (this.isDestroyed) {
39
+ return;
40
+ }
41
+ try {
42
+ const eventData = JSON.parse(evt.data);
43
+ const data = this.zodSchema.parse(eventData);
44
+ if (isInitEvent(data)) {
45
+ this.processMessage(data.data, true);
46
+ return;
47
+ }
48
+ this.processMessage(data, false);
49
+ }
50
+ catch (error) {
51
+ console.error('Error parsing event data:', evt.data, error);
52
+ }
53
+ }
54
+ processMessage(event, isInit) {
55
+ const listeners = this.listeners[event.type];
56
+ const list = Object.values(listeners ?? {});
57
+ list.forEach((listener) => listener(event, isInit));
58
+ }
59
+ destroy() {
60
+ this._isDestroyed = true;
61
+ this.ws.onmessage = () => { };
62
+ this.ws.destroy();
63
+ this.listeners = {};
64
+ }
65
+ }
66
+ const isInitEvent = (event) => {
67
+ return event.type === 'init';
68
+ };
@@ -22,16 +22,16 @@ export class DefaultClient {
22
22
  }
23
23
  this.httpRequestSender = new HttpRequestSender(agentOptions);
24
24
  }
25
- get = (params) => {
25
+ get(params) {
26
26
  const { path, parameters, headers, timeout } = params;
27
27
  const options = this.getBaseConnectionParams('GET', path, parameters, headers, timeout);
28
28
  return this.httpRequestSender.sendRequest(options);
29
- };
30
- post = (params) => {
29
+ }
30
+ post(params) {
31
31
  const { path, data, parameters, headers, timeout } = params;
32
32
  const options = this.getBaseConnectionParams('POST', path, parameters, headers, timeout);
33
33
  return this.httpRequestSender.sendRequest(options, data);
34
- };
34
+ }
35
35
  getBaseConnectionParams(method, path, params, headers, timeout) {
36
36
  return {
37
37
  method: method,
@@ -1,4 +1,4 @@
1
- import { Digest } from '../internal/Digest';
1
+ import { Digest } from './Digest';
2
2
  import { Agent, fetch as undiciFetch, Request as UndiciRequest, } from 'undici';
3
3
  export class HttpRequestSender {
4
4
  agent;
@@ -1,6 +1,6 @@
1
1
  import * as EventEmitter from 'events';
2
2
  import * as WebSocket from 'ws';
3
- import { Digest } from '../internal/Digest';
3
+ import { Digest } from './Digest';
4
4
  export class WsClient extends EventEmitter {
5
5
  user;
6
6
  pass;
@@ -1,6 +1,6 @@
1
- import { pad } from '../internal/utils';
2
- import { ProxyClient } from '../internal/ProxyClient';
3
- import { DefaultClient } from '../node';
1
+ import { pad } from '../../internal/utils';
2
+ import { ProxyClient } from '../../internal/ProxyClient';
3
+ import { DefaultClient } from '../DefaultClient';
4
4
  export class AxisCameraStationEvents {
5
5
  sourceKey;
6
6
  client;
@@ -1,27 +1,24 @@
1
1
  import { z } from 'zod';
2
- import { responseStringify, pad } from '../internal/utils';
3
- const ACTION = 'AddCameraBookmark';
4
- const GET_CAMERAS_URL = 'report/EntityConfiguration?q=EntityTypes@Camera';
5
- const GET_CAMERAS_DETAILS_URL = '/entity?q=';
6
- const cameraGuidsResponseSchema = z.object({
2
+ import { responseStringify, pad } from '../../internal/utils';
3
+ const successResponseSchema = z.object({
7
4
  Rsp: z.object({
8
- Status: z.string(),
9
- Result: z.array(z.object({ Guid: z.string() })),
5
+ Status: z.literal('Ok'),
10
6
  }),
11
7
  });
12
- const connectionResponseSchema = z.object({
8
+ const cameraGuidsResponseSchema = z.object({
13
9
  Rsp: z.object({
14
- Status: z.string(),
10
+ Status: z.literal('Ok'),
11
+ Result: z.array(z.object({ Guid: z.string() })),
15
12
  }),
16
13
  });
17
- export const cameraDetailSchema = z.object({
14
+ const cameraDetailSchema = z.object({
18
15
  Guid: z.string().optional(),
19
16
  Name: z.string().optional(),
20
17
  EntityType: z.string().optional(),
21
18
  });
22
- export const cameraDetailsResponseSchema = z.object({
19
+ const cameraDetailsResponseSchema = z.object({
23
20
  Rsp: z.object({
24
- Status: z.string(),
21
+ Status: z.literal('Ok'),
25
22
  Result: z.union([z.array(cameraDetailSchema), cameraDetailSchema]),
26
23
  }),
27
24
  });
@@ -45,56 +42,70 @@ export class GenetecAgent {
45
42
  }
46
43
  async checkConnection() {
47
44
  const requestOptions = this.getRequestOptions('GET');
48
- const res = await this.fetchWithTimeout(`${this.baseUrl}/`, requestOptions);
45
+ const res = await this.fetchWithTimeout(new URL(this.baseUrl), requestOptions);
49
46
  if (!res.ok) {
50
47
  throw new Error(await responseStringify(res));
51
48
  }
52
- return connectionResponseSchema.parse(await res.json());
49
+ const responseBody = await res.text();
50
+ const result = await successResponseSchema.safeParseAsync(JSON.parse(responseBody));
51
+ if (!result.success) {
52
+ throw new Error('Genetec connection test failed: ' + JSON.stringify(result.error.issues) + '\n' + responseBody);
53
+ }
53
54
  }
54
55
  async getAllCameraGuids() {
55
56
  const requestOptions = this.getRequestOptions('GET');
56
- const res = await this.fetchWithTimeout(`${this.baseUrl}/${GET_CAMERAS_URL}`, requestOptions);
57
+ const url = new URL(`${this.baseUrl}/report/EntityConfiguration`);
58
+ url.searchParams.set('q', 'EntityTypes@Camera');
59
+ const res = await this.fetchWithTimeout(url, requestOptions);
57
60
  if (!res.ok) {
58
61
  throw new Error(await responseStringify(res));
59
62
  }
60
- return cameraGuidsResponseSchema.parse(await res.json());
63
+ const responseBody = await res.text();
64
+ const result = await cameraGuidsResponseSchema.safeParseAsync(JSON.parse(responseBody));
65
+ if (!result.success) {
66
+ throw new Error('Genetec get camera guids failed: ' + JSON.stringify(result.error.issues) + '\n' + responseBody);
67
+ }
68
+ return result.data;
61
69
  }
62
70
  async getCameraDetails(guids, parameters) {
63
71
  const params = parameters.join(',');
64
- let camerasGuids = [];
65
72
  const requestOptions = this.getRequestOptions('GET');
66
73
  const allCameras = [];
67
74
  const chunkSize = 10;
68
75
  while (guids.length > 0) {
69
76
  const chunk = guids.slice(0, chunkSize);
70
77
  guids.splice(0, chunkSize);
71
- camerasGuids = chunk.map((item) => item.Guid);
72
- const camerasDetailsUrl = [];
73
- for (const guid of camerasGuids) {
74
- camerasDetailsUrl.push(`entity=${guid},${params}`);
75
- }
76
- const res = await this.fetchWithTimeout(`${this.baseUrl}/${GET_CAMERAS_DETAILS_URL}${camerasDetailsUrl.join(',')}`, requestOptions);
78
+ const url = new URL(`${this.baseUrl}/entity`);
79
+ url.searchParams.set('q', chunk.map((item) => `entity=${item.Guid},${params}`).join(','));
80
+ const res = await this.fetchWithTimeout(url, requestOptions);
77
81
  if (!res.ok) {
78
82
  throw new Error(await responseStringify(res));
79
83
  }
80
- const data = cameraDetailsResponseSchema.parse(await res.json());
84
+ const responseBody = await res.text();
85
+ const result = await cameraDetailsResponseSchema.safeParseAsync(JSON.parse(responseBody));
86
+ if (!result.success) {
87
+ throw new Error('Genetec get camera details failed: ' + JSON.stringify(result.error.issues) + '\n' + responseBody);
88
+ }
89
+ const data = result.data;
81
90
  const resultArray = Array.isArray(data.Rsp.Result) ? data.Rsp.Result : [data.Rsp.Result];
82
91
  allCameras.push(...resultArray);
83
92
  }
84
93
  return allCameras;
85
94
  }
86
95
  async sendBookmark(guids, bookmarkText) {
87
- const cameraEntitiesUrl = [];
88
96
  const timeStamp = this.getTimeStamp();
89
97
  const requestOptions = this.getRequestOptions('POST');
90
- for (const guid of guids) {
91
- cameraEntitiesUrl.push(`${ACTION}(${guid},${timeStamp},${bookmarkText})`);
92
- }
93
- const res = await this.fetchWithTimeout(`${this.baseUrl}/action?q=${cameraEntitiesUrl.join(',')}`, requestOptions);
98
+ const url = new URL(`${this.baseUrl}/action`);
99
+ url.searchParams.set('q', guids.map((guid) => `AddCameraBookmark(${guid},${timeStamp},${bookmarkText})`).join(','));
100
+ const res = await this.fetchWithTimeout(url, requestOptions);
94
101
  if (!res.ok) {
95
102
  throw new Error(await responseStringify(res));
96
103
  }
97
- return res;
104
+ const responseBody = await res.text();
105
+ const result = await successResponseSchema.safeParseAsync(JSON.parse(responseBody));
106
+ if (!result.success) {
107
+ throw new Error('Genetec send bookmark failed: ' + JSON.stringify(result.error.issues) + '\n' + responseBody);
108
+ }
98
109
  }
99
110
  getRequestOptions(method) {
100
111
  return {
package/esm/node/index.js CHANGED
@@ -1,4 +1,5 @@
1
- export { DefaultClient } from './DefaultClient';
2
- export { WsClient } from './WsClient';
3
- export { AxisCameraStationEvents } from '../events/AxisCameraStationEvents';
4
- export * from '../events/GenetecAgent';
1
+ export * from './DefaultClient';
2
+ export * from './WsClient';
3
+ export * from './HttpServer';
4
+ export * from './events/AxisCameraStationEvents';
5
+ export * from './events/GenetecAgent';
@@ -8,6 +8,7 @@ import { pipSchema } from './pipSchema';
8
8
  import { customGraphicsSchema } from './customGraphicsSchema';
9
9
  import { screenSharingSchema } from './screenSharingSchema';
10
10
  import { webCameraSharingSchema } from './webCameraSharingSchema';
11
+ import { baseballScoreBoardAutomaticSchema, baseballScoreBoardSchema, scoreBoardSchema, scoreOverviewSchema, } from './scoreBoardSchema';
11
12
  export const WSResponseSchema = z.object({
12
13
  status: z.number(),
13
14
  message: z.string(),
@@ -23,6 +24,10 @@ export const widgetsSchema = z.discriminatedUnion('name', [
23
24
  customGraphicsSchema,
24
25
  screenSharingSchema,
25
26
  webCameraSharingSchema,
27
+ scoreBoardSchema,
28
+ baseballScoreBoardSchema,
29
+ baseballScoreBoardAutomaticSchema,
30
+ scoreOverviewSchema,
26
31
  ]);
27
32
  export const widgetListSchema = z.object({
28
33
  services: z.array(widgetsSchema),
@@ -36,6 +41,10 @@ export const isPtzCompass = (widget) => widget.name === 'ptzCompass';
36
41
  export const isPtz = (widget) => widget.name === 'ptz';
37
42
  export const isScreenSharing = (widget) => widget.name === 'screenSharing';
38
43
  export const isWebCameraSharing = (widget) => widget.name === 'web_camera';
44
+ export const isScoreBoard = (widget) => widget.name === 'scoreBoard';
45
+ export const isBaseballScoreBoard = (widget) => widget.name === 'baseballScoreBoard';
46
+ export const isBaseballScoreBoardAutomatic = (widget) => widget.name === 'myBallBaseballWidgets';
47
+ export const isScoreOverview = (widget) => widget.name === 'scoreOverview';
39
48
  export var ImageType;
40
49
  (function (ImageType) {
41
50
  ImageType[ImageType["PNG"] = 0] = "PNG";