camstreamerlib 4.0.0-beta.3 → 4.0.0-beta.31

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 (194) hide show
  1. package/README.md +8 -2
  2. package/cjs/CamOverlayAPI.d.ts +48 -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 +34 -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 +17 -14
  17. package/cjs/CamStreamerAPI.js +32 -32
  18. package/cjs/CamSwitcherAPI.d.ts +43 -37
  19. package/cjs/CamSwitcherAPI.js +123 -114
  20. package/cjs/CamSwitcherEvents.d.ts +1 -1
  21. package/cjs/PlaneTrackerAPI.d.ts +43 -0
  22. package/cjs/PlaneTrackerAPI.js +211 -0
  23. package/cjs/VapixAPI.d.ts +56 -42
  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 +7 -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/index.d.ts +2 -0
  50. package/cjs/node/index.js +18 -1
  51. package/cjs/types/CamOverlayAPI/CamOverlayAPI.d.ts +3071 -0
  52. package/cjs/types/CamOverlayAPI/CamOverlayAPI.js +127 -0
  53. package/cjs/types/CamOverlayAPI/accuweatherSchema.d.ts +114 -0
  54. package/cjs/types/CamOverlayAPI/accuweatherSchema.js +50 -0
  55. package/cjs/types/CamOverlayAPI/customGraphicsSchema.d.ts +783 -0
  56. package/cjs/types/CamOverlayAPI/customGraphicsSchema.js +75 -0
  57. package/cjs/types/CamOverlayAPI/imagesSchema.d.ts +122 -0
  58. package/cjs/types/CamOverlayAPI/imagesSchema.js +12 -0
  59. package/cjs/types/CamOverlayAPI/index.d.ts +9 -0
  60. package/cjs/types/CamOverlayAPI/index.js +25 -0
  61. package/cjs/types/CamOverlayAPI/infotickerSchema.d.ts +130 -0
  62. package/cjs/types/CamOverlayAPI/infotickerSchema.js +29 -0
  63. package/cjs/types/CamOverlayAPI/pipSchema.d.ts +166 -0
  64. package/cjs/types/CamOverlayAPI/pipSchema.js +42 -0
  65. package/cjs/types/CamOverlayAPI/ptzCompassSchema.d.ts +126 -0
  66. package/cjs/types/CamOverlayAPI/ptzCompassSchema.js +28 -0
  67. package/cjs/types/CamOverlayAPI/ptzSchema.d.ts +146 -0
  68. package/cjs/types/CamOverlayAPI/ptzSchema.js +15 -0
  69. package/cjs/types/CamOverlayAPI/screenSharingSchema.d.ts +79 -0
  70. package/cjs/types/CamOverlayAPI/screenSharingSchema.js +11 -0
  71. package/cjs/types/CamOverlayAPI/webCameraSharingSchema.d.ts +79 -0
  72. package/cjs/types/CamOverlayAPI/webCameraSharingSchema.js +11 -0
  73. package/cjs/types/CamOverlayDrawingAPI.d.ts +58 -0
  74. package/cjs/types/CamOverlayDrawingAPI.js +2 -0
  75. package/cjs/types/CamOverlayPainter.d.ts +74 -0
  76. package/cjs/types/CamOverlayPainter.js +2 -0
  77. package/cjs/types/CamScripterAPI.d.ts +82 -17
  78. package/cjs/types/CamScripterAPI.js +22 -7
  79. package/cjs/types/CamStreamerAPI.d.ts +16 -5
  80. package/cjs/types/CamStreamerAPI.js +5 -1
  81. package/cjs/types/CamSwitcherAPI.d.ts +4 -6
  82. package/cjs/types/CamSwitcherEvents.d.ts +77 -0
  83. package/cjs/types/CamSwitcherEvents.js +8 -0
  84. package/cjs/types/PlaneTrackerAPI.d.ts +8 -0
  85. package/cjs/types/PlaneTrackerAPI.js +2 -0
  86. package/cjs/types/VapixAPI.d.ts +635 -520
  87. package/cjs/types/VapixAPI.js +62 -24
  88. package/cjs/types/common.d.ts +14 -5
  89. package/cjs/web/DefaultClient.d.ts +5 -5
  90. package/cjs/web/DefaultClient.js +22 -10
  91. package/cjs/web/WsClient.js +2 -2
  92. package/esm/CamOverlayAPI.d.ts +48 -26
  93. package/esm/CamOverlayAPI.js +167 -84
  94. package/esm/CamOverlayDrawingAPI.d.ts +2 -47
  95. package/esm/CamOverlayDrawingAPI.js +6 -3
  96. package/esm/CamOverlayPainter/Frame.d.ts +8 -37
  97. package/esm/CamOverlayPainter/Frame.js +33 -0
  98. package/esm/CamOverlayPainter/Painter.d.ts +16 -10
  99. package/esm/CamOverlayPainter/Painter.js +5 -3
  100. package/esm/CamOverlayPainter/ResourceManager.d.ts +3 -2
  101. package/esm/CamOverlayPainter/ResourceManager.js +7 -11
  102. package/esm/CamScripterAPI.d.ts +34 -16
  103. package/esm/CamScripterAPI.js +46 -37
  104. package/esm/CamScripterAPICameraEventsGenerator.d.ts +1 -1
  105. package/esm/CamScripterAPICameraEventsGenerator.js +6 -3
  106. package/esm/CamStreamerAPI.d.ts +17 -14
  107. package/esm/CamStreamerAPI.js +32 -32
  108. package/esm/CamSwitcherAPI.d.ts +43 -37
  109. package/esm/CamSwitcherAPI.js +116 -107
  110. package/esm/CamSwitcherEvents.d.ts +1 -1
  111. package/esm/PlaneTrackerAPI.d.ts +43 -0
  112. package/esm/PlaneTrackerAPI.js +207 -0
  113. package/esm/VapixAPI.d.ts +56 -42
  114. package/esm/VapixAPI.js +297 -208
  115. package/esm/VapixEvents.d.ts +1 -1
  116. package/esm/VapixEvents.js +3 -3
  117. package/esm/errors/errors.d.ts +3 -0
  118. package/esm/errors/errors.js +6 -0
  119. package/esm/events/AxisCameraStationEvents.d.ts +7 -4
  120. package/esm/events/AxisCameraStationEvents.js +18 -13
  121. package/esm/events/GenetecAgent.d.ts +6 -3
  122. package/esm/events/GenetecAgent.js +20 -9
  123. package/esm/index.d.ts +14 -1
  124. package/esm/index.js +14 -1
  125. package/esm/internal/Digest.js +6 -6
  126. package/esm/internal/ProxyClient.d.ts +8 -9
  127. package/esm/internal/ProxyClient.js +25 -29
  128. package/esm/internal/types.d.ts +42 -0
  129. package/esm/internal/types.js +1 -0
  130. package/esm/internal/utils.d.ts +4 -1
  131. package/esm/internal/utils.js +17 -1
  132. package/esm/internal/versionCompare.d.ts +2 -2
  133. package/esm/node/DefaultClient.d.ts +5 -6
  134. package/esm/node/DefaultClient.js +12 -14
  135. package/esm/node/HttpRequestSender.d.ts +1 -0
  136. package/esm/node/HttpRequestSender.js +13 -3
  137. package/esm/node/HttpServer.js +1 -1
  138. package/esm/node/WsClient.d.ts +2 -1
  139. package/esm/node/index.d.ts +2 -0
  140. package/esm/node/index.js +2 -0
  141. package/esm/types/CamOverlayAPI/CamOverlayAPI.d.ts +3071 -0
  142. package/esm/types/CamOverlayAPI/CamOverlayAPI.js +124 -0
  143. package/esm/types/CamOverlayAPI/accuweatherSchema.d.ts +114 -0
  144. package/esm/types/CamOverlayAPI/accuweatherSchema.js +46 -0
  145. package/esm/types/CamOverlayAPI/customGraphicsSchema.d.ts +783 -0
  146. package/esm/types/CamOverlayAPI/customGraphicsSchema.js +71 -0
  147. package/esm/types/CamOverlayAPI/imagesSchema.d.ts +122 -0
  148. package/esm/types/CamOverlayAPI/imagesSchema.js +8 -0
  149. package/esm/types/CamOverlayAPI/index.d.ts +9 -0
  150. package/esm/types/CamOverlayAPI/index.js +9 -0
  151. package/esm/types/CamOverlayAPI/infotickerSchema.d.ts +130 -0
  152. package/esm/types/CamOverlayAPI/infotickerSchema.js +25 -0
  153. package/esm/types/CamOverlayAPI/pipSchema.d.ts +166 -0
  154. package/esm/types/CamOverlayAPI/pipSchema.js +38 -0
  155. package/esm/types/CamOverlayAPI/ptzCompassSchema.d.ts +126 -0
  156. package/esm/types/CamOverlayAPI/ptzCompassSchema.js +24 -0
  157. package/esm/types/CamOverlayAPI/ptzSchema.d.ts +146 -0
  158. package/esm/types/CamOverlayAPI/ptzSchema.js +11 -0
  159. package/esm/types/CamOverlayAPI/screenSharingSchema.d.ts +79 -0
  160. package/esm/types/CamOverlayAPI/screenSharingSchema.js +7 -0
  161. package/esm/types/CamOverlayAPI/webCameraSharingSchema.d.ts +79 -0
  162. package/esm/types/CamOverlayAPI/webCameraSharingSchema.js +7 -0
  163. package/esm/types/CamOverlayDrawingAPI.d.ts +58 -0
  164. package/esm/types/CamOverlayDrawingAPI.js +1 -0
  165. package/esm/types/CamOverlayPainter.d.ts +74 -0
  166. package/esm/types/CamOverlayPainter.js +1 -0
  167. package/esm/types/CamScripterAPI.d.ts +82 -17
  168. package/esm/types/CamScripterAPI.js +21 -6
  169. package/esm/types/CamStreamerAPI.d.ts +16 -5
  170. package/esm/types/CamStreamerAPI.js +4 -0
  171. package/esm/types/CamSwitcherAPI.d.ts +4 -6
  172. package/esm/types/CamSwitcherEvents.d.ts +77 -0
  173. package/esm/types/CamSwitcherEvents.js +8 -0
  174. package/esm/types/PlaneTrackerAPI.d.ts +8 -0
  175. package/esm/types/PlaneTrackerAPI.js +1 -0
  176. package/esm/types/VapixAPI.d.ts +635 -520
  177. package/esm/types/VapixAPI.js +61 -23
  178. package/esm/types/common.d.ts +14 -5
  179. package/esm/web/DefaultClient.d.ts +5 -5
  180. package/esm/web/DefaultClient.js +22 -10
  181. package/esm/web/WsClient.js +2 -2
  182. package/package.json +9 -8
  183. package/cjs/internal/common.d.ts +0 -39
  184. package/cjs/internal/common.js +0 -27
  185. package/cjs/node/WsEventClient.d.ts +0 -13
  186. package/cjs/node/WsEventClient.js +0 -22
  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/node/WsEventClient.d.ts +0 -13
  192. package/esm/node/WsEventClient.js +0 -18
  193. package/esm/types/CamOverlayAPI.d.ts +0 -188
  194. package/esm/types/CamOverlayAPI.js +0 -44
