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 * as fs from 'fs/promises';
2
- export default class ResourceManager {
2
+ export class ResourceManager {
3
3
  co;
4
4
  imgFileNames = {};
5
5
  fontFileNames = {};
@@ -15,30 +15,26 @@ export default class ResourceManager {
15
15
  this.fontFileNames[moniker] = process.env.INSTALL_PATH + '/fonts/' + fileName;
16
16
  }
17
17
  async image(moniker) {
18
- if (moniker in this.images) {
18
+ if (this.images[moniker] !== undefined) {
19
19
  return this.images[moniker];
20
20
  }
21
- else if (moniker in this.imgFileNames) {
21
+ if (this.imgFileNames[moniker] !== undefined) {
22
22
  const imgData = await fs.readFile(this.imgFileNames[moniker]);
23
23
  this.images[moniker] = await this.co.uploadImageData(imgData);
24
24
  return this.images[moniker];
25
25
  }
26
- else {
27
- throw new Error('Error! Unknown image requested!');
28
- }
26
+ throw new Error('Error! Unknown image requested!');
29
27
  }
30
28
  async font(moniker) {
31
- if (moniker in this.fonts) {
29
+ if (this.fonts[moniker] !== undefined) {
32
30
  return this.fonts[moniker];
33
31
  }
34
- else if (moniker in this.fontFileNames) {
32
+ if (this.fontFileNames[moniker] !== undefined) {
35
33
  const fontData = await fs.readFile(this.fontFileNames[moniker]);
36
34
  this.fonts[moniker] = await this.co.uploadFontData(fontData);
37
35
  return this.fonts[moniker];
38
36
  }
39
- else {
40
- throw new Error('Error! Unknown font requested!');
41
- }
37
+ throw new Error('Error! Unknown font requested!');
42
38
  }
43
39
  clear() {
44
40
  this.images = {};
@@ -1,19 +1,36 @@
1
- import { IClient } from './internal/common';
2
- import { CamScripterOptions, TNodeState, TPackageInfoList, TStorage, TStorageType } from './types/CamScripterAPI';
3
- import { TNetworkCamera } from './types/common';
4
- export declare class CamOverlayAPI {
5
- private client;
6
- constructor(options?: CamScripterOptions | IClient);
7
- checkCameraTime(): Promise<boolean>;
8
- getStorageInfo(): Promise<TStorage>;
9
- getNetworkCameraList(): Promise<TNetworkCamera[]>;
10
- getPackageList(): Promise<TPackageInfoList>;
11
- installPackages(formData: FormData, storage: TStorageType): Promise<void>;
12
- uninstallPackage(packageId: string): Promise<void>;
13
- importSettings(packageId: string, formData: FormData): Promise<void>;
14
- exportSettings(packageId: string, formData: FormData): Promise<void>;
15
- getNodejsStatus(): Promise<TNodeState>;
16
- installNodejs(storage: TStorageType): Promise<void>;
1
+ import { IClient, TResponse } from './internal/types';
2
+ import { TNodeState, TPackageInfoList, TStorage, TStorageType } from './types/CamScripterAPI';
3
+ import { THttpRequestOptions, TNetworkCamera } from './types/common';
4
+ export declare class CamScripterAPI<Client extends IClient<TResponse> = IClient<TResponse>> {
5
+ client: Client;
6
+ constructor(client: Client);
7
+ static getProxyUrlPath: () => string;
8
+ checkCameraTime(options?: THttpRequestOptions): Promise<boolean>;
9
+ getNetworkCameraList(options?: THttpRequestOptions): Promise<TNetworkCamera[]>;
10
+ getStorageInfo(options?: THttpRequestOptions): Promise<TStorage>;
11
+ getPackageList(options?: THttpRequestOptions): Promise<TPackageInfoList>;
12
+ installPackages(formData: FormData, storage: TStorageType, options?: THttpRequestOptions): Promise<{
13
+ status: number;
14
+ message: string;
15
+ }>;
16
+ uninstallPackage(packageId: string, options?: THttpRequestOptions): Promise<{
17
+ status: number;
18
+ message: string;
19
+ }>;
20
+ importSettings(packageId: string, formData: FormData, options?: THttpRequestOptions): Promise<{
21
+ status: number;
22
+ message: string;
23
+ }>;
24
+ exportSettings(packageId: string, formData: FormData, options?: THttpRequestOptions): Promise<{
25
+ status: number;
26
+ message: string;
27
+ }>;
28
+ getNodejsStatus(options?: THttpRequestOptions): Promise<TNodeState>;
29
+ installNodejs(storage: TStorageType, options?: THttpRequestOptions): Promise<{
30
+ status: number;
31
+ message: string;
32
+ }>;
17
33
  private get;
18
34
  private post;
35
+ private getAgent;
19
36
  }
@@ -1,52 +1,57 @@
1
- import { isClient, responseStringify } from './internal/common';
2
- import { DefaultClient } from './node/DefaultClient';
3
- import { packageInfoListSchema, storageSchema, } from './types/CamScripterAPI';
1
+ import { ProxyClient } from './internal/ProxyClient';
2
+ import { responseStringify } from './internal/utils';
3
+ import { cameraTimeResponseSchema, camscripterApiResponseSchema, nodeStateSchema, packageInfoListSchema, storageSchema, } from './types/CamScripterAPI';
4
4
  import { networkCameraListSchema } from './types/common';
5
- export class CamOverlayAPI {
5
+ const BASE_PATH = '/local/camscripter';
6
+ export class CamScripterAPI {
6
7
  client;
7
- constructor(options = {}) {
8
- if (isClient(options)) {
9
- this.client = options;
10
- }
11
- else {
12
- this.client = new DefaultClient(options);
13
- }
8
+ constructor(client) {
9
+ this.client = client;
14
10
  }
15
- async checkCameraTime() {
16
- return (await this.get('/local/camscripter/camera_time.cgi')).state;
11
+ static getProxyUrlPath = () => `${BASE_PATH}/proxy.cgi`;
12
+ async checkCameraTime(options) {
13
+ const data = await this.get(`${BASE_PATH}/camera_time.cgi`, undefined, options);
14
+ return cameraTimeResponseSchema.parse(data).state;
17
15
  }
18
- async getStorageInfo() {
19
- const data = await this.get(`/local/camscripter/package/get_storage.cgi`);
20
- return storageSchema.parse(data);
16
+ async getNetworkCameraList(options) {
17
+ const data = await this.get(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
18
+ return networkCameraListSchema.parse(data.camera_list);
21
19
  }
22
- async getNetworkCameraList() {
23
- const response = await this.get('/local/camscripter/network_camera_list.cgi');
24
- return networkCameraListSchema.parse(response.camera_list);
20
+ async getStorageInfo(options) {
21
+ const data = await this.get(`${BASE_PATH}/package/get_storage.cgi`, undefined, options);
22
+ return storageSchema.parse(data);
25
23
  }
26
- async getPackageList() {
27
- const data = await this.get('/local/camscripter/package/list.cgi');
24
+ async getPackageList(options) {
25
+ const data = await this.get(`${BASE_PATH}/package/list.cgi`, undefined, options);
28
26
  return packageInfoListSchema.parse(data);
29
27
  }
30
- async installPackages(formData, storage) {
31
- await this.post(`/local/camscripter/package/install.cgi?storage=${storage}`, formData);
28
+ async installPackages(formData, storage, options) {
29
+ const data = await this.post(`${BASE_PATH}/package/install.cgi?storage=${storage}`, formData, undefined, options);
30
+ return camscripterApiResponseSchema.parse(data);
32
31
  }
33
- async uninstallPackage(packageId) {
34
- await this.get(`/local/camscripter/package/remove.cgi?package_name=${packageId}`);
32
+ async uninstallPackage(packageId, options) {
33
+ const data = await this.get(`${BASE_PATH}/package/remove.cgi?package_name=${packageId}`, undefined, options);
34
+ return camscripterApiResponseSchema.parse(data);
35
35
  }
36
- async importSettings(packageId, formData) {
37
- await this.post(`/local/camscripter/package/data.cgi?action=IMPORT&package_name=${packageId}`, formData);
36
+ async importSettings(packageId, formData, options) {
37
+ const data = await this.post(`${BASE_PATH}/package/data.cgi?action=IMPORT&package_name=${packageId}`, formData, undefined, options);
38
+ return camscripterApiResponseSchema.parse(data);
38
39
  }
39
- async exportSettings(packageId, formData) {
40
- await this.post(`/local/camscripter/package/data.cgi?action=EXPORT&package_name=${packageId}`, formData);
40
+ async exportSettings(packageId, formData, options) {
41
+ const data = await this.post(`${BASE_PATH}/package/data.cgi?action=EXPORT&package_name=${packageId}`, formData, undefined, options);
42
+ return camscripterApiResponseSchema.parse(data);
41
43
  }
42
- async getNodejsStatus() {
43
- return (await this.get('/local/camscripter/diagnostics.cgi')).node_state;
44
+ async getNodejsStatus(options) {
45
+ const data = await this.get(`${BASE_PATH}/diagnostics.cgi`, undefined, options);
46
+ return nodeStateSchema.parse(data);
44
47
  }
45
- async installNodejs(storage) {
46
- await this.get(`/local/camscripter/node_update.cgi?storage=${storage}`);
48
+ async installNodejs(storage, options) {
49
+ const data = await this.get(`${BASE_PATH}/node_update.cgi?storage=${storage}`, undefined, options);
50
+ return camscripterApiResponseSchema.parse(data);
47
51
  }
48
- async get(path, params) {
49
- const res = await this.client.get(path, params);
52
+ async get(path, parameters, options) {
53
+ const agent = this.getAgent(options?.proxyParams);
54
+ const res = await agent.get({ path, parameters, timeout: options?.timeout });
50
55
  if (res.ok) {
51
56
  return await res.json();
52
57
  }
@@ -54,8 +59,9 @@ export class CamOverlayAPI {
54
59
  throw new Error(await responseStringify(res));
55
60
  }
56
61
  }
57
- async post(path, data, params) {
58
- const res = await this.client.post(path, data, params);
62
+ async post(path, data, parameters, options) {
63
+ const agent = this.getAgent(options?.proxyParams);
64
+ const res = await agent.post({ path, data, parameters, timeout: options?.timeout });
59
65
  if (res.ok) {
60
66
  return await res.json();
61
67
  }
@@ -63,4 +69,7 @@ export class CamOverlayAPI {
63
69
  throw new Error(await responseStringify(res));
64
70
  }
65
71
  }
72
+ getAgent(proxyParams) {
73
+ return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
74
+ }
66
75
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import * as EventEmitter from 'events';
3
- import { WsOptions } from './internal/common';
3
+ import { WsOptions } from './internal/types';
4
4
  export type CamScripterOptions = WsOptions;
5
5
  export type TDeclaration = {
6
6
  type?: '' | 'SOURCE' | 'DATA';
@@ -88,10 +88,10 @@ export class CamScripterAPICameraEventsGenerator extends EventEmitter {
88
88
  }
89
89
  if (dataJSON.call_id !== undefined) {
90
90
  if (errorResponse !== undefined) {
91
- this.sendMessages[dataJSON.call_id].reject(new Error(errorResponse.error));
91
+ this.sendMessages[dataJSON.call_id]?.reject(new Error(errorResponse.error));
92
92
  }
93
93
  else {
94
- this.sendMessages[dataJSON.call_id].resolve(dataJSON);
94
+ this.sendMessages[dataJSON.call_id]?.resolve(dataJSON);
95
95
  }
96
96
  delete this.sendMessages[dataJSON.call_id];
97
97
  }
@@ -124,6 +124,9 @@ export class CamScripterAPICameraEventsGenerator extends EventEmitter {
124
124
  const now = Date.now();
125
125
  for (const callId in this.sendMessages) {
126
126
  const msg = this.sendMessages[callId];
127
+ if (!msg) {
128
+ continue;
129
+ }
127
130
  if (now - msg.sentTimestamp > 10000) {
128
131
  reconnect = true;
129
132
  msg.reject(new Error('Message timeout'));
@@ -147,7 +150,7 @@ export class CamScripterAPICameraEventsGenerator extends EventEmitter {
147
150
  }
148
151
  reportClose() {
149
152
  for (const callId in this.sendMessages) {
150
- this.sendMessages[callId].reject(new Error('Connection lost'));
153
+ this.sendMessages[callId]?.reject(new Error('Connection lost'));
151
154
  }
152
155
  this.sendMessages = {};
153
156
  this.emit('close');
@@ -1,16 +1,18 @@
1
- import { IClient } from './internal/common';
2
- import { CamStreamerAPIOptions, TStreamAttributes, TStreamList } from './types/CamStreamerAPI';
3
- export declare class CamStreamerAPI {
4
- private client;
5
- constructor(options?: CamStreamerAPIOptions | IClient);
6
- getStreamList(): Promise<TStreamList>;
7
- getStream(streamID: string): Promise<TStreamAttributes>;
8
- getStreamParameter(streamID: string, paramName: string): Promise<string>;
9
- setStream(streamID: string, params: Partial<TStreamAttributes>): Promise<void>;
10
- setStreamParameter(streamID: string, paramName: string, value: string): Promise<void>;
11
- isStreaming(streamID: string): Promise<boolean>;
12
- deleteStream(streamID: string): Promise<void>;
13
- wsAutoratization(): Promise<string>;
14
- getUtcTime(): Promise<number>;
1
+ import { IClient, TResponse } from './internal/types';
2
+ import { TStreamAttributes, TStreamList } from './types/CamStreamerAPI';
3
+ import { THttpRequestOptions } from './types/common';
4
+ export declare class CamStreamerAPI<Client extends IClient<TResponse> = IClient<TResponse>> {
5
+ client: Client;
6
+ constructor(client: Client);
7
+ getStreamList(options?: THttpRequestOptions): Promise<TStreamList>;
8
+ getStream(streamId: string, options?: THttpRequestOptions): Promise<TStreamAttributes>;
9
+ getStreamParameter(streamId: string, paramName: string, options?: THttpRequestOptions): Promise<string>;
10
+ setStream(streamId: string, params: Partial<TStreamAttributes>, options?: THttpRequestOptions): Promise<void>;
11
+ setStreamParameter(streamId: string, paramName: string, value: string, options?: THttpRequestOptions): Promise<void>;
12
+ isStreaming(streamId: string, options?: THttpRequestOptions): Promise<boolean>;
13
+ deleteStream(streamId: string, options?: THttpRequestOptions): Promise<void>;
14
+ wsAuthorization(options?: THttpRequestOptions): Promise<string>;
15
+ getUtcTime(options?: THttpRequestOptions): Promise<number>;
15
16
  private get;
17
+ private getAgent;
16
18
  }
@@ -1,56 +1,53 @@
1
- import { isClient, responseStringify } from './internal/common';
2
- import { DefaultClient } from './node/DefaultClient';
3
- import { streamAttributesSchema, streamListSchema, } from './types/CamStreamerAPI';
1
+ import { ProxyClient } from './internal/ProxyClient';
2
+ import { responseStringify } from './internal/utils';
3
+ import { streamAttributesSchema, streamListSchema } from './types/CamStreamerAPI';
4
+ const BASE_PATH = '/local/camstreamer';
4
5
  export class CamStreamerAPI {
5
6
  client;
6
- constructor(options = {}) {
7
- if (isClient(options)) {
8
- this.client = options;
9
- }
10
- else {
11
- this.client = new DefaultClient(options);
12
- }
7
+ constructor(client) {
8
+ this.client = client;
13
9
  }
14
- async getStreamList() {
15
- const streamListRes = await this.get('/local/camstreamer/stream/list.cgi');
10
+ async getStreamList(options) {
11
+ const streamListRes = await this.get(`${BASE_PATH}/stream/list.cgi`, undefined, options);
16
12
  return streamListSchema.parse(streamListRes.data);
17
13
  }
18
- async getStream(streamID) {
19
- const stream = await this.get(`/local/camstreamer/stream/get.cgi?stream_id=${streamID}`);
14
+ async getStream(streamId, options) {
15
+ const stream = await this.get(`${BASE_PATH}/stream/get.cgi?stream_id=${streamId}`, undefined, options);
20
16
  return streamAttributesSchema.parse(stream.data);
21
17
  }
22
- async getStreamParameter(streamID, paramName) {
23
- const stream = await this.get(`/local/camstreamer/stream/get.cgi?stream_id=${streamID}`);
18
+ async getStreamParameter(streamId, paramName, options) {
19
+ const stream = await this.get(`${BASE_PATH}/stream/get.cgi?stream_id=${streamId}`, undefined, options);
24
20
  return stream.data[paramName];
25
21
  }
26
- async setStream(streamID, params) {
22
+ async setStream(streamId, params, options) {
27
23
  const { streamDelay, startTime, stopTime, ...rest } = params;
28
- await this.get('/local/camstreamer/stream/set.cgi', {
29
- stream_id: streamID,
24
+ await this.get(`${BASE_PATH}/stream/set.cgi`, {
25
+ stream_id: streamId,
30
26
  streamDelay: streamDelay ?? '',
31
27
  startTime: startTime ?? 'null',
32
28
  stopTime: stopTime ?? 'null',
33
29
  ...rest,
34
- });
30
+ }, options);
35
31
  }
36
- async setStreamParameter(streamID, paramName, value) {
37
- await this.get(`/local/camstreamer/stream/set.cgi?stream_id=${streamID}&${paramName}=${value}`);
32
+ async setStreamParameter(streamId, paramName, value, options) {
33
+ await this.get(`${BASE_PATH}/stream/set.cgi?stream_id=${streamId}&${paramName}=${value}`, undefined, options);
38
34
  }
39
- async isStreaming(streamID) {
40
- const response = await this.get(`/local/camstreamer/get_streamstat.cgi?stream_id=${streamID}`);
35
+ async isStreaming(streamId, options) {
36
+ const response = await this.get(`${BASE_PATH}/get_streamstat.cgi?stream_id=${streamId}`, undefined, options);
41
37
  return response.data.is_streaming === 1;
42
38
  }
43
- async deleteStream(streamID) {
44
- await this.get('/local/camstreamer/stream/remove.cgi', { stream_id: streamID });
39
+ async deleteStream(streamId, options) {
40
+ await this.get(`${BASE_PATH}/stream/remove.cgi`, { stream_id: streamId }, options);
45
41
  }
46
- wsAutoratization() {
47
- return this.get('/local/camstreamer/ws_authorization.cgi');
42
+ wsAuthorization(options) {
43
+ return this.get(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
48
44
  }
49
- async getUtcTime() {
50
- return await this.get('/local/camstreamer/get_utc_time.cgi');
45
+ async getUtcTime(options) {
46
+ return await this.get(`${BASE_PATH}/get_utc_time.cgi`, undefined, options);
51
47
  }
52
- async get(path, parameters) {
53
- const res = await this.client.get(path, parameters);
48
+ async get(path, parameters, options) {
49
+ const agent = this.getAgent(options?.proxyParams);
50
+ const res = await agent.get({ path, parameters, timeout: options?.timeout });
54
51
  if (res.ok) {
55
52
  return await res.json();
56
53
  }
@@ -58,4 +55,7 @@ export class CamStreamerAPI {
58
55
  throw new Error(await responseStringify(res));
59
56
  }
60
57
  }
58
+ getAgent(proxyParams) {
59
+ return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
60
+ }
61
61
  }
@@ -1,48 +1,53 @@
1
- import { IClient } from './internal/common';
1
+ import { IClient, TResponse } from './internal/types';
2
2
  import { TAudioPushInfo, TOutputInfo, TStorageInfo, TStreamSaveList, TClipList, TStreamSaveLoadList, TClipSaveLoadList, TPlaylistSaveLoadList, TTrackerSaveList, TrackerSaveLoadList, TClipSaveList, TPlaylistSaveList, TCameraOptions, TGlobalAudioSettings, TSecondaryAudioSettings } from './types/CamSwitcherAPI';
3
- import { TAudioChannel, TNetworkCamera, TStorageType } from './types/common';
4
- export declare class CamSwitcherAPI<Client extends IClient = IClient> {
3
+ import { TAudioChannel, THttpRequestOptions, TNetworkCamera, TStorageType } from './types/common';
4
+ export declare class CamSwitcherAPI<Client extends IClient<TResponse> = IClient<TResponse>> {
5
5
  client: Client;
6
+ private CustomFormData;
6
7
  private vapixAgent;
7
- constructor(client: Client);
8
+ constructor(client: Client, CustomFormData?: {
9
+ new (form?: HTMLFormElement | undefined, submitter?: HTMLElement | null | undefined): FormData;
10
+ prototype: FormData;
11
+ });
8
12
  static getProxyUrlPath: () => string;
9
13
  static getWsEventsUrlPath: () => string;
10
14
  static getClipPreviewUrlPath: (id: string, storage: TStorageType) => string;
11
- generateSilence(sampleRate: number, channels: TAudioChannel): Promise<void>;
12
- checkCameraTime(): Promise<boolean>;
13
- getIpListFromNetworkCheck(): Promise<TNetworkCamera[]>;
14
- getMaxFps(source: number): Promise<number>;
15
- getStorageInfo(): Promise<TStorageInfo[]>;
16
- wsAuthorization(): Promise<string>;
17
- getOutputInfo(): Promise<TOutputInfo>;
18
- getAudioPushInfo(): Promise<TAudioPushInfo>;
19
- getStreamSaveList(): Promise<TStreamSaveLoadList>;
20
- getClipSaveList(): Promise<TClipSaveLoadList>;
21
- getPlaylistSaveList(): Promise<TPlaylistSaveLoadList>;
22
- getTrackerSaveList(): Promise<TrackerSaveLoadList>;
23
- setStreamSaveList(data: TStreamSaveList): Promise<boolean>;
24
- setClipSaveList(data: TClipSaveList): Promise<boolean>;
25
- setPlaylistSaveList(data: TPlaylistSaveList): Promise<boolean>;
26
- setTrackerSaveList(data: TTrackerSaveList): Promise<boolean>;
27
- playlistSwitch(playlistName: string): Promise<void>;
28
- playlistQueuePush(playlistName: string): Promise<void>;
29
- playlistQueueClear(): Promise<void>;
30
- playlistQueueList(): Promise<string[]>;
31
- playlistQueuePlayNext(): Promise<void>;
32
- addNewClip(file: any, clipType: 'video' | 'audio', storage: TStorageType, id: string, fileName?: string): Promise<void>;
33
- removeClip(id: string, storage: TStorageType): Promise<any>;
34
- getClipList(): Promise<TClipList>;
35
- setCamSwitchOptions(data: TCameraOptions, cameraFWVersion: string): Promise<boolean>;
36
- setGlobalAudioSettings(settings: TGlobalAudioSettings): Promise<boolean>;
37
- setSecondaryAudioSettings(settings: TSecondaryAudioSettings): Promise<boolean>;
38
- setDefaultPlaylist(id: string): Promise<boolean>;
39
- setPermanentRtspUrlToken(token: string): Promise<boolean>;
40
- getCamSwitchOptions(): Promise<Partial<TCameraOptions>>;
41
- getGlobalAudioSettings(): Promise<TGlobalAudioSettings>;
42
- getSecondaryAudioSettings(): Promise<TSecondaryAudioSettings>;
43
- getPermanentRtspUrlToken(): Promise<string>;
15
+ generateSilence(sampleRate: number, channels: TAudioChannel, options?: THttpRequestOptions): Promise<void>;
16
+ checkCameraTime(options?: THttpRequestOptions): Promise<boolean>;
17
+ getNetworkCameraList(options?: THttpRequestOptions): Promise<TNetworkCamera[]>;
18
+ getMaxFps(source: number, options?: THttpRequestOptions): Promise<number>;
19
+ getStorageInfo(options?: THttpRequestOptions): Promise<TStorageInfo[]>;
20
+ wsAuthorization(options?: THttpRequestOptions): Promise<string>;
21
+ getOutputInfo(options?: THttpRequestOptions): Promise<TOutputInfo>;
22
+ getAudioPushInfo(options?: THttpRequestOptions): Promise<TAudioPushInfo>;
23
+ getStreamSaveList(options?: THttpRequestOptions): Promise<TStreamSaveLoadList>;
24
+ getClipSaveList(options?: THttpRequestOptions): Promise<TClipSaveLoadList>;
25
+ getPlaylistSaveList(options?: THttpRequestOptions): Promise<TPlaylistSaveLoadList>;
26
+ getTrackerSaveList(options?: THttpRequestOptions): Promise<TrackerSaveLoadList>;
27
+ setStreamSaveList(data: TStreamSaveList, options?: THttpRequestOptions): Promise<boolean>;
28
+ setClipSaveList(data: TClipSaveList, options?: THttpRequestOptions): Promise<boolean>;
29
+ setPlaylistSaveList(data: TPlaylistSaveList, options?: THttpRequestOptions): Promise<boolean>;
30
+ setTrackerSaveList(data: TTrackerSaveList, options?: THttpRequestOptions): Promise<boolean>;
31
+ playlistSwitch(playlistName: string, options?: THttpRequestOptions): Promise<void>;
32
+ playlistQueuePush(playlistName: string, options?: THttpRequestOptions): Promise<void>;
33
+ playlistQueueClear(options?: THttpRequestOptions): Promise<void>;
34
+ playlistQueueList(options?: THttpRequestOptions): Promise<string[]>;
35
+ playlistQueuePlayNext(options?: THttpRequestOptions): Promise<void>;
36
+ addNewClip(file: any, clipType: 'video' | 'audio', storage: TStorageType, id: string, fileName?: string, options?: THttpRequestOptions): Promise<void>;
37
+ removeClip(id: string, storage: TStorageType, options?: THttpRequestOptions): Promise<any>;
38
+ getClipList(options?: THttpRequestOptions): Promise<TClipList>;
39
+ setCamSwitchOptions(data: TCameraOptions, cameraFWVersion: string, options?: THttpRequestOptions): Promise<boolean>;
40
+ setGlobalAudioSettings(settings: TGlobalAudioSettings, options?: THttpRequestOptions): Promise<boolean>;
41
+ setSecondaryAudioSettings(settings: TSecondaryAudioSettings, options?: THttpRequestOptions): Promise<boolean>;
42
+ setDefaultPlaylist(id: string, options?: THttpRequestOptions): Promise<boolean>;
43
+ setPermanentRtspUrlToken(token: string, options?: THttpRequestOptions): Promise<boolean>;
44
+ getCamSwitchOptions(options?: THttpRequestOptions): Promise<Partial<TCameraOptions>>;
45
+ getGlobalAudioSettings(options?: THttpRequestOptions): Promise<TGlobalAudioSettings>;
46
+ getSecondaryAudioSettings(options?: THttpRequestOptions): Promise<TSecondaryAudioSettings>;
47
+ getPermanentRtspUrlToken(options?: THttpRequestOptions): Promise<string>;
44
48
  private get;
45
49
  private set;
46
50
  private setParamFromCameraJSON;
47
51
  private getParamFromCameraAndJSONParse;
52
+ private getAgent;
48
53
  }