camstreamerlib 4.0.0-beta.3 → 4.0.0-beta.30

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 (192) hide show
  1. package/README.md +8 -2
  2. package/cjs/CamOverlayAPI.d.ts +47 -26
  3. package/cjs/CamOverlayAPI.js +171 -88
  4. package/cjs/CamOverlayDrawingAPI.d.ts +2 -47
  5. package/cjs/CamOverlayDrawingAPI.js +6 -3
  6. package/cjs/CamOverlayPainter/Frame.d.ts +8 -37
  7. package/cjs/CamOverlayPainter/Frame.js +33 -0
  8. package/cjs/CamOverlayPainter/Painter.d.ts +16 -10
  9. package/cjs/CamOverlayPainter/Painter.js +6 -5
  10. package/cjs/CamOverlayPainter/ResourceManager.d.ts +3 -2
  11. package/cjs/CamOverlayPainter/ResourceManager.js +8 -11
  12. package/cjs/CamScripterAPI.d.ts +33 -16
  13. package/cjs/CamScripterAPI.js +50 -41
  14. package/cjs/CamScripterAPICameraEventsGenerator.d.ts +1 -1
  15. package/cjs/CamScripterAPICameraEventsGenerator.js +6 -3
  16. package/cjs/CamStreamerAPI.d.ts +16 -14
  17. package/cjs/CamStreamerAPI.js +32 -32
  18. package/cjs/CamSwitcherAPI.d.ts +42 -37
  19. package/cjs/CamSwitcherAPI.js +123 -114
  20. package/cjs/CamSwitcherEvents.d.ts +1 -1
  21. package/cjs/PlaneTrackerAPI.d.ts +42 -0
  22. package/cjs/PlaneTrackerAPI.js +211 -0
  23. package/cjs/VapixAPI.d.ts +56 -43
  24. package/cjs/VapixAPI.js +305 -216
  25. package/cjs/VapixEvents.d.ts +1 -1
  26. package/cjs/VapixEvents.js +3 -3
  27. package/cjs/errors/errors.d.ts +3 -0
  28. package/cjs/errors/errors.js +8 -1
  29. package/cjs/events/AxisCameraStationEvents.d.ts +5 -4
  30. package/cjs/events/AxisCameraStationEvents.js +23 -18
  31. package/cjs/events/GenetecAgent.d.ts +6 -3
  32. package/cjs/events/GenetecAgent.js +30 -19
  33. package/cjs/index.d.ts +14 -1
  34. package/cjs/index.js +23 -2
  35. package/cjs/internal/Digest.js +6 -6
  36. package/cjs/internal/ProxyClient.d.ts +8 -9
  37. package/cjs/internal/ProxyClient.js +25 -29
  38. package/cjs/internal/types.d.ts +42 -0
  39. package/cjs/internal/types.js +2 -0
  40. package/cjs/internal/utils.d.ts +4 -1
  41. package/cjs/internal/utils.js +22 -3
  42. package/cjs/internal/versionCompare.d.ts +2 -2
  43. package/cjs/node/DefaultClient.d.ts +5 -6
  44. package/cjs/node/DefaultClient.js +12 -14
  45. package/cjs/node/HttpRequestSender.d.ts +1 -0
  46. package/cjs/node/HttpRequestSender.js +13 -3
  47. package/cjs/node/HttpServer.js +1 -1
  48. package/cjs/node/WsClient.d.ts +2 -1
  49. package/cjs/node/WsEventClient.d.ts +1 -1
  50. package/cjs/node/index.d.ts +2 -0
  51. package/cjs/node/index.js +18 -1
  52. package/cjs/types/CamOverlayAPI/CamOverlayAPI.d.ts +3073 -0
  53. package/cjs/types/CamOverlayAPI/CamOverlayAPI.js +127 -0
  54. package/cjs/types/CamOverlayAPI/accuweatherSchema.d.ts +114 -0
  55. package/cjs/types/CamOverlayAPI/accuweatherSchema.js +50 -0
  56. package/cjs/types/CamOverlayAPI/customGraphicsSchema.d.ts +783 -0
  57. package/cjs/types/CamOverlayAPI/customGraphicsSchema.js +75 -0
  58. package/cjs/types/CamOverlayAPI/imagesSchema.d.ts +122 -0
  59. package/cjs/types/CamOverlayAPI/imagesSchema.js +12 -0
  60. package/cjs/types/CamOverlayAPI/index.d.ts +9 -0
  61. package/cjs/types/CamOverlayAPI/index.js +25 -0
  62. package/cjs/types/CamOverlayAPI/infotickerSchema.d.ts +130 -0
  63. package/cjs/types/CamOverlayAPI/infotickerSchema.js +29 -0
  64. package/cjs/types/CamOverlayAPI/pipSchema.d.ts +166 -0
  65. package/cjs/types/CamOverlayAPI/pipSchema.js +42 -0
  66. package/cjs/types/CamOverlayAPI/ptzCompassSchema.d.ts +126 -0
  67. package/cjs/types/CamOverlayAPI/ptzCompassSchema.js +28 -0
  68. package/cjs/types/CamOverlayAPI/ptzSchema.d.ts +146 -0
  69. package/cjs/types/CamOverlayAPI/ptzSchema.js +15 -0
  70. package/cjs/types/CamOverlayAPI/screenSharingSchema.d.ts +79 -0
  71. package/cjs/types/CamOverlayAPI/screenSharingSchema.js +11 -0
  72. package/cjs/types/CamOverlayAPI/webCameraSharingSchema.d.ts +79 -0
  73. package/cjs/types/CamOverlayAPI/webCameraSharingSchema.js +11 -0
  74. package/cjs/types/CamOverlayDrawingAPI.d.ts +58 -0
  75. package/cjs/types/CamOverlayDrawingAPI.js +2 -0
  76. package/cjs/types/CamOverlayPainter.d.ts +74 -0
  77. package/cjs/types/CamOverlayPainter.js +2 -0
  78. package/cjs/types/CamScripterAPI.d.ts +82 -17
  79. package/cjs/types/CamScripterAPI.js +22 -7
  80. package/cjs/types/CamStreamerAPI.d.ts +16 -5
  81. package/cjs/types/CamStreamerAPI.js +5 -1
  82. package/cjs/types/CamSwitcherAPI.d.ts +5 -5
  83. package/cjs/types/CamSwitcherEvents.d.ts +77 -0
  84. package/cjs/types/CamSwitcherEvents.js +8 -0
  85. package/cjs/types/PlaneTrackerAPI.d.ts +8 -0
  86. package/cjs/types/PlaneTrackerAPI.js +2 -0
  87. package/cjs/types/VapixAPI.d.ts +636 -519
  88. package/cjs/types/VapixAPI.js +62 -24
  89. package/cjs/types/common.d.ts +14 -5
  90. package/cjs/web/DefaultClient.d.ts +5 -5
  91. package/cjs/web/DefaultClient.js +22 -10
  92. package/cjs/web/WsClient.js +2 -2
  93. package/esm/CamOverlayAPI.d.ts +47 -26
  94. package/esm/CamOverlayAPI.js +169 -86
  95. package/esm/CamOverlayDrawingAPI.d.ts +2 -47
  96. package/esm/CamOverlayDrawingAPI.js +6 -3
  97. package/esm/CamOverlayPainter/Frame.d.ts +8 -37
  98. package/esm/CamOverlayPainter/Frame.js +33 -0
  99. package/esm/CamOverlayPainter/Painter.d.ts +16 -10
  100. package/esm/CamOverlayPainter/Painter.js +5 -3
  101. package/esm/CamOverlayPainter/ResourceManager.d.ts +3 -2
  102. package/esm/CamOverlayPainter/ResourceManager.js +7 -11
  103. package/esm/CamScripterAPI.d.ts +33 -16
  104. package/esm/CamScripterAPI.js +46 -37
  105. package/esm/CamScripterAPICameraEventsGenerator.d.ts +1 -1
  106. package/esm/CamScripterAPICameraEventsGenerator.js +6 -3
  107. package/esm/CamStreamerAPI.d.ts +16 -14
  108. package/esm/CamStreamerAPI.js +32 -32
  109. package/esm/CamSwitcherAPI.d.ts +42 -37
  110. package/esm/CamSwitcherAPI.js +116 -107
  111. package/esm/CamSwitcherEvents.d.ts +1 -1
  112. package/esm/PlaneTrackerAPI.d.ts +42 -0
  113. package/esm/PlaneTrackerAPI.js +207 -0
  114. package/esm/VapixAPI.d.ts +56 -43
  115. package/esm/VapixAPI.js +297 -208
  116. package/esm/VapixEvents.d.ts +1 -1
  117. package/esm/VapixEvents.js +3 -3
  118. package/esm/errors/errors.d.ts +3 -0
  119. package/esm/errors/errors.js +6 -0
  120. package/esm/events/AxisCameraStationEvents.d.ts +5 -4
  121. package/esm/events/AxisCameraStationEvents.js +18 -13
  122. package/esm/events/GenetecAgent.d.ts +6 -3
  123. package/esm/events/GenetecAgent.js +20 -9
  124. package/esm/index.d.ts +14 -1
  125. package/esm/index.js +14 -1
  126. package/esm/internal/Digest.js +6 -6
  127. package/esm/internal/ProxyClient.d.ts +8 -9
  128. package/esm/internal/ProxyClient.js +25 -29
  129. package/esm/internal/types.d.ts +42 -0
  130. package/esm/internal/types.js +1 -0
  131. package/esm/internal/utils.d.ts +4 -1
  132. package/esm/internal/utils.js +17 -1
  133. package/esm/internal/versionCompare.d.ts +2 -2
  134. package/esm/node/DefaultClient.d.ts +5 -6
  135. package/esm/node/DefaultClient.js +12 -14
  136. package/esm/node/HttpRequestSender.d.ts +1 -0
  137. package/esm/node/HttpRequestSender.js +13 -3
  138. package/esm/node/HttpServer.js +1 -1
  139. package/esm/node/WsClient.d.ts +2 -1
  140. package/esm/node/WsEventClient.d.ts +1 -1
  141. package/esm/node/index.d.ts +2 -0
  142. package/esm/node/index.js +2 -0
  143. package/esm/types/CamOverlayAPI/CamOverlayAPI.d.ts +3073 -0
  144. package/esm/types/CamOverlayAPI/CamOverlayAPI.js +124 -0
  145. package/esm/types/CamOverlayAPI/accuweatherSchema.d.ts +114 -0
  146. package/esm/types/CamOverlayAPI/accuweatherSchema.js +46 -0
  147. package/esm/types/CamOverlayAPI/customGraphicsSchema.d.ts +783 -0
  148. package/esm/types/CamOverlayAPI/customGraphicsSchema.js +71 -0
  149. package/esm/types/CamOverlayAPI/imagesSchema.d.ts +122 -0
  150. package/esm/types/CamOverlayAPI/imagesSchema.js +8 -0
  151. package/esm/types/CamOverlayAPI/index.d.ts +9 -0
  152. package/esm/types/CamOverlayAPI/index.js +9 -0
  153. package/esm/types/CamOverlayAPI/infotickerSchema.d.ts +130 -0
  154. package/esm/types/CamOverlayAPI/infotickerSchema.js +25 -0
  155. package/esm/types/CamOverlayAPI/pipSchema.d.ts +166 -0
  156. package/esm/types/CamOverlayAPI/pipSchema.js +38 -0
  157. package/esm/types/CamOverlayAPI/ptzCompassSchema.d.ts +126 -0
  158. package/esm/types/CamOverlayAPI/ptzCompassSchema.js +24 -0
  159. package/esm/types/CamOverlayAPI/ptzSchema.d.ts +146 -0
  160. package/esm/types/CamOverlayAPI/ptzSchema.js +11 -0
  161. package/esm/types/CamOverlayAPI/screenSharingSchema.d.ts +79 -0
  162. package/esm/types/CamOverlayAPI/screenSharingSchema.js +7 -0
  163. package/esm/types/CamOverlayAPI/webCameraSharingSchema.d.ts +79 -0
  164. package/esm/types/CamOverlayAPI/webCameraSharingSchema.js +7 -0
  165. package/esm/types/CamOverlayDrawingAPI.d.ts +58 -0
  166. package/esm/types/CamOverlayDrawingAPI.js +1 -0
  167. package/esm/types/CamOverlayPainter.d.ts +74 -0
  168. package/esm/types/CamOverlayPainter.js +1 -0
  169. package/esm/types/CamScripterAPI.d.ts +82 -17
  170. package/esm/types/CamScripterAPI.js +21 -6
  171. package/esm/types/CamStreamerAPI.d.ts +16 -5
  172. package/esm/types/CamStreamerAPI.js +4 -0
  173. package/esm/types/CamSwitcherAPI.d.ts +5 -5
  174. package/esm/types/CamSwitcherEvents.d.ts +77 -0
  175. package/esm/types/CamSwitcherEvents.js +8 -0
  176. package/esm/types/PlaneTrackerAPI.d.ts +8 -0
  177. package/esm/types/PlaneTrackerAPI.js +1 -0
  178. package/esm/types/VapixAPI.d.ts +636 -519
  179. package/esm/types/VapixAPI.js +61 -23
  180. package/esm/types/common.d.ts +14 -5
  181. package/esm/web/DefaultClient.d.ts +5 -5
  182. package/esm/web/DefaultClient.js +22 -10
  183. package/esm/web/WsClient.js +2 -2
  184. package/package.json +9 -8
  185. package/cjs/internal/common.d.ts +0 -39
  186. package/cjs/internal/common.js +0 -27
  187. package/cjs/types/CamOverlayAPI.d.ts +0 -188
  188. package/cjs/types/CamOverlayAPI.js +0 -47
  189. package/esm/internal/common.d.ts +0 -39
  190. package/esm/internal/common.js +0 -20
  191. package/esm/types/CamOverlayAPI.d.ts +0 -188
  192. package/esm/types/CamOverlayAPI.js +0 -44
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter2 as EventEmitter } from 'eventemitter2';
2
- import { WsOptions } from './internal/common';
2
+ import { WsOptions } from './internal/types';
3
3
  export type VapixEventsOptions = WsOptions;