@@ -1,123 +1,134 @@
1
1
  import { z } from 'zod';
2
2
  import { AddNewClipError } from './errors/errors';
3
- import { isNullish, responseStringify } from './internal/common';
3
+ import { isClip, isNullish, responseStringify } from './internal/utils';
4
4
  import { storageInfoListSchema, outputInfoSchema, audioPushInfoSchema, clipListSchema, playlistQueueSchema, streamSaveLoadSchema, clipSaveLoadSchema, playlistSaveLoadSchema, trackerSaveLoadSchema, } from './types/CamSwitcherAPI';
5
- import { networkCameraListSchema } from './types/common';
5
+ import { networkCameraListSchema, } from './types/common';
6
6
  import { VapixAPI } from './VapixAPI';
7
7
  import { isFirmwareVersionAtLeast } from './internal/versionCompare';
8
- import { isClip } from './internal/utils';
9
8
  import { FIRMWARE_WITH_BITRATE_MODES_SUPPORT } from './internal/constants';
10
- const baseUrl = '/local/camswitcher/api';
9
+ import { ProxyClient } from './internal/ProxyClient';
10
+ const BASE_PATH = '/local/camswitcher/api';
11
11
  export class CamSwitcherAPI {
12
12
  client;
13
+ CustomFormData;
13
14
  vapixAgent;
14
- constructor(client) {
15
+ constructor(client, CustomFormData = FormData) {
15
16
  this.client = client;
16
- this.vapixAgent = new VapixAPI(client, () => '');
17
+ this.CustomFormData = CustomFormData;
18
+ this.vapixAgent = new VapixAPI(client);
17
19
  }
18
- static getProxyUrlPath = () => `${baseUrl}/proxy.cgi`;
20
+ static getProxyUrlPath = () => `${BASE_PATH}/proxy.cgi`;
19
21
  static getWsEventsUrlPath = () => `/local/camswitcher/events`;
20
- static getClipPreviewUrlPath = (id, storage) => `${baseUrl}/clip_preview.cgi?clip_name=${id}&storage=${storage}`;
21
- async generateSilence(sampleRate, channels) {
22
- await this.client.get(`${baseUrl}/generate_silence.cgi`, {
23
- sample_rate: sampleRate.toString(),
24
- channels,
22
+ static getClipPreviewUrlPath = (id, storage) => `${BASE_PATH}/clip_preview.cgi?clip_name=${id}&storage=${storage}`;
23
+ getClient(proxyParams) {
24
+ return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
25
+ }
26
+ async generateSilence(sampleRate, channels, options) {
27
+ const agent = this.getClient(options?.proxyParams);
28
+ await agent.get({
29
+ path: `${BASE_PATH}/generate_silence.cgi`,
30
+ parameters: {
31
+ sample_rate: sampleRate.toString(),
32
+ channels,
33
+ },
34
+ timeout: options?.timeout,
25
35
  });
26
36
  }
27
- async checkCameraTime() {
28
- const data = await this.get(`${baseUrl}/camera_time.cgi`);
37
+ async checkCameraTime(options) {
38
+ const data = await this.get(`${BASE_PATH}/camera_time.cgi`, undefined, options);
29
39
  return z.boolean().parse(data);
30
40
  }
31
- async getIpListFromNetworkCheck() {
32
- const data = await this.get(`${baseUrl}/network_camera_list.cgi`);
41
+ async getNetworkCameraList(options) {
42
+ const data = await this.get(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
33
43
  return networkCameraListSchema.parse(data);
34
44
  }
35
- async getMaxFps(source) {
36
- const data = await this.get(`${baseUrl}/get_max_framerate.cgi`, {
45
+ async getMaxFps(source, options) {
46
+ const data = await this.get(`${BASE_PATH}/get_max_framerate.cgi`, {
37
47
  video_source: source.toString(),
38
- });
48
+ }, options);
39
49
  return z.number().parse(data);
40
50
  }
41
- async getStorageInfo() {
42
- const data = await this.get(`${baseUrl}/get_storage.cgi`);
51
+ async getStorageInfo(options) {
52
+ const data = await this.get(`${BASE_PATH}/get_storage.cgi`, undefined, options);
43
53
  return storageInfoListSchema.parse(data);
44
54
  }
45
- async wsAuthorization() {
46
- const data = await this.get(`${baseUrl}/ws_authorization.cgi`);
55
+ async wsAuthorization(options) {
56
+ const data = await this.get(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
47
57
  return z.string().parse(data);
48
58
  }
49
- async getOutputInfo() {
50
- const data = await this.get(`${baseUrl}/output_info.cgi`);
59
+ async getOutputInfo(options) {
60
+ const data = await this.get(`${BASE_PATH}/output_info.cgi`, undefined, options);
51
61
  return outputInfoSchema.parse(data);
52
62
  }
53
- async getAudioPushInfo() {
54
- const data = await this.get(`${baseUrl}/audio_push_info.cgi`);
63
+ async getAudioPushInfo(options) {
64
+ const data = await this.get(`${BASE_PATH}/audio_push_info.cgi`, undefined, options);
55
65
  return audioPushInfoSchema.parse(data);
56
66
  }
57
- async getStreamSaveList() {
58
- const data = await this.get(`${baseUrl}/streams.cgi`, { action: 'get' });
67
+ async getStreamSaveList(options) {
68
+ const data = await this.get(`${BASE_PATH}/streams.cgi`, { action: 'get' }, options);
59
69
  return streamSaveLoadSchema.parse(data);
60
70
  }
61
- async getClipSaveList() {
62
- const data = await this.get(`${baseUrl}/clips.cgi`, { action: 'get' });
71
+ async getClipSaveList(options) {
72
+ const data = await this.get(`${BASE_PATH}/clips.cgi`, { action: 'get' }, options);
63
73
  return clipSaveLoadSchema.parse(data);
64
74
  }
65
- async getPlaylistSaveList() {
66
- const data = await this.get(`${baseUrl}/playlists.cgi`, { action: 'get' });
75
+ async getPlaylistSaveList(options) {
76
+ const data = await this.get(`${BASE_PATH}/playlists.cgi`, { action: 'get' }, options);
67
77
  return playlistSaveLoadSchema.parse(data);
68
78
  }
69
- async getTrackerSaveList() {
70
- const data = await this.get(`${baseUrl}/trackers.cgi`, { action: 'get' });
79
+ async getTrackerSaveList(options) {
80
+ const data = await this.get(`${BASE_PATH}/trackers.cgi`, { action: 'get' }, options);
71
81
  return trackerSaveLoadSchema.parse(data);
72
82
  }
73
- async setStreamSaveList(data) {
74
- return await this.set(`${baseUrl}/streams.cgi`, data, { action: 'set' });
83
+ async setStreamSaveList(data, options) {
84
+ return await this.set(`${BASE_PATH}/streams.cgi`, data, { action: 'set' }, options);
75
85
  }
76
- async setClipSaveList(data) {
77
- return await this.set(`${baseUrl}/clips.cgi`, data, { action: 'set' });
86
+ async setClipSaveList(data, options) {
87
+ return await this.set(`${BASE_PATH}/clips.cgi`, data, { action: 'set' }, options);
78
88
  }
79
- async setPlaylistSaveList(data) {
80
- return await this.set(`${baseUrl}/playlists.cgi`, data, { action: 'set' });
89
+ async setPlaylistSaveList(data, options) {
90
+ return await this.set(`${BASE_PATH}/playlists.cgi`, data, { action: 'set' }, options);
81
91
  }
82
- async setTrackerSaveList(data) {
83
- return await this.set(`${baseUrl}/trackers.cgi`, data, { action: 'set' });
92
+ async setTrackerSaveList(data, options) {
93
+ return await this.set(`${BASE_PATH}/trackers.cgi`, data, { action: 'set' }, options);
84
94
  }
85
- async playlistSwitch(playlistName) {
86
- await this.get(`${baseUrl}/playlist_switch.cgi?playlist_name=${playlistName}`);
95
+ async playlistSwitch(playlistName, options) {
96
+ await this.get(`${BASE_PATH}/playlist_switch.cgi`, { playlist_name: playlistName }, options);
87
97
  }
88
- async playlistQueuePush(playlistName) {
89
- await this.get(`${baseUrl}/playlist_queue_push.cgi?playlist_name=${playlistName}`);
98
+ async playlistQueuePush(playlistName, options) {
99
+ await this.get(`${BASE_PATH}/playlist_queue_push.cgi`, { playlist_name: playlistName }, options);
90
100
  }
91
- async playlistQueueClear() {
92
- await this.get(`${baseUrl}/playlist_queue_clear.cgi`);
101
+ async playlistQueueClear(options) {
102
+ await this.get(`${BASE_PATH}/playlist_queue_clear.cgi`, undefined, options);
93
103
  }
94
- async playlistQueueList() {
95
- const data = await this.get(`${baseUrl}/playlist_queue_list.cgi`);
104
+ async playlistQueueList(options) {
105
+ const data = await this.get(`${BASE_PATH}/playlist_queue_list.cgi`, undefined, options);
96
106
  return playlistQueueSchema.parse(data).playlistQueueList;
97
107
  }
98
- async playlistQueuePlayNext() {
99
- await this.get(`${baseUrl}/playlist_queue_play_next.cgi`);
108
+ async playlistQueuePlayNext(options) {
109
+ await this.get(`${BASE_PATH}/playlist_queue_play_next.cgi`, undefined, options);
100
110
  }
101
- async addNewClip(file, clipType, storage, id, fileName) {
102
- const formData = new FormData();
111
+ async addNewClip(file, clipType, storage, id, fileName, options) {
112
+ const path = `${BASE_PATH}/clip_upload.cgi?storage=${storage}`;
113
+ const formData = new this.CustomFormData();
103
114
  formData.append('clip_name', id);
104
115
  formData.append('clip_type', clipType);
105
116
  formData.append('file', file, fileName);
106
- const path = `${baseUrl}/clip_upload.cgi?storage=${storage}`;
107
- const res = await this.client.post(path, formData);
117
+ const agent = this.getClient(options?.proxyParams);
118
+ const res = await agent.post({ path, data: formData, timeout: options?.timeout });
108
119
  const output = (await res.json());
109
120
  if (output.status !== 200) {
110
121
  throw new AddNewClipError(output.message);
111
122
  }
112
123
  }
113
- removeClip(id, storage) {
114
- return this.get(`${baseUrl}/clip_remove.cgi`, { clip_name: id, storage });
124
+ removeClip(id, storage, options) {
125
+ return this.get(`${BASE_PATH}/clip_remove.cgi`, { clip_name: id, storage }, options);
115
126
  }
116
- async getClipList() {
117
- const data = await this.get(`${baseUrl}/clip_list.cgi`);
127
+ async getClipList(options) {
128
+ const data = await this.get(`${BASE_PATH}/clip_list.cgi`, undefined, options);
118
129
  return clipListSchema.parse(data).clip_list;
119
130
  }
120
- setCamSwitchOptions(data, cameraFWVersion) {
131
+ setCamSwitchOptions(data, cameraFWVersion, options) {
121
132
  const bitrateVapixParams = parseBitrateOptionsToBitrateVapixParams(cameraFWVersion, data.bitrateMode, data);
122
133
  const saveData = {
123
134
  video: {
@@ -135,9 +146,9 @@ export class CamSwitcherAPI {
135
146
  },
136
147
  keyboard: data.keyboard,
137
148
  };
138
- return this.setParamFromCameraJSON(CSW_PARAM_NAMES.SETTINGS, saveData);
149
+ return this.setParamFromCameraJSON(CSW_PARAM_NAMES.SETTINGS, saveData, options);
139
150
  }
140
- setGlobalAudioSettings(settings) {
151
+ setGlobalAudioSettings(settings, options) {
141
152
  let acceptedType = 'NONE';
142
153
  if (settings.type === 'source' && settings.source) {
143
154
  if (isClip(settings.source)) {
@@ -153,9 +164,9 @@ export class CamSwitcherAPI {
153
164
  clip_name: settings.source,
154
165
  storage: settings.storage,
155
166
  };
156
- return this.setParamFromCameraJSON(CSW_PARAM_NAMES.MASTER_AUDIO, data);
167
+ return this.setParamFromCameraJSON(CSW_PARAM_NAMES.MASTER_AUDIO, data, options);
157
168
  }
158
- setSecondaryAudioSettings(settings) {
169
+ setSecondaryAudioSettings(settings, options) {
159
170
  const data = {
160
171
  type: settings.type,
161
172
  stream_name: settings.streamName ?? '',
@@ -164,19 +175,19 @@ export class CamSwitcherAPI {
164
175
  secondary_audio_level: settings.secondaryAudioLevel,
165
176
  master_audio_level: settings.masterAudioLevel,
166
177
  };
167
- return this.setParamFromCameraJSON(CSW_PARAM_NAMES.SECONDARY_AUDIO, data);
178
+ return this.setParamFromCameraJSON(CSW_PARAM_NAMES.SECONDARY_AUDIO, data, options);
168
179
  }
169
- setDefaultPlaylist(id) {
180
+ setDefaultPlaylist(id, options) {
170
181
  const value = JSON.stringify({ default_playlist_id: id });
171
182
  return this.vapixAgent.setParameter({
172
183
  [CSW_PARAM_NAMES.DEFAULT_PLAYLIST]: value,
173
- }, null);
184
+ }, options);
174
185
  }
175
- setPermanentRtspUrlToken(token) {
176
- return this.vapixAgent.setParameter({ [CSW_PARAM_NAMES.RTSP_TOKEN]: token }, null);
186
+ setPermanentRtspUrlToken(token, options) {
187
+ return this.vapixAgent.setParameter({ [CSW_PARAM_NAMES.RTSP_TOKEN]: token }, options);
177
188
  }
178
- async getCamSwitchOptions() {
179
- const saveData = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SETTINGS);
189
+ async getCamSwitchOptions(options) {
190
+ const saveData = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SETTINGS, options);
180
191
  if (isNullish(saveData.video)) {
181
192
  return saveData;
182
193
  }
@@ -201,12 +212,12 @@ export class CamSwitcherAPI {
201
212
  keyboard: saveData.keyboard,
202
213
  };
203
214
  }
204
- async getGlobalAudioSettings() {
215
+ async getGlobalAudioSettings(options) {
205
216
  const settings = {
206
217
  type: 'fromSource',
207
218
  source: 'fromSource',
208
219
  };
209
- const res = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.MASTER_AUDIO);
220
+ const res = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.MASTER_AUDIO, options);
210
221
  if (res.type === 'STREAM') {
211
222
  settings.type = 'source';
212
223
  settings.source = res.stream_name;
@@ -218,8 +229,8 @@ export class CamSwitcherAPI {
218
229
  }
219
230
  return settings;
220
231
  }
221
- async getSecondaryAudioSettings() {
222
- const res = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SECONDARY_AUDIO);
232
+ async getSecondaryAudioSettings(options) {
233
+ const res = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SECONDARY_AUDIO, options);
223
234
  const settings = {
224
235
  type: res.type ?? 'NONE',
225
236
  streamName: res.stream_name,
@@ -230,13 +241,14 @@ export class CamSwitcherAPI {
230
241
  };
231
242
  return settings;
232
243
  }
233
- async getPermanentRtspUrlToken() {
244
+ async getPermanentRtspUrlToken(options) {
234
245
  const paramName = CSW_PARAM_NAMES.RTSP_TOKEN;
235
- const res = await this.vapixAgent.getParameter([paramName], null);
246
+ const res = await this.vapixAgent.getParameter([paramName], options);
236
247
  return res[paramName] ?? '';
237
248
  }
238
- async get(path, parameters = {}) {
239
- const res = await this.client.get(path, parameters);
249
+ async get(path, parameters, options) {
250
+ const agent = this.getClient(options?.proxyParams);
251
+ const res = await agent.get({ path, parameters, timeout: options?.timeout });
240
252
  if (res.ok) {
241
253
  const d = (await res.json());
242
254
  return d.data;
@@ -245,8 +257,9 @@ export class CamSwitcherAPI {
245
257
  throw new Error(await responseStringify(res));
246
258
  }
247
259
  }
248
- async set(path, data, parameters = {}) {
249
- const res = await this.client.post(path, JSON.stringify(data), parameters);
260
+ async set(path, data, parameters, options) {
261
+ const agent = this.getClient(options?.proxyParams);
262
+ const res = await agent.post({ path, data: JSON.stringify(data), parameters, timeout: options?.timeout });
250
263
  if (res.ok) {
251
264
  const parsed = await res.json();
252
265
  return parsed.message === 'OK';
@@ -255,13 +268,13 @@ export class CamSwitcherAPI {
255
268
  throw new Error(await responseStringify(res));
256
269
  }
257
270
  }
258
- setParamFromCameraJSON(paramName, data) {
271
+ setParamFromCameraJSON(paramName, data, options) {
259
272
  const params = {};
260
273
  params[paramName] = JSON.stringify(data);
261
- return this.vapixAgent.setParameter(params, null);
274
+ return this.vapixAgent.setParameter(params, options);
262
275
  }
263
- async getParamFromCameraAndJSONParse(paramName) {
264
- const data = await this.vapixAgent.getParameter([paramName], null);
276
+ async getParamFromCameraAndJSONParse(paramName, options) {
277
+ const data = await this.vapixAgent.getParameter([paramName], options);
265
278
  if (data[paramName] !== undefined) {
266
279
  try {
267
280
  if (data[paramName] === '') {
@@ -292,16 +305,12 @@ const parseBitrateOptionsToBitrateVapixParams = (firmWareVersion, bitrateMode, c
292
305
  if (bitrateMode === null) {
293
306
  return '';
294
307
  }
295
- if (bitrateMode === 'VBR') {
296
- return 'videobitratemode=vbr';
297
- }
298
- if (bitrateMode === 'MBR') {
299
- return `videobitratemode=mbr&videomaxbitrate=${cameraOptions.maximumBitRate}`;
300
- }
301
- if (bitrateMode === 'ABR') {
302
- return `videobitratemode=abr&videoabrtargetbitrate=${cameraOptions.maximumBitRate}&videoabrretentiontime=${cameraOptions.retentionTime}&videoabrmaxbitrate=${cameraOptions.bitRateLimit}`;
303
- }
304
- throw new Error('Unknown bitrateMode param in getVapixParams method.');
308
+ const data = {
309
+ VBR: 'videobitratemode=vbr',
310
+ MBR: `videobitratemode=mbr&videomaxbitrate=${cameraOptions.maximumBitRate}`,
311
+ ABR: `videobitratemode=abr&videoabrtargetbitrate=${cameraOptions.maximumBitRate}&videoabrretentiontime=${cameraOptions.retentionTime}&videoabrmaxbitrate=${cameraOptions.bitRateLimit}`,
312
+ };
313
+ return data[bitrateMode];
305
314
  };
306
315
  const parseVapixParamsToBitrateOptions = (bitrateVapixParams) => {
307
316
  const params = {};
@@ -312,7 +321,7 @@ const parseVapixParamsToBitrateOptions = (bitrateVapixParams) => {
312
321
  const bitrateMode = params['videobitratemode'] !== undefined ? params['videobitratemode'].toUpperCase() : undefined;
313
322
  const hasLowerFw = bitrateMode === undefined && params['videomaxbitrate'] !== undefined;
314
323
  if (hasLowerFw) {
315
- const maximumBitRate = parseInt(params['videomaxbitrate'], 10);
324
+ const maximumBitRate = parseInt(params['videomaxbitrate'] ?? '0', 10);
316
325
  return {
317
326
  bitrateMode: 'MBR',
318
327
  maximumBitRate: maximumBitRate,
@@ -321,19 +330,19 @@ const parseVapixParamsToBitrateOptions = (bitrateVapixParams) => {
321
330
  };
322
331
  }
323
332
  if (bitrateMode === 'ABR') {
324
- const maximumBitRate = parseInt(params['videoabrtargetbitrate'], 10);
325
- const retentionTime = parseInt(params['videoabrretentiontime'], 10);
326
- const bitrateLimit = parseInt(params['videoabrmaxbitrate'], 10);
333
+ const maximumBitRate = parseInt(params['videoabrtargetbitrate'] ?? '0', 10);
334
+ const retentionTime = parseInt(params['videoabrretentiontime'] ?? '0', 10);
335
+ const bitRateLimit = parseInt(params['videoabrmaxbitrate'] ?? '0', 10);
327
336
  return {
328
- bitrateMode: bitrateMode,
329
- maximumBitRate: maximumBitRate,
330
- retentionTime: retentionTime,
331
- bitRateLimit: bitrateLimit,
337
+ bitrateMode,
338
+ maximumBitRate,
339
+ retentionTime,
340
+ bitRateLimit,
332
341
  };
333
342
  }
334
343
  else if (bitrateMode === 'MBR') {
335
- const maximumBitRate = parseInt(params['videomaxbitrate'], 10);
336
- const oldMaximumBitrateParamValue = parseInt(params['videombrmaxbitrate'], 10);
344
+ const maximumBitRate = params['videomaxbitrate'] !== undefined ? parseInt(params['videomaxbitrate'], 10) : null;
345
+ const oldMaximumBitrateParamValue = parseInt(params['videombrmaxbitrate'] ?? '0', 10);
337
346
  return {
338
347
  bitrateMode: bitrateMode,
339
348
  maximumBitRate: maximumBitRate ?? oldMaximumBitrateParamValue,
@@ -1,4 +1,4 @@
1
- import { IWebsocket } from './internal/common';
1
+ import { IWebsocket } from './internal/types';
2
2
  import { TCamSwitcherEventOfType, TCamSwitcherEventType } from './types/CamSwitcherEvents';
3
3
  type TListenerFunction<T extends TCamSwitcherEventType> = (data: TCamSwitcherEventOfType<T>, isInit: boolean) => void;
4
4
  export declare class CamSwitcherEvents<Event extends {
@@ -0,0 +1,43 @@
1
+ import { IClient, TBlobResponse, TParameters, TResponse } from './internal/types';
2
+ import { ICAO, TApiUser, TExportDataType, TImportDataType } from './types/PlaneTrackerAPI';
3
+ import { THttpRequestOptions, TProxyParams } from './types/common';
4
+ import { ProxyClient } from './internal/ProxyClient';
5
+ export declare class PlaneTrackerAPI<Client extends IClient<TResponse> = IClient<TResponse>> {
6
+ private client;
7
+ private apiUser;
8
+ constructor(client: Client, apiUser: TApiUser);
9
+ static getProxyUrlPath: () => string;
10
+ getClient(proxyParams?: TProxyParams): Client | ProxyClient<Client>;
11
+ checkCameraTime(options?: THttpRequestOptions): Promise<boolean>;
12
+ resetPtzCalibration: (options?: THttpRequestOptions) => Promise<TResponse>;
13
+ resetFocusCalibration: (options?: THttpRequestOptions) => Promise<TResponse>;
14
+ serverRunCheck: (options?: THttpRequestOptions) => Promise<TResponse>;
15
+ getLiveViewAlias: (rtspUrl: string, options?: THttpRequestOptions) => Promise<TResponse>;
16
+ fetchCameraSettings: (options?: THttpRequestOptions) => Promise<any>;
17
+ setCameraSettings: (settingsJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
18
+ fetchServerSettings: (options?: THttpRequestOptions) => Promise<any>;
19
+ exportAppSettings: (dataType: TExportDataType, options?: THttpRequestOptions) => Promise<TBlobResponse<Client>>;
20
+ importAppSettings: (dataType: TImportDataType, formData: FormData, options?: THttpRequestOptions) => Promise<TResponse>;
21
+ fetchFlightInfo: (icao: ICAO, options?: THttpRequestOptions) => Promise<any>;
22
+ getTrackingMode: (options?: THttpRequestOptions) => Promise<any>;
23
+ setTrackingMode: (modeJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
24
+ startTrackingPlane: (icao: ICAO, options?: THttpRequestOptions) => Promise<TResponse>;
25
+ stopTrackingPlane: (options?: THttpRequestOptions) => Promise<TResponse>;
26
+ getPriorityList: (options?: THttpRequestOptions) => Promise<any>;
27
+ setPriorityList: (priorityListJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
28
+ getWhiteList: (options?: THttpRequestOptions) => Promise<any>;
29
+ setWhiteList: (whiteListJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
30
+ getBlackList: (options?: THttpRequestOptions) => Promise<any>;
31
+ setBlackList: (blackListJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
32
+ fetchMapInfo: (options?: THttpRequestOptions) => Promise<any>;
33
+ getZones: (options?: THttpRequestOptions) => Promise<any>;
34
+ setZones: (zonesJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
35
+ goToCoordinates: (lat: number, lon: number, alt?: number, options?: THttpRequestOptions) => Promise<TResponse>;
36
+ checkGenetecConnection: (params: TParameters, options?: THttpRequestOptions) => Promise<TResponse>;
37
+ getGenetecCameraList: (params: TParameters, options?: THttpRequestOptions) => Promise<any>;
38
+ private _getJson;
39
+ private _getBlob;
40
+ private parseBlobResponse;
41
+ private _postJsonEncoded;
42
+ private _postUrlEncoded;
43
+ }
@@ -0,0 +1,207 @@
1
+ import { z } from 'zod';
2
+ import { paramToUrl, responseStringify } from './internal/utils';
3
+ import { ParsingBlobError } from './errors/errors';
4
+ import { ProxyClient } from './internal/ProxyClient';
5
+ const BASE_PATH = '/local/planetracker';
6
+ export class PlaneTrackerAPI {
7
+ client;
8
+ apiUser;
9
+ constructor(client, apiUser) {
10
+ this.client = client;
11
+ this.apiUser = apiUser;
12
+ }
13
+ static getProxyUrlPath = () => `${BASE_PATH}/proxy.cgi`;
14
+ getClient(proxyParams) {
15
+ return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
16
+ }
17
+ async checkCameraTime(options) {
18
+ const response = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
19
+ return z.boolean().parse(response.state);
20
+ }
21
+ resetPtzCalibration = async (options) => {
22
+ const agent = this.getClient(options?.proxyParams);
23
+ return await agent.get({
24
+ path: `${BASE_PATH}/package/resetPtzCalibration.cgi`,
25
+ parameters: this.apiUser,
26
+ timeout: options?.timeout,
27
+ });
28
+ };
29
+ resetFocusCalibration = async (options) => {
30
+ const agent = this.getClient(options?.proxyParams);
31
+ return await agent.get({
32
+ path: `${BASE_PATH}/package/resetFocusCalibration.cgi`,
33
+ parameters: this.apiUser,
34
+ timeout: options?.timeout,
35
+ });
36
+ };
37
+ serverRunCheck = async (options) => {
38
+ const agent = this.getClient(options?.proxyParams);
39
+ return await agent.get({ path: `${BASE_PATH}/package/serverRunCheck.cgi`, timeout: options?.timeout });
40
+ };
41
+ getLiveViewAlias = async (rtspUrl, options) => {
42
+ const agent = this.getClient(options?.proxyParams);
43
+ return await agent.get({
44
+ path: `${BASE_PATH}/getLiveViewAlias.cgi`,
45
+ parameters: { rtsp_url: rtspUrl },
46
+ timeout: options?.timeout,
47
+ });
48
+ };
49
+ fetchCameraSettings = async (options) => {
50
+ return await this._getJson(`${BASE_PATH}/package_camera_settings.cgi`, { action: 'get' }, options);
51
+ };
52
+ setCameraSettings = async (settingsJsonString, options) => {
53
+ return await this._postJsonEncoded(`${BASE_PATH}/package_camera_settings.cgi`, settingsJsonString, {
54
+ action: 'set',
55
+ }, options);
56
+ };
57
+ fetchServerSettings = async (options) => {
58
+ return await this._getJson(`${BASE_PATH}/package_server_settings.cgi`, { action: 'get' }, options);
59
+ };
60
+ exportAppSettings = async (dataType, options) => {
61
+ return await this._getBlob(`${BASE_PATH}/package_data.cgi`, { action: 'EXPORT', dataType }, options);
62
+ };
63
+ importAppSettings = async (dataType, formData, options) => {
64
+ const agent = this.getClient(options?.proxyParams);
65
+ return await agent.post({
66
+ path: `${BASE_PATH}/package_data.cgi`,
67
+ data: formData,
68
+ parameters: { action: 'IMPORT', dataType },
69
+ timeout: options?.timeout,
70
+ });
71
+ };
72
+ fetchFlightInfo = async (icao, options) => {
73
+ return await this._getJson(`${BASE_PATH}/package/flightInfo.cgi`, { icao: encodeURIComponent(icao) }, options);
74
+ };
75
+ getTrackingMode = async (options) => {
76
+ return await this._getJson(`${BASE_PATH}/package/getTrackingMode.cgi`, undefined, options);
77
+ };
78
+ setTrackingMode = async (modeJsonString, options) => {
79
+ return await this._postJsonEncoded(`${BASE_PATH}/package/setTrackingMode.cgi`, modeJsonString, this.apiUser, options);
80
+ };
81
+ startTrackingPlane = async (icao, options) => {
82
+ const agent = this.getClient(options?.proxyParams);
83
+ return await agent.get({
84
+ path: `${BASE_PATH}/package/trackIcao.cgi`,
85
+ parameters: { icao, ...this.apiUser },
86
+ timeout: options?.timeout,
87
+ });
88
+ };
89
+ stopTrackingPlane = async (options) => {
90
+ const agent = this.getClient(options?.proxyParams);
91
+ return await agent.get({
92
+ path: `${BASE_PATH}/package/resetIcao.cgi`,
93
+ parameters: this.apiUser,
94
+ timeout: options?.timeout,
95
+ });
96
+ };
97
+ getPriorityList = async (options) => {
98
+ return await this._getJson(`${BASE_PATH}/package/getPriorityList.cgi`, undefined, options);
99
+ };
100
+ setPriorityList = async (priorityListJsonString, options) => {
101
+ return await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`, priorityListJsonString, this.apiUser, options);
102
+ };
103
+ getWhiteList = async (options) => {
104
+ return await this._getJson(`${BASE_PATH}/package/getWhiteList.cgi`, undefined, options);
105
+ };
106
+ setWhiteList = async (whiteListJsonString, options) => {
107
+ return await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`, whiteListJsonString, this.apiUser, options);
108
+ };
109
+ getBlackList = async (options) => {
110
+ return await this._getJson(`${BASE_PATH}/package/getBlackList.cgi`, undefined, options);
111
+ };
112
+ setBlackList = async (blackListJsonString, options) => {
113
+ return await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`, blackListJsonString, this.apiUser, options);
114
+ };
115
+ fetchMapInfo = async (options) => {
116
+ return await this._getJson(`${BASE_PATH}/package/getMapInfo.cgi`, undefined, options);
117
+ };
118
+ getZones = async (options) => {
119
+ return await this._getJson(`${BASE_PATH}/package/getZones.cgi`, undefined, options);
120
+ };
121
+ setZones = async (zonesJsonString, options) => {
122
+ return await this._postJsonEncoded(`${BASE_PATH}/package/setZones.cgi`, zonesJsonString, this.apiUser, options);
123
+ };
124
+ goToCoordinates = async (lat, lon, alt, options) => {
125
+ const agent = this.getClient(options?.proxyParams);
126
+ return await agent.get({
127
+ path: `${BASE_PATH}/package/goToCoordinates.cgi`,
128
+ parameters: { lat, lon, alt, ...this.apiUser },
129
+ timeout: options?.timeout,
130
+ });
131
+ };
132
+ checkGenetecConnection = async (params, options) => {
133
+ return await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
134
+ };
135
+ getGenetecCameraList = async (params, options) => {
136
+ const res = await this._postUrlEncoded(`${BASE_PATH}/package/getGenetecCameraList.cgi`, params, options);
137
+ return await res.json();
138
+ };
139
+ async _getJson(path, parameters, options) {
140
+ const agent = this.getClient(options?.proxyParams);
141
+ const res = await agent.get({
142
+ path,
143
+ parameters,
144
+ timeout: options?.timeout,
145
+ });
146
+ if (res.ok) {
147
+ return await res.json();
148
+ }
149
+ else {
150
+ throw new Error(await responseStringify(res));
151
+ }
152
+ }
153
+ async _getBlob(path, parameters, options) {
154
+ const agent = this.getClient(options?.proxyParams);
155
+ const res = await agent.get({
156
+ path,
157
+ parameters,
158
+ timeout: options?.timeout,
159
+ });
160
+ if (res.ok) {
161
+ return await this.parseBlobResponse(res);
162
+ }
163
+ else {
164
+ throw new Error(await responseStringify(res));
165
+ }
166
+ }
167
+ async parseBlobResponse(response) {
168
+ try {
169
+ return (await response.blob());
170
+ }
171
+ catch (err) {
172
+ throw new ParsingBlobError(err);
173
+ }
174
+ }
175
+ async _postJsonEncoded(path, data, parameters, options) {
176
+ const agent = this.getClient(options?.proxyParams);
177
+ const res = await agent.post({
178
+ path,
179
+ data,
180
+ parameters,
181
+ headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
182
+ timeout: options?.timeout,
183
+ });
184
+ if (res.ok) {
185
+ return res;
186
+ }
187
+ else {
188
+ throw new Error(await responseStringify(res));
189
+ }
190
+ }
191
+ async _postUrlEncoded(path, params, options) {
192
+ const data = paramToUrl(params);
193
+ const agent = this.getClient(options?.proxyParams);
194
+ const res = await agent.post({
195
+ path,
196
+ data,
197
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
198
+ timeout: options?.timeout,
199
+ });
200
+ if (res.ok) {
201
+ return res;
202
+ }
203
+ else {
204
+ throw new Error(await responseStringify(res));
205
+ }
206
+ }
207
+ }