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,123 +1,131 @@
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
+ async generateSilence(sampleRate, channels, options) {
24
+ const agent = this.getAgent(options?.proxyParams);
25
+ await agent.get({
26
+ path: `${BASE_PATH}/generate_silence.cgi`,
27
+ parameters: {
28
+ sample_rate: sampleRate.toString(),
29
+ channels,
30
+ },
31
+ timeout: options?.timeout,
25
32
  });
26
33
  }
27
- async checkCameraTime() {
28
- const data = await this.get(`${baseUrl}/camera_time.cgi`);
34
+ async checkCameraTime(options) {
35
+ const data = await this.get(`${BASE_PATH}/camera_time.cgi`, undefined, options);
29
36
  return z.boolean().parse(data);
30
37
  }
31
- async getIpListFromNetworkCheck() {
32
- const data = await this.get(`${baseUrl}/network_camera_list.cgi`);
38
+ async getNetworkCameraList(options) {
39
+ const data = await this.get(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
33
40
  return networkCameraListSchema.parse(data);
34
41
  }
35
- async getMaxFps(source) {
36
- const data = await this.get(`${baseUrl}/get_max_framerate.cgi`, {
42
+ async getMaxFps(source, options) {
43
+ const data = await this.get(`${BASE_PATH}/get_max_framerate.cgi`, {
37
44
  video_source: source.toString(),
38
- });
45
+ }, options);
39
46
  return z.number().parse(data);
40
47
  }
41
- async getStorageInfo() {
42
- const data = await this.get(`${baseUrl}/get_storage.cgi`);
48
+ async getStorageInfo(options) {
49
+ const data = await this.get(`${BASE_PATH}/get_storage.cgi`, undefined, options);
43
50
  return storageInfoListSchema.parse(data);
44
51
  }
45
- async wsAuthorization() {
46
- const data = await this.get(`${baseUrl}/ws_authorization.cgi`);
52
+ async wsAuthorization(options) {
53
+ const data = await this.get(`${BASE_PATH}/ws_authorization.cgi`, undefined, options);
47
54
  return z.string().parse(data);
48
55
  }
49
- async getOutputInfo() {
50
- const data = await this.get(`${baseUrl}/output_info.cgi`);
56
+ async getOutputInfo(options) {
57
+ const data = await this.get(`${BASE_PATH}/output_info.cgi`, undefined, options);
51
58
  return outputInfoSchema.parse(data);
52
59
  }
53
- async getAudioPushInfo() {
54
- const data = await this.get(`${baseUrl}/audio_push_info.cgi`);
60
+ async getAudioPushInfo(options) {
61
+ const data = await this.get(`${BASE_PATH}/audio_push_info.cgi`, undefined, options);
55
62
  return audioPushInfoSchema.parse(data);
56
63
  }
57
- async getStreamSaveList() {
58
- const data = await this.get(`${baseUrl}/streams.cgi`, { action: 'get' });
64
+ async getStreamSaveList(options) {
65
+ const data = await this.get(`${BASE_PATH}/streams.cgi`, { action: 'get' }, options);
59
66
  return streamSaveLoadSchema.parse(data);
60
67
  }
61
- async getClipSaveList() {
62
- const data = await this.get(`${baseUrl}/clips.cgi`, { action: 'get' });
68
+ async getClipSaveList(options) {
69
+ const data = await this.get(`${BASE_PATH}/clips.cgi`, { action: 'get' }, options);
63
70
  return clipSaveLoadSchema.parse(data);
64
71
  }
65
- async getPlaylistSaveList() {
66
- const data = await this.get(`${baseUrl}/playlists.cgi`, { action: 'get' });
72
+ async getPlaylistSaveList(options) {
73
+ const data = await this.get(`${BASE_PATH}/playlists.cgi`, { action: 'get' }, options);
67
74
  return playlistSaveLoadSchema.parse(data);
68
75
  }
69
- async getTrackerSaveList() {
70
- const data = await this.get(`${baseUrl}/trackers.cgi`, { action: 'get' });
76
+ async getTrackerSaveList(options) {
77
+ const data = await this.get(`${BASE_PATH}/trackers.cgi`, { action: 'get' }, options);
71
78
  return trackerSaveLoadSchema.parse(data);
72
79
  }
73
- async setStreamSaveList(data) {
74
- return await this.set(`${baseUrl}/streams.cgi`, data, { action: 'set' });
80
+ async setStreamSaveList(data, options) {
81
+ return await this.set(`${BASE_PATH}/streams.cgi`, data, { action: 'set' }, options);
75
82
  }
76
- async setClipSaveList(data) {
77
- return await this.set(`${baseUrl}/clips.cgi`, data, { action: 'set' });
83
+ async setClipSaveList(data, options) {
84
+ return await this.set(`${BASE_PATH}/clips.cgi`, data, { action: 'set' }, options);
78
85
  }
79
- async setPlaylistSaveList(data) {
80
- return await this.set(`${baseUrl}/playlists.cgi`, data, { action: 'set' });
86
+ async setPlaylistSaveList(data, options) {
87
+ return await this.set(`${BASE_PATH}/playlists.cgi`, data, { action: 'set' }, options);
81
88
  }
82
- async setTrackerSaveList(data) {
83
- return await this.set(`${baseUrl}/trackers.cgi`, data, { action: 'set' });
89
+ async setTrackerSaveList(data, options) {
90
+ return await this.set(`${BASE_PATH}/trackers.cgi`, data, { action: 'set' }, options);
84
91
  }
85
- async playlistSwitch(playlistName) {
86
- await this.get(`${baseUrl}/playlist_switch.cgi?playlist_name=${playlistName}`);
92
+ async playlistSwitch(playlistName, options) {
93
+ await this.get(`${BASE_PATH}/playlist_switch.cgi`, { playlist_name: playlistName }, options);
87
94
  }
88
- async playlistQueuePush(playlistName) {
89
- await this.get(`${baseUrl}/playlist_queue_push.cgi?playlist_name=${playlistName}`);
95
+ async playlistQueuePush(playlistName, options) {
96
+ await this.get(`${BASE_PATH}/playlist_queue_push.cgi`, { playlist_name: playlistName }, options);
90
97
  }
91
- async playlistQueueClear() {
92
- await this.get(`${baseUrl}/playlist_queue_clear.cgi`);
98
+ async playlistQueueClear(options) {
99
+ await this.get(`${BASE_PATH}/playlist_queue_clear.cgi`, undefined, options);
93
100
  }
94
- async playlistQueueList() {
95
- const data = await this.get(`${baseUrl}/playlist_queue_list.cgi`);
101
+ async playlistQueueList(options) {
102
+ const data = await this.get(`${BASE_PATH}/playlist_queue_list.cgi`, undefined, options);
96
103
  return playlistQueueSchema.parse(data).playlistQueueList;
97
104
  }
98
- async playlistQueuePlayNext() {
99
- await this.get(`${baseUrl}/playlist_queue_play_next.cgi`);
105
+ async playlistQueuePlayNext(options) {
106
+ await this.get(`${BASE_PATH}/playlist_queue_play_next.cgi`, undefined, options);
100
107
  }
101
- async addNewClip(file, clipType, storage, id, fileName) {
102
- const formData = new FormData();
108
+ async addNewClip(file, clipType, storage, id, fileName, options) {
109
+ const path = `${BASE_PATH}/clip_upload.cgi?storage=${storage}`;
110
+ const formData = new this.CustomFormData();
103
111
  formData.append('clip_name', id);
104
112
  formData.append('clip_type', clipType);
105
113
  formData.append('file', file, fileName);
106
- const path = `${baseUrl}/clip_upload.cgi?storage=${storage}`;
107
- const res = await this.client.post(path, formData);
114
+ const agent = this.getAgent(options?.proxyParams);
115
+ const res = await agent.post({ path, data: formData, timeout: options?.timeout });
108
116
  const output = (await res.json());
109
117
  if (output.status !== 200) {
110
118
  throw new AddNewClipError(output.message);
111
119
  }
112
120
  }
113
- removeClip(id, storage) {
114
- return this.get(`${baseUrl}/clip_remove.cgi`, { clip_name: id, storage });
121
+ removeClip(id, storage, options) {
122
+ return this.get(`${BASE_PATH}/clip_remove.cgi`, { clip_name: id, storage }, options);
115
123
  }
116
- async getClipList() {
117
- const data = await this.get(`${baseUrl}/clip_list.cgi`);
124
+ async getClipList(options) {
125
+ const data = await this.get(`${BASE_PATH}/clip_list.cgi`, undefined, options);
118
126
  return clipListSchema.parse(data).clip_list;
119
127
  }
120
- setCamSwitchOptions(data, cameraFWVersion) {
128
+ setCamSwitchOptions(data, cameraFWVersion, options) {
121
129
  const bitrateVapixParams = parseBitrateOptionsToBitrateVapixParams(cameraFWVersion, data.bitrateMode, data);
122
130
  const saveData = {
123
131
  video: {
@@ -135,9 +143,9 @@ export class CamSwitcherAPI {
135
143
  },
136
144
  keyboard: data.keyboard,
137
145
  };
138
- return this.setParamFromCameraJSON(CSW_PARAM_NAMES.SETTINGS, saveData);
146
+ return this.setParamFromCameraJSON(CSW_PARAM_NAMES.SETTINGS, saveData, options);
139
147
  }
140
- setGlobalAudioSettings(settings) {
148
+ setGlobalAudioSettings(settings, options) {
141
149
  let acceptedType = 'NONE';
142
150
  if (settings.type === 'source' && settings.source) {
143
151
  if (isClip(settings.source)) {
@@ -153,9 +161,9 @@ export class CamSwitcherAPI {
153
161
  clip_name: settings.source,
154
162
  storage: settings.storage,
155
163
  };
156
- return this.setParamFromCameraJSON(CSW_PARAM_NAMES.MASTER_AUDIO, data);
164
+ return this.setParamFromCameraJSON(CSW_PARAM_NAMES.MASTER_AUDIO, data, options);
157
165
  }
158
- setSecondaryAudioSettings(settings) {
166
+ setSecondaryAudioSettings(settings, options) {
159
167
  const data = {
160
168
  type: settings.type,
161
169
  stream_name: settings.streamName ?? '',
@@ -164,19 +172,19 @@ export class CamSwitcherAPI {
164
172
  secondary_audio_level: settings.secondaryAudioLevel,
165
173
  master_audio_level: settings.masterAudioLevel,
166
174
  };
167
- return this.setParamFromCameraJSON(CSW_PARAM_NAMES.SECONDARY_AUDIO, data);
175
+ return this.setParamFromCameraJSON(CSW_PARAM_NAMES.SECONDARY_AUDIO, data, options);
168
176
  }
169
- setDefaultPlaylist(id) {
177
+ setDefaultPlaylist(id, options) {
170
178
  const value = JSON.stringify({ default_playlist_id: id });
171
179
  return this.vapixAgent.setParameter({
172
180
  [CSW_PARAM_NAMES.DEFAULT_PLAYLIST]: value,
173
- }, null);
181
+ }, options);
174
182
  }
175
- setPermanentRtspUrlToken(token) {
176
- return this.vapixAgent.setParameter({ [CSW_PARAM_NAMES.RTSP_TOKEN]: token }, null);
183
+ setPermanentRtspUrlToken(token, options) {
184
+ return this.vapixAgent.setParameter({ [CSW_PARAM_NAMES.RTSP_TOKEN]: token }, options);
177
185
  }
178
- async getCamSwitchOptions() {
179
- const saveData = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SETTINGS);
186
+ async getCamSwitchOptions(options) {
187
+ const saveData = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SETTINGS, options);
180
188
  if (isNullish(saveData.video)) {
181
189
  return saveData;
182
190
  }
@@ -201,12 +209,12 @@ export class CamSwitcherAPI {
201
209
  keyboard: saveData.keyboard,
202
210
  };
203
211
  }
204
- async getGlobalAudioSettings() {
212
+ async getGlobalAudioSettings(options) {
205
213
  const settings = {
206
214
  type: 'fromSource',
207
215
  source: 'fromSource',
208
216
  };
209
- const res = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.MASTER_AUDIO);
217
+ const res = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.MASTER_AUDIO, options);
210
218
  if (res.type === 'STREAM') {
211
219
  settings.type = 'source';
212
220
  settings.source = res.stream_name;
@@ -218,8 +226,8 @@ export class CamSwitcherAPI {
218
226
  }
219
227
  return settings;
220
228
  }
221
- async getSecondaryAudioSettings() {
222
- const res = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SECONDARY_AUDIO);
229
+ async getSecondaryAudioSettings(options) {
230
+ const res = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SECONDARY_AUDIO, options);
223
231
  const settings = {
224
232
  type: res.type ?? 'NONE',
225
233
  streamName: res.stream_name,
@@ -230,13 +238,14 @@ export class CamSwitcherAPI {
230
238
  };
231
239
  return settings;
232
240
  }
233
- async getPermanentRtspUrlToken() {
241
+ async getPermanentRtspUrlToken(options) {
234
242
  const paramName = CSW_PARAM_NAMES.RTSP_TOKEN;
235
- const res = await this.vapixAgent.getParameter([paramName], null);
243
+ const res = await this.vapixAgent.getParameter([paramName], options);
236
244
  return res[paramName] ?? '';
237
245
  }
238
- async get(path, parameters = {}) {
239
- const res = await this.client.get(path, parameters);
246
+ async get(path, parameters, options) {
247
+ const agent = this.getAgent(options?.proxyParams);
248
+ const res = await agent.get({ path, parameters, timeout: options?.timeout });
240
249
  if (res.ok) {
241
250
  const d = (await res.json());
242
251
  return d.data;
@@ -245,8 +254,9 @@ export class CamSwitcherAPI {
245
254
  throw new Error(await responseStringify(res));
246
255
  }
247
256
  }
248
- async set(path, data, parameters = {}) {
249
- const res = await this.client.post(path, JSON.stringify(data), parameters);
257
+ async set(path, data, parameters, options) {
258
+ const agent = this.getAgent(options?.proxyParams);
259
+ const res = await agent.post({ path, data: JSON.stringify(data), parameters, timeout: options?.timeout });
250
260
  if (res.ok) {
251
261
  const parsed = await res.json();
252
262
  return parsed.message === 'OK';
@@ -255,13 +265,13 @@ export class CamSwitcherAPI {
255
265
  throw new Error(await responseStringify(res));
256
266
  }
257
267
  }
258
- setParamFromCameraJSON(paramName, data) {
268
+ setParamFromCameraJSON(paramName, data, options) {
259
269
  const params = {};
260
270
  params[paramName] = JSON.stringify(data);
261
- return this.vapixAgent.setParameter(params, null);
271
+ return this.vapixAgent.setParameter(params, options);
262
272
  }
263
- async getParamFromCameraAndJSONParse(paramName) {
264
- const data = await this.vapixAgent.getParameter([paramName], null);
273
+ async getParamFromCameraAndJSONParse(paramName, options) {
274
+ const data = await this.vapixAgent.getParameter([paramName], options);
265
275
  if (data[paramName] !== undefined) {
266
276
  try {
267
277
  if (data[paramName] === '') {
@@ -277,6 +287,9 @@ export class CamSwitcherAPI {
277
287
  }
278
288
  throw new Error("Error: no parametr '" + paramName + "' was found");
279
289
  }
290
+ getAgent(proxyParams) {
291
+ return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
292
+ }
280
293
  }
281
294
  const CSW_PARAM_NAMES = {
282
295
  SETTINGS: 'Camswitcher.Settings',
@@ -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,42 @@
1
+ import { IClient, TBlobResponse, TParameters, TResponse } from './internal/types';
2
+ import { ICAO, TApiUser, TExportDataType, TImportDataType } from './types/PlaneTrackerAPI';
3
+ import { THttpRequestOptions } from './types/common';
4
+ export declare class PlaneTrackerAPI<Client extends IClient<TResponse> = IClient<TResponse>> {
5
+ private client;
6
+ private apiUser;
7
+ constructor(client: Client, apiUser: TApiUser);
8
+ static getProxyUrlPath: () => string;
9
+ checkCameraTime(options?: THttpRequestOptions): Promise<boolean>;
10
+ resetPtzCalibration: (options?: THttpRequestOptions) => Promise<TResponse>;
11
+ resetFocusCalibration: (options?: THttpRequestOptions) => Promise<TResponse>;
12
+ serverRunCheck: (options?: THttpRequestOptions) => Promise<TResponse>;
13
+ getLiveViewAlias: (rtspUrl: string, options?: THttpRequestOptions) => Promise<TResponse>;
14
+ fetchCameraSettings: (options?: THttpRequestOptions) => Promise<any>;
15
+ setCameraSettings: (settingsJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
16
+ fetchServerSettings: (options?: THttpRequestOptions) => Promise<any>;
17
+ exportAppSettings: (dataType: TExportDataType, options?: THttpRequestOptions) => Promise<TBlobResponse<Client>>;
18
+ importAppSettings: (dataType: TImportDataType, formData: FormData, options?: THttpRequestOptions) => Promise<TResponse>;
19
+ fetchFlightInfo: (icao: ICAO, options?: THttpRequestOptions) => Promise<any>;
20
+ getTrackingMode: (options?: THttpRequestOptions) => Promise<any>;
21
+ setTrackingMode: (modeJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
22
+ startTrackingPlane: (icao: ICAO, options?: THttpRequestOptions) => Promise<TResponse>;
23
+ stopTrackingPlane: (options?: THttpRequestOptions) => Promise<TResponse>;
24
+ getPriorityList: (options?: THttpRequestOptions) => Promise<any>;
25
+ setPriorityList: (priorityListJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
26
+ getWhiteList: (options?: THttpRequestOptions) => Promise<any>;
27
+ setWhiteList: (whiteListJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
28
+ getBlackList: (options?: THttpRequestOptions) => Promise<any>;
29
+ setBlackList: (blackListJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
30
+ fetchMapInfo: (options?: THttpRequestOptions) => Promise<any>;
31
+ getZones: (options?: THttpRequestOptions) => Promise<any>;
32
+ setZones: (zonesJsonString: string, options?: THttpRequestOptions) => Promise<TResponse>;
33
+ goToCoordinates: (lat: number, lon: number, alt?: number, options?: THttpRequestOptions) => Promise<TResponse>;
34
+ checkGenetecConnection: (params: TParameters, options?: THttpRequestOptions) => Promise<TResponse>;
35
+ getGenetecCameraList: (params: TParameters, options?: THttpRequestOptions) => Promise<any>;
36
+ private _getJson;
37
+ private _getBlob;
38
+ private parseBlobResponse;
39
+ private _postJsonEncoded;
40
+ private _postUrlEncoded;
41
+ private getAgent;
42
+ }
@@ -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
+ async checkCameraTime(options) {
15
+ const response = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
16
+ return z.boolean().parse(response.state);
17
+ }
18
+ resetPtzCalibration = async (options) => {
19
+ const agent = this.getAgent(options?.proxyParams);
20
+ return await agent.get({
21
+ path: `${BASE_PATH}/package/resetPtzCalibration.cgi`,
22
+ parameters: this.apiUser,
23
+ timeout: options?.timeout,
24
+ });
25
+ };
26
+ resetFocusCalibration = async (options) => {
27
+ const agent = this.getAgent(options?.proxyParams);
28
+ return await agent.get({
29
+ path: `${BASE_PATH}/package/resetFocusCalibration.cgi`,
30
+ parameters: this.apiUser,
31
+ timeout: options?.timeout,
32
+ });
33
+ };
34
+ serverRunCheck = async (options) => {
35
+ const agent = this.getAgent(options?.proxyParams);
36
+ return await agent.get({ path: `${BASE_PATH}/package/serverRunCheck.cgi`, timeout: options?.timeout });
37
+ };
38
+ getLiveViewAlias = async (rtspUrl, options) => {
39
+ const agent = this.getAgent(options?.proxyParams);
40
+ return await agent.get({
41
+ path: `${BASE_PATH}/getLiveViewAlias.cgi`,
42
+ parameters: { rtsp_url: rtspUrl },
43
+ timeout: options?.timeout,
44
+ });
45
+ };
46
+ fetchCameraSettings = async (options) => {
47
+ return await this._getJson(`${BASE_PATH}/package_camera_settings.cgi`, { action: 'get' }, options);
48
+ };
49
+ setCameraSettings = async (settingsJsonString, options) => {
50
+ return await this._postJsonEncoded(`${BASE_PATH}/package_camera_settings.cgi`, settingsJsonString, {
51
+ action: 'set',
52
+ }, options);
53
+ };
54
+ fetchServerSettings = async (options) => {
55
+ return await this._getJson(`${BASE_PATH}/package_server_settings.cgi`, { action: 'get' }, options);
56
+ };
57
+ exportAppSettings = async (dataType, options) => {
58
+ return await this._getBlob(`${BASE_PATH}/package_data.cgi`, { action: 'EXPORT', dataType }, options);
59
+ };
60
+ importAppSettings = async (dataType, formData, options) => {
61
+ const agent = this.getAgent(options?.proxyParams);
62
+ return await agent.post({
63
+ path: `${BASE_PATH}/package_data.cgi`,
64
+ data: formData,
65
+ parameters: { action: 'IMPORT', dataType },
66
+ timeout: options?.timeout,
67
+ });
68
+ };
69
+ fetchFlightInfo = async (icao, options) => {
70
+ return await this._getJson(`${BASE_PATH}/package/flightInfo.cgi`, { icao: encodeURIComponent(icao) }, options);
71
+ };
72
+ getTrackingMode = async (options) => {
73
+ return await this._getJson(`${BASE_PATH}/package/getTrackingMode.cgi`, undefined, options);
74
+ };
75
+ setTrackingMode = async (modeJsonString, options) => {
76
+ return await this._postJsonEncoded(`${BASE_PATH}/package/setTrackingMode.cgi`, modeJsonString, this.apiUser, options);
77
+ };
78
+ startTrackingPlane = async (icao, options) => {
79
+ const agent = this.getAgent(options?.proxyParams);
80
+ return await agent.get({
81
+ path: `${BASE_PATH}/package/trackIcao.cgi`,
82
+ parameters: { icao, ...this.apiUser },
83
+ timeout: options?.timeout,
84
+ });
85
+ };
86
+ stopTrackingPlane = async (options) => {
87
+ const agent = this.getAgent(options?.proxyParams);
88
+ return await agent.get({
89
+ path: `${BASE_PATH}/package/resetIcao.cgi`,
90
+ parameters: this.apiUser,
91
+ timeout: options?.timeout,
92
+ });
93
+ };
94
+ getPriorityList = async (options) => {
95
+ return await this._getJson(`${BASE_PATH}/package/getPriorityList.cgi`, undefined, options);
96
+ };
97
+ setPriorityList = async (priorityListJsonString, options) => {
98
+ return await this._postJsonEncoded(`${BASE_PATH}/package/setPriorityList.cgi`, priorityListJsonString, this.apiUser, options);
99
+ };
100
+ getWhiteList = async (options) => {
101
+ return await this._getJson(`${BASE_PATH}/package/getWhiteList.cgi`, undefined, options);
102
+ };
103
+ setWhiteList = async (whiteListJsonString, options) => {
104
+ return await this._postJsonEncoded(`${BASE_PATH}/package/setWhiteList.cgi`, whiteListJsonString, this.apiUser, options);
105
+ };
106
+ getBlackList = async (options) => {
107
+ return await this._getJson(`${BASE_PATH}/package/getBlackList.cgi`, undefined, options);
108
+ };
109
+ setBlackList = async (blackListJsonString, options) => {
110
+ return await this._postJsonEncoded(`${BASE_PATH}/package/setBlackList.cgi`, blackListJsonString, this.apiUser, options);
111
+ };
112
+ fetchMapInfo = async (options) => {
113
+ return await this._getJson(`${BASE_PATH}/package/getMapInfo.cgi`, undefined, options);
114
+ };
115
+ getZones = async (options) => {
116
+ return await this._getJson(`${BASE_PATH}/package/getZones.cgi`, undefined, options);
117
+ };
118
+ setZones = async (zonesJsonString, options) => {
119
+ return await this._postJsonEncoded(`${BASE_PATH}/package/setZones.cgi`, zonesJsonString, this.apiUser, options);
120
+ };
121
+ goToCoordinates = async (lat, lon, alt, options) => {
122
+ const agent = this.getAgent(options?.proxyParams);
123
+ return await agent.get({
124
+ path: `${BASE_PATH}/package/goToCoordinates.cgi`,
125
+ parameters: { lat, lon, alt, ...this.apiUser },
126
+ timeout: options?.timeout,
127
+ });
128
+ };
129
+ checkGenetecConnection = async (params, options) => {
130
+ return await this._postUrlEncoded(`${BASE_PATH}/package/checkGenetecConnection.cgi`, params, options);
131
+ };
132
+ getGenetecCameraList = async (params, options) => {
133
+ const res = await this._postUrlEncoded(`${BASE_PATH}/package/getGenetecCameraList.cgi`, params, options);
134
+ return await res.json();
135
+ };
136
+ async _getJson(path, parameters, options) {
137
+ const agent = this.getAgent(options?.proxyParams);
138
+ const res = await agent.get({
139
+ path,
140
+ parameters,
141
+ timeout: options?.timeout,
142
+ });
143
+ if (res.ok) {
144
+ return await res.json();
145
+ }
146
+ else {
147
+ throw new Error(await responseStringify(res));
148
+ }
149
+ }
150
+ async _getBlob(path, parameters, options) {
151
+ const agent = this.getAgent(options?.proxyParams);
152
+ const res = await agent.get({
153
+ path,
154
+ parameters,
155
+ timeout: options?.timeout,
156
+ });
157
+ if (res.ok) {
158
+ return await this.parseBlobResponse(res);
159
+ }
160
+ else {
161
+ throw new Error(await responseStringify(res));
162
+ }
163
+ }
164
+ async parseBlobResponse(response) {
165
+ try {
166
+ return (await response.blob());
167
+ }
168
+ catch (err) {
169
+ throw new ParsingBlobError(err);
170
+ }
171
+ }
172
+ async _postJsonEncoded(path, data, parameters, options) {
173
+ const agent = this.getAgent(options?.proxyParams);
174
+ const res = await agent.post({
175
+ path,
176
+ data,
177
+ parameters,
178
+ headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
179
+ timeout: options?.timeout,
180
+ });
181
+ if (res.ok) {
182
+ return res;
183
+ }
184
+ else {
185
+ throw new Error(await responseStringify(res));
186
+ }
187
+ }
188
+ async _postUrlEncoded(path, params, options) {
189
+ const data = paramToUrl(params);
190
+ const agent = this.getAgent(options?.proxyParams);
191
+ const res = await agent.post({
192
+ path,
193
+ data,
194
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
195
+ timeout: options?.timeout,
196
+ });
197
+ if (res.ok) {
198
+ return res;
199
+ }
200
+ else {
201
+ throw new Error(await responseStringify(res));
202
+ }
203
+ }
204
+ getAgent(proxyParams) {
205
+ return proxyParams ? new ProxyClient(this.client, proxyParams) : this.client;
206
+ }
207
+ }