4
4
  type TEventMessage = {
5
5
  apiVersion: string;
@@ -39,10 +39,10 @@ export class VapixEvents extends EventEmitter {
39
39
  this.ws.on('open', () => {
40
40
  const topics = [];
41
41
  const eventNames = this.eventNames();
42
- for (let i = 0; i < eventNames.length; i++) {
43
- if (!this.isReservedEventName(eventNames[i])) {
42
+ for (const eventName of eventNames) {
43
+ if (!this.isReservedEventName(eventName)) {
44
44
  const topic = {
45
- topicFilter: eventNames[i],
45
+ topicFilter: eventName,
46
46
  };
47
47
  topics.push(topic);
48
48
  }
@@ -31,4 +31,7 @@ export declare class FetchDeviceInfoError extends Error {
31
31
  export declare class AddNewClipError extends Error {
32
32
  constructor(message: string);
33
33
  }
34
+ export declare class PtzNotSupportedError extends Error {
35
+ constructor();
36
+ }
34
37
  export {};
@@ -64,3 +64,9 @@ export class AddNewClipError extends Error {
64
64
  this.name = 'AddNewClipError';
65
65
  }
66
66
  }
67
+ export class PtzNotSupportedError extends Error {
68
+ constructor() {
69
+ super('Ptz not supported.');
70
+ this.name = 'PtzNotSupportedError';
71
+ }
72
+ }
@@ -1,9 +1,10 @@
1
- import { IClient, HttpOptions } from '../internal/common';
2
- export type AcsEventsOptions = HttpOptions;
1
+ import { HttpOptions } from '../internal/types';
2
+ import { THttpRequestOptions } from '../types/common';
3
3
  export declare class AxisCameraStationEvents {
4
4
  private sourceKey;
5
5
  private client;
6
- constructor(sourceKey: string, opt?: AcsEventsOptions | IClient);
7
- sendEvent(data: Record<string, string>, eventType: string): Promise<void>;
6
+ constructor(clientOptions: HttpOptions, sourceKey: string);
7
+ sendEvent(data: Record<string, string>, eventType: string, options?: THttpRequestOptions): Promise<void>;
8
8
  private getDate;
9
+ private getAgent;
9
10
  }
@@ -1,18 +1,14 @@
1
- import { DefaultClient } from '../node/DefaultClient';
2
- import { isClient, pad } from '../internal/common';
1
+ import { pad } from '../internal/utils';
2
+ import { ProxyClient } from '../internal/ProxyClient';
3
+ import { DefaultClient } from '../node';
3
4
  export class AxisCameraStationEvents {
4
5
  sourceKey;
5
6
  client;
6
- constructor(sourceKey, opt = {}) {
7
+ constructor(clientOptions, sourceKey) {
7
8
  this.sourceKey = sourceKey;
8
- if (isClient(opt)) {
9
- this.client = opt;
10
- }
11
- else {
12
- this.client = new DefaultClient(opt);
13
- }
9
+ this.client = new DefaultClient(clientOptions);
14
10
  }
15
- async sendEvent(data, eventType) {
11
+ async sendEvent(data, eventType, options) {
16
12
  const dateString = this.getDate();
17
13
  const event = {
18
14
  addExternalDataRequest: {
@@ -23,9 +19,15 @@ export class AxisCameraStationEvents {
23
19
  },
24
20
  };
25
21
  const eventData = JSON.stringify(event);
26
- const res = await this.client.post('/Acs/Api/ExternalDataFacade/AddExternalData', eventData, undefined, {
27
- 'Content-Type': 'application/json',
28
- 'Content-Length': eventData.length.toString(),
22
+ const agent = this.getAgent(options?.proxyParams);
23
+ const res = await agent.post({
24
+ path: '/Acs/Api/ExternalDataFacade/AddExternalData',
25
+ data: eventData,
26
+ headers: {
27
+ 'Content-Type': 'application/json',
28
+ 'Content-Length': eventData.length.toString(),
29
+ },
30
+ timeout: options?.timeout,
29
31
  });
30
32
  if (!res.ok) {
31
33
  throw new Error(`ACS status code: ${res.status}`);
@@ -41,4 +43,7 @@ export class AxisCameraStationEvents {
41
43
  const seconds = pad(date.getUTCSeconds(), 2);
42
44
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
43
45
  }
46
+ getAgent(proxyParams) {
47
+ return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
48
+ }
44
49
  }
@@ -148,14 +148,16 @@ export declare const cameraDetailsResponseSchema: z.ZodObject<{
148
148
  export type TCameraDetailsResponse = z.infer<typeof cameraDetailsResponseSchema>;
149
149
  export type TCameraDetail = z.infer<typeof cameraDetailSchema>;
150
150
  export type TParams = Array<'Guid' | 'Name' | 'EntityType'>;
151
+ export type TProtocol = 'http' | 'https' | 'https_insecure';
151
152
  export type GenetecAgentOptions = {
152
- protocol?: 'http' | 'https' | 'https_insecure';
153
+ protocol?: TProtocol;
153
154
  ip?: string;
154
155
  port?: number;
155
- base_uri?: string;
156
+ baseUri?: string;
156
157
  user?: string;
157
158
  pass?: string;
158
- app_id?: string;
159
+ appId?: string;
160
+ timeout?: number;
159
161
  };
160
162
  export declare class GenetecAgent {
161
163
  private settings;
@@ -170,5 +172,6 @@ export declare class GenetecAgent {
170
172
  sendBookmark(guids: string[], bookmarkText: string): Promise<Response>;
171
173
  private getRequestOptions;
172
174
  private getTimeStamp;
175
+ private fetchWithTimeout;
173
176
  }
174
177
  export {};
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { responseStringify, pad } from '../internal/common';
2
+ import { responseStringify, pad } from '../internal/utils';
3
3
  const ACTION = 'AddCameraBookmark';
4
4
  const GET_CAMERAS_URL = 'report/EntityConfiguration?q=EntityTypes@Camera';
5
5
  const GET_CAMERAS_DETAILS_URL = '/entity?q=';
@@ -34,17 +34,18 @@ export class GenetecAgent {
34
34
  protocol: options.protocol ?? 'http',
35
35
  ip: options.ip ?? '127.0.0.1',
36
36
  port: options.port ?? 80,
37
- base_uri: options.base_uri ?? 'WebSdk',
37
+ baseUri: options.baseUri ?? 'WebSdk',
38
38
  user: options.user ?? 'root',
39
39
  pass: options.pass ?? '',
40
- app_id: options.app_id ?? '',
40
+ appId: options.appId ?? '',
41
+ timeout: options.timeout ?? 10000,
41
42
  };
42
- this.baseUrl = `${this.settings.protocol}://${this.settings.ip}:${this.settings.port}/${this.settings.base_uri}`;
43
- this.credentials = btoa(`${this.settings.user};${this.settings.app_id}:${this.settings.pass}`);
43
+ this.baseUrl = `${this.settings.protocol}://${this.settings.ip}:${this.settings.port}/${this.settings.baseUri}`;
44
+ this.credentials = btoa(`${this.settings.user};${this.settings.appId}:${this.settings.pass}`);
44
45
  }
45
46
  async checkConnection() {
46
47
  const requestOptions = this.getRequestOptions('GET');
47
- const res = await fetch(`${this.baseUrl}/`, requestOptions);
48
+ const res = await this.fetchWithTimeout(`${this.baseUrl}/`, requestOptions);
48
49
  if (!res.ok) {
49
50
  throw new Error(await responseStringify(res));
50
51
  }
@@ -52,7 +53,7 @@ export class GenetecAgent {
52
53
  }
53
54
  async getAllCameraGuids() {
54
55
  const requestOptions = this.getRequestOptions('GET');
55
- const res = await fetch(`${this.baseUrl}/${GET_CAMERAS_URL}`, requestOptions);
56
+ const res = await this.fetchWithTimeout(`${this.baseUrl}/${GET_CAMERAS_URL}`, requestOptions);
56
57
  if (!res.ok) {
57
58
  throw new Error(await responseStringify(res));
58
59
  }
@@ -72,7 +73,7 @@ export class GenetecAgent {
72
73
  for (const guid of camerasGuids) {
73
74
  camerasDetailsUrl.push(`entity=${guid},${params}`);
74
75
  }
75
- const res = await fetch(`${this.baseUrl}/${GET_CAMERAS_DETAILS_URL}${camerasDetailsUrl.join(',')}`, requestOptions);
76
+ const res = await this.fetchWithTimeout(`${this.baseUrl}/${GET_CAMERAS_DETAILS_URL}${camerasDetailsUrl.join(',')}`, requestOptions);
76
77
  if (!res.ok) {
77
78
  throw new Error(await responseStringify(res));
78
79
  }
@@ -89,7 +90,7 @@ export class GenetecAgent {
89
90
  for (const guid of guids) {
90
91
  cameraEntitiesUrl.push(`${ACTION}(${guid},${timeStamp},${bookmarkText})`);
91
92
  }
92
- const res = await fetch(`${this.baseUrl}/action?q=${cameraEntitiesUrl.join(',')}`, requestOptions);
93
+ const res = await this.fetchWithTimeout(`${this.baseUrl}/action?q=${cameraEntitiesUrl.join(',')}`, requestOptions);
93
94
  if (!res.ok) {
94
95
  throw new Error(await responseStringify(res));
95
96
  }
@@ -116,4 +117,14 @@ export class GenetecAgent {
116
117
  const miliSeconds = pad(date.getUTCMilliseconds(), 2);
117
118
  return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${miliSeconds}Z`;
118
119
  }
120
+ async fetchWithTimeout(url, options) {
121
+ const controller = new AbortController();
122
+ const timeoutId = setTimeout(() => controller.abort(), this.settings.timeout);
123
+ try {
124
+ return await fetch(url, { ...options, signal: controller.signal });
125
+ }
126
+ finally {
127
+ clearTimeout(timeoutId);
128
+ }
129
+ }
119
130
  }
package/esm/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './internal/common';
1
+ export * from './internal/types';
2
2
  export * from './internal/constants';
3
3
  export * from './internal/utils';
4
4
  export * from './internal/versionCompare';
@@ -6,6 +6,19 @@ export * from './types/common';
6
6
  export { CamSwitcherAPI } from './CamSwitcherAPI';
7
7
  export { CamSwitcherEvents } from './CamSwitcherEvents';
8
8
  export { VapixAPI } from './VapixAPI';
9
+ export { CamOverlayAPI } from './CamOverlayAPI';
10
+ export { CamScripterAPI } from './CamScripterAPI';
11
+ export { CamStreamerAPI } from './CamStreamerAPI';
12
+ export { PlaneTrackerAPI } from './PlaneTrackerAPI';
9
13
  export * from './types/CamSwitcherEvents';
10
14
  export * from './types/CamSwitcherAPI';
11
15
  export * from './types/VapixAPI';
16
+ export * from './types/CamOverlayAPI';
17
+ export * from './types/CamOverlayAPI/CamOverlayAPI';
18
+ export * from './types/PlaneTrackerAPI';
19
+ export { Frame } from './CamOverlayPainter/Frame';
20
+ export { Painter } from './CamOverlayPainter/Painter';
21
+ export { ResourceManager } from './CamOverlayPainter/ResourceManager';
22
+ export * from './types/CamOverlayPainter';
23
+ export { CamOverlayDrawingAPI } from './CamOverlayDrawingAPI';
24
+ export * from './types/CamOverlayDrawingAPI';
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export * from './internal/common';
1
+ export * from './internal/types';
2
2
  export * from './internal/constants';
3
3
  export * from './internal/utils';
4
4
  export * from './internal/versionCompare';
@@ -6,6 +6,19 @@ export * from './types/common';
6
6
  export { CamSwitcherAPI } from './CamSwitcherAPI';
7
7
  export { CamSwitcherEvents } from './CamSwitcherEvents';
8
8
  export { VapixAPI } from './VapixAPI';
9
+ export { CamOverlayAPI } from './CamOverlayAPI';
10
+ export { CamScripterAPI } from './CamScripterAPI';
11
+ export { CamStreamerAPI } from './CamStreamerAPI';
12
+ export { PlaneTrackerAPI } from './PlaneTrackerAPI';
9
13
  export * from './types/CamSwitcherEvents';
10
14
  export * from './types/CamSwitcherAPI';
11
15
  export * from './types/VapixAPI';
16
+ export * from './types/CamOverlayAPI';
17
+ export * from './types/CamOverlayAPI/CamOverlayAPI';
18
+ export * from './types/PlaneTrackerAPI';
19
+ export { Frame } from './CamOverlayPainter/Frame';
20
+ export { Painter } from './CamOverlayPainter/Painter';
21
+ export { ResourceManager } from './CamOverlayPainter/ResourceManager';
22
+ export * from './types/CamOverlayPainter';
23
+ export { CamOverlayDrawingAPI } from './CamOverlayDrawingAPI';
24
+ export * from './types/CamOverlayDrawingAPI';
@@ -4,17 +4,17 @@ export class Digest {
4
4
  getAuthHeader(user, pass, method, uri, wwwAuthenticateHeader) {
5
5
  const digestItems = {};
6
6
  const digestArr = wwwAuthenticateHeader.substring(wwwAuthenticateHeader.indexOf('Digest') + 6).split(',');
7
- for (let i = 0; i < digestArr.length; i++) {
8
- const pos = digestArr[i].indexOf('=');
9
- const key = digestArr[i].substring(0, pos).trim();
10
- const value = digestArr[i].substring(pos + 1).trim();
7
+ for (const arg of digestArr) {
8
+ const pos = arg.indexOf('=');
9
+ const key = arg.substring(0, pos).trim();
10
+ const value = arg.substring(pos + 1).trim();
11
11
  digestItems[key] = value.replace(/"/g, '');
12
12
  }
13
13
  const HA1 = crypto.createHash('md5').update(`${user}:${digestItems['realm']}:${pass}`).digest('hex');
14
14
  const HA2 = crypto.createHash('md5').update(`${method}:${uri}`).digest('hex');
15
15
  const ncValue = ('00000000' + this.nonceCount.toString(16)).slice(-8);
16
16
  let response;
17
- if (digestItems['qop']) {
17
+ if (digestItems['qop'] !== undefined) {
18
18
  response = crypto
19
19
  .createHash('md5')
20
20
  .update(`${HA1}:${digestItems['nonce']}:${ncValue}:162d50aa594e9648:auth:${HA2}`)
@@ -29,7 +29,7 @@ export class Digest {
29
29
  `nonce="${digestItems['nonce']}",` +
30
30
  `uri="${uri}",` +
31
31
  `response="${response}"`;
32
- if (digestItems['qop']) {
32
+ if (digestItems['qop'] !== undefined) {
33
33
  header += `,qop=auth,nc=${ncValue},cnonce="162d50aa594e9648"`;
34
34
  }
35
35
  this.nonceCount++;
@@ -1,11 +1,10 @@
1
- /// <reference types="node" />
2
- import { IClient, TParameters } from './common';
3
- import { TProxyParam } from '../types/common';
4
- export declare class ProxyClient<Client extends IClient = IClient> {
5
- client: Client;
6
- getProxyUrl: () => string;
7
- constructor(client: Client, getProxyUrl: () => string);
8
- get: (proxy: TProxyParam, path: string, parameters?: TParameters, headers?: Record<string, string>) => Promise<import("./common").TResponse>;
9
- post: (proxy: TProxyParam, path: string, data: string | Buffer | FormData, parameters?: TParameters, headers?: Record<string, string>) => Promise<import("./common").TResponse>;
1
+ import { IClient, TGetParams, TPostParams, TResponse } from './types';
2
+ import { TProxyParams } from '../types/common';
3
+ export declare class ProxyClient<Client extends IClient<TResponse> = IClient<TResponse>> {
4
+ private client;
5
+ private proxyParams;
6
+ constructor(client: Client, proxyParams: TProxyParams);
7
+ get: (params: TGetParams) => Promise<TResponse>;
8
+ post: (params: TPostParams) => Promise<TResponse>;
10
9
  private getReal;
11
10
  }
@@ -1,40 +1,36 @@
1
1
  import { addParametersToPath } from './utils';
2
2
  export class ProxyClient {
3
3
  client;
4
- getProxyUrl;
5
- constructor(client, getProxyUrl) {
4
+ proxyParams;
5
+ constructor(client, proxyParams) {
6
6
  this.client = client;
7
- this.getProxyUrl = getProxyUrl;
7
+ this.proxyParams = proxyParams;
8
8
  }
9
- get = (proxy, path, parameters, headers = {}) => {
10
- const url = addParametersToPath(path, parameters);
11
- const { realUrl, realHeaders } = this.getReal(proxy, url, headers);
12
- return this.client.get(realUrl, {}, realHeaders);
9
+ get = (params) => {
10
+ const { path, parameters, headers, timeout } = params;
11
+ const targetPath = addParametersToPath(path, parameters);
12
+ const { realPath, realHeaders } = this.getReal(targetPath, headers);
13
+ return this.client.get({ path: realPath, headers: realHeaders, timeout });
13
14
  };
14
- post = (proxy, path, data, parameters, headers) => {
15
- const url = addParametersToPath(path, parameters);
16
- const { realUrl, realHeaders } = this.getReal(proxy, url, headers);
17
- return this.client.post(realUrl, data, {}, realHeaders);
15
+ post = (params) => {
16
+ const { path, data, parameters, headers, timeout } = params;
17
+ const targetPath = addParametersToPath(path, parameters);
18
+ const { realPath, realHeaders } = this.getReal(targetPath, headers);
19
+ return this.client.post({ path: realPath, data, headers: realHeaders, timeout });
18
20
  };
19
- getReal = (proxy, url, headers) => {
20
- if (proxy !== null) {
21
- return {
22
- realUrl: this.getProxyUrl(),
23
- realHeaders: {
24
- ...(headers ?? {}),
25
- 'x-target-camera-protocol': proxy.port === 443 ? 'https' : 'http',
26
- 'x-target-camera-path': url,
27
- 'x-target-camera-ip': proxy.ip,
28
- 'x-target-camera-mdns': proxy.mdnsName,
29
- 'x-target-camera-port': String(proxy.port),
30
- 'x-target-camera-pass': encodeURIComponent(proxy.pass),
31
- 'x-target-camera-user': encodeURIComponent(proxy.user),
32
- },
33
- };
34
- }
21
+ getReal = (targetPath, headers) => {
35
22
  return {
36
- realUrl: url,
37
- realHeaders: headers,
23
+ realPath: this.proxyParams.path,
24
+ realHeaders: {
25
+ ...(headers ?? {}),
26
+ 'x-target-camera-protocol': this.proxyParams.target.port === 443 ? 'https' : 'http',
27
+ 'x-target-camera-path': targetPath,
28
+ 'x-target-camera-ip': this.proxyParams.target.ip,
29
+ 'x-target-camera-mdns': this.proxyParams.target.mdnsName,
30
+ 'x-target-camera-port': String(this.proxyParams.target.port),
31
+ 'x-target-camera-pass': this.proxyParams.target.pass,
32
+ 'x-target-camera-user': this.proxyParams.target.user,
33
+ },
38
34
  };
39
35
  };
40
36
  }
@@ -0,0 +1,42 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Response as UndiciResponse } from 'undici';
4
+ export type Options = {
5
+ ip?: string;
6
+ port?: number;
7
+ user?: string;
8
+ pass?: string;
9
+ tls?: boolean;
10
+ tlsInsecure?: boolean;
11
+ };
12
+ export type HttpOptions = Options & {
13
+ keepAlive?: boolean;
14
+ };
15
+ export type WsOptions = Options;
16
+ export type TParameters = Record<string, string | number | boolean | null | undefined>;
17
+ export type TResponse = Response | UndiciResponse;
18
+ export type TGetParams = {
19
+ path: string;
20
+ parameters?: TParameters;
21
+ headers?: Record<string, string>;
22
+ timeout?: number;
23
+ };
24
+ export type TPostParams = {
25
+ path: string;
26
+ data: string | Buffer | FormData;
27
+ parameters?: TParameters;
28
+ headers?: Record<string, string>;
29
+ timeout?: number;
30
+ };
31
+ export interface IClient<TRes extends TResponse> {
32
+ get: (params: TGetParams) => Promise<TRes>;
33
+ post: (params: TPostParams) => Promise<TRes>;
34
+ }
35
+ export type TBlobResponse<Client extends IClient<TResponse>> = Awaited<ReturnType<Awaited<ReturnType<Client['get']>>['blob']>>;
36
+ export interface IWebsocket<Event extends {
37
+ readonly data: string;
38
+ }> {
39
+ destroy: () => void;
40
+ onmessage: null | ((event: Event) => void);
41
+ send: (data: string) => void;
42
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { TPlaylistPlayType } from '../types/CamSwitcherAPI';
2
- import { TParameters } from './common';
2
+ import { TParameters, TResponse } from './types';
3
3
  export declare const addParametersToPath: (path: string, params?: TParameters) => string;
4
4
  export declare const paramToUrl: (params?: TParameters) => string;
5
5
  export declare const arrayToUrl: (arr: string | string[]) => string;
@@ -9,3 +9,6 @@ export declare const isClip: (id?: string) => boolean;
9
9
  export declare const isTracker: (id?: string) => boolean;
10
10
  export declare const isPlaylist: (id?: string) => boolean;
11
11
  export declare const isLoopPlayType: (playType: TPlaylistPlayType) => boolean;
12
+ export declare function responseStringify(res: TResponse): Promise<string>;
13
+ export declare function pad(num: number, size: number): string;
14
+ export declare function isNullish<T>(value: T | undefined | null): value is undefined | null;
@@ -1,4 +1,3 @@
1
- import { isNullish } from './common';
2
1
  export const addParametersToPath = (path, params) => {
3
2
  if (params === undefined || Object.keys(params).length === 0) {
4
3
  return path;
@@ -32,3 +31,20 @@ export const isClip = (id) => id?.charAt(0) === 's';
32
31
  export const isTracker = (id) => id?.charAt(0) === 't';
33
32
  export const isPlaylist = (id) => id?.charAt(0) === 'p';
34
33
  export const isLoopPlayType = (playType) => playType.includes('LOOP');
34
+ export async function responseStringify(res) {
35
+ return JSON.stringify({
36
+ status: res.status,
37
+ body: await res.text(),
38
+ });
39
+ }
40
+ export function pad(num, size) {
41
+ const sign = Math.sign(num) === -1 ? '-' : '';
42
+ return (sign +
43
+ new Array(size)
44
+ .concat([Math.abs(num)])
45
+ .join('0')
46
+ .slice(-size));
47
+ }
48
+ export function isNullish(value) {
49
+ return value === null || value === undefined;
50
+ }
@@ -1,6 +1,6 @@
1
1
  export declare const assertVersionString: (s: string, msg?: string) => void;
2
2
  export declare const isFirmwareVersionAtLeast: (version: string, compareVersion: string) => boolean;
3
3
  export declare const isVersionAtLeast: (version: string, compareVersion: string) => boolean;
4
- export declare const firmwareVersionCompare: (a: string, b: string) => 1 | -1 | 0;
5
- export declare const versionCompare: (a: string, b: string) => 1 | -1 | 0;
4
+ export declare const firmwareVersionCompare: (a: string, b: string) => 0 | 1 | -1;
5
+ export declare const versionCompare: (a: string, b: string) => 0 | 1 | -1;
6
6
  export declare const fixVersionToDots: (version: string) => string;
@@ -1,6 +1,6 @@
1
- /// <reference types="node" />
2
- import { IClient, HttpOptions, TParameters } from '../internal/common';
3
- export declare class DefaultClient implements IClient {
1
+ import { IClient, HttpOptions, TGetParams, TPostParams } from '../internal/types';
2
+ import { Response as UndiciResponse } from 'undici';
3
+ export declare class DefaultClient implements IClient<UndiciResponse> {
4
4
  private tls;
5
5
  private ip;
6
6
  private port;
@@ -8,8 +8,7 @@ export declare class DefaultClient implements IClient {
8
8
  private pass;
9
9
  private httpRequestSender;
10
10
  constructor(opt?: HttpOptions);
11
- get url(): string;
12
- get(path: string, parameters?: TParameters, headers?: Record<string, string>): Promise<import("undici").Response>;
13
- post(path: string, data: string | FormData | Buffer, parameters?: TParameters, headers?: Record<string, string>): Promise<import("undici").Response>;
11
+ get: (params: TGetParams) => Promise<UndiciResponse>;
12
+ post: (params: TPostParams) => Promise<UndiciResponse>;
14
13
  private getBaseConnectionParams;
15
14
  }
@@ -22,29 +22,27 @@ export class DefaultClient {
22
22
  }
23
23
  this.httpRequestSender = new HttpRequestSender(agentOptions);
24
24
  }
25
- get url() {
26
- return `${this.tls ? 'https' : 'http'}://${this.user}:${this.pass}@${this.ip}:${this.port}`;
27
- }
28
- async get(path, parameters = {}, headers) {
29
- const options = this.getBaseConnectionParams('GET', path, parameters);
30
- options.headers = headers;
25
+ get = (params) => {
26
+ const { path, parameters, headers, timeout } = params;
27
+ const options = this.getBaseConnectionParams('GET', path, parameters, headers, timeout);
31
28
  return this.httpRequestSender.sendRequest(options);
32
- }
33
- async post(path, data, parameters = {}, headers) {
34
- const options = this.getBaseConnectionParams('POST', path, parameters);
35
- options.headers = headers;
29
+ };
30
+ post = (params) => {
31
+ const { path, data, parameters, headers, timeout } = params;
32
+ const options = this.getBaseConnectionParams('POST', path, parameters, headers, timeout);
36
33
  return this.httpRequestSender.sendRequest(options, data);
37
- }
38
- getBaseConnectionParams(method, path, params) {
39
- let pathName = addParametersToPath(path, params);
34
+ };
35
+ getBaseConnectionParams(method, path, params, headers, timeout) {
40
36
  return {
41
37
  method: method,
42
38
  protocol: this.tls ? 'https:' : 'http:',
43
39
  host: this.ip,
44
40
  port: this.port,
45
- path: pathName,
41
+ path: addParametersToPath(path, params),
46
42
  user: this.user,
47
43
  pass: this.pass,
44
+ headers,
45
+ timeout,
48
46
  };
49
47
  }
50
48
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { FormData as UndiciFormData, Response as UndiciResponse } from 'undici';
3
4
  export type HttpRequestOptions = {
4
5
  method?: string;
@@ -8,8 +8,18 @@ export class HttpRequestSender {
8
8
  connect: { rejectUnauthorized: agentOptions?.rejectUnaurhorized, keepAlive: agentOptions?.keepAlive },
9
9
  });
10
10
  }
11
- sendRequest(options, postData) {
12
- return this.sendRequestWithAuth(options, postData);
11
+ async sendRequest(options, postData) {
12
+ const stackHolder = { stack: '' };
13
+ Error.captureStackTrace(stackHolder, this.sendRequest);
14
+ try {
15
+ return await this.sendRequestWithAuth(options, postData);
16
+ }
17
+ catch (err) {
18
+ if (err instanceof Error) {
19
+ err.stack = `${err.stack}\nCaptured at:\n${stackHolder.stack}`;
20
+ }
21
+ throw err;
22
+ }
13
23
  }
14
24
  async sendRequestWithAuth(options, postData, wwwAuthenticateHeader) {
15
25
  options.timeout ??= 10000;
@@ -79,7 +89,7 @@ export class HttpRequestSender {
79
89
  return authData.digest.getAuthHeader(options.user, options.pass, options.method ?? 'GET', options.path, authData.wwwAuthenticateHeader);
80
90
  }
81
91
  else {
82
- return `Basic ${btoa(options.user + ':' + options.pass)}`;
92
+ return `Basic ${Buffer.from(`${options.user}:${options.pass}`).toString('base64')}`;
83
93
  }
84
94
  }
85
95
  }
@@ -86,7 +86,7 @@ export class HttpServer extends EventEmitter {
86
86
  close() {
87
87
  this.server.close();
88
88
  for (const key in this.sockets) {
89
- this.sockets[key].destroy();
89
+ this.sockets[key]?.destroy();
90
90
  }
91
91
  }
92
92
  }
@@ -1,7 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
+ /// <reference types="node" />
3
4
  import * as EventEmitter from 'events';
4
- import { WsOptions } from '../internal/common';
5
+ import { WsOptions } from '../internal/types';
5
6
  export type WsClientOptions = WsOptions & {
6
7
  address: string;
7
8
  headers?: Record<string, string>;
@@ -1,4 +1,4 @@
1
- import { IWebsocket } from '../internal/common';
1
+ import { IWebsocket } from '../internal/types';
2
2
  import { WsClientOptions } from './WsClient';
3
3
  type TEvent = {
4
4
  data: string;
@@ -1,2 +1,4 @@
1
1
  export { DefaultClient } from './DefaultClient';
2
2
  export { WsClient } from './WsClient';
3
+ export { AxisCameraStationEvents } from '../events/AxisCameraStationEvents';
4
+ export * from '../events/GenetecAgent';
package/esm/node/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  export { DefaultClient } from './DefaultClient';
2
2
  export { WsClient } from './WsClient';
3
+ export { AxisCameraStationEvents } from '../events/AxisCameraStationEvents';
4
+ export * from '../events/GenetecAgent';