camstreamerlib 4.0.30-fd4e027 → 4.0.31-2493e55

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 (60) hide show
  1. package/README.md +1 -1
  2. package/cjs/CamSwitcherAPI.d.ts +18 -1
  3. package/cjs/CamSwitcherAPI.js +30 -26
  4. package/cjs/errors/errors.d.ts +3 -0
  5. package/cjs/errors/errors.js +8 -1
  6. package/cjs/internal/types.d.ts +2 -0
  7. package/cjs/node/CamOverlayDrawingAPI.d.ts +2 -1
  8. package/cjs/node/CamOverlayDrawingAPI.js +6 -3
  9. package/cjs/node/CamScripterAPICameraEventsGenerator.d.ts +2 -1
  10. package/cjs/node/CamScripterAPICameraEventsGenerator.js +6 -3
  11. package/cjs/node/DefaultClient.d.ts +4 -3
  12. package/cjs/node/DefaultClient.js +8 -6
  13. package/cjs/node/DeviceConnectClient.d.ts +9 -0
  14. package/cjs/node/DeviceConnectClient.js +15 -0
  15. package/cjs/node/DeviceConnectWsClient.d.ts +12 -0
  16. package/cjs/node/DeviceConnectWsClient.js +21 -0
  17. package/cjs/node/VapixEvents.d.ts +2 -1
  18. package/cjs/node/VapixEvents.js +6 -3
  19. package/cjs/node/WsClient.d.ts +7 -2
  20. package/cjs/node/WsClient.js +3 -3
  21. package/cjs/node/index.d.ts +2 -0
  22. package/cjs/node/index.js +4 -1
  23. package/cjs/web/DefaultClient.d.ts +2 -1
  24. package/cjs/web/DefaultClient.js +5 -3
  25. package/cjs/web/DeviceConnectClient.d.ts +4 -0
  26. package/cjs/web/DeviceConnectClient.js +10 -0
  27. package/cjs/web/DeviceConnectWsClient.d.ts +4 -0
  28. package/cjs/web/DeviceConnectWsClient.js +14 -0
  29. package/cjs/web/index.d.ts +2 -0
  30. package/cjs/web/index.js +5 -1
  31. package/esm/CamSwitcherAPI.js +32 -28
  32. package/esm/errors/errors.js +6 -0
  33. package/esm/node/CamOverlayDrawingAPI.js +6 -3
  34. package/esm/node/CamScripterAPICameraEventsGenerator.js +6 -3
  35. package/esm/node/DefaultClient.js +8 -6
  36. package/esm/node/DeviceConnectClient.js +11 -0
  37. package/esm/node/DeviceConnectWsClient.js +17 -0
  38. package/esm/node/VapixEvents.js +6 -3
  39. package/esm/node/WsClient.js +3 -3
  40. package/esm/node/index.js +2 -0
  41. package/esm/web/DefaultClient.js +5 -3
  42. package/esm/web/DeviceConnectClient.js +6 -0
  43. package/esm/web/DeviceConnectWsClient.js +10 -0
  44. package/esm/web/index.js +2 -0
  45. package/package.json +1 -1
  46. package/types/CamSwitcherAPI.d.ts +18 -1
  47. package/types/errors/errors.d.ts +3 -0
  48. package/types/internal/types.d.ts +2 -0
  49. package/types/node/CamOverlayDrawingAPI.d.ts +2 -1
  50. package/types/node/CamScripterAPICameraEventsGenerator.d.ts +2 -1
  51. package/types/node/DefaultClient.d.ts +4 -3
  52. package/types/node/DeviceConnectClient.d.ts +9 -0
  53. package/types/node/DeviceConnectWsClient.d.ts +12 -0
  54. package/types/node/VapixEvents.d.ts +2 -1
  55. package/types/node/WsClient.d.ts +7 -2
  56. package/types/node/index.d.ts +2 -0
  57. package/types/web/DefaultClient.d.ts +2 -1
  58. package/types/web/DeviceConnectClient.d.ts +4 -0
  59. package/types/web/DeviceConnectWsClient.d.ts +4 -0
  60. package/types/web/index.d.ts +2 -0
package/README.md CHANGED
@@ -83,7 +83,7 @@ const coApi = new CamOverlayAPI(
83
83
  new DefaultClient({
84
84
  tls: false,
85
85
  tlsInsecure: false,
86
- ip: '127.0.0.1',
86
+ host: '127.0.0.1',
87
87
  port: 80,
88
88
  user: '',
89
89
  pass: '',
@@ -144,7 +144,24 @@ export declare class CamSwitcherAPI<Client extends IClient<TResponse, any>> exte
144
144
  setSecondaryAudioSettings(settings: TSecondaryAudioSettings, options?: THttpRequestOptions): Promise<void>;
145
145
  setDefaultPlaylist(playlistId: string, options?: THttpRequestOptions): Promise<void>;
146
146
  setPermanentRtspUrlToken(token: string, options?: THttpRequestOptions): Promise<void>;
147
- getCamSwitchOptions(options?: THttpRequestOptions): Promise<any>;
147
+ getCamSwitchOptions(options?: THttpRequestOptions): Promise<{
148
+ resolution?: string | undefined;
149
+ compression?: number | undefined;
150
+ bitrateMode?: "VBR" | "MBR" | "ABR" | undefined;
151
+ maximumBitRate?: number | undefined;
152
+ retentionTime?: number | undefined;
153
+ bitRateLimit?: number | undefined;
154
+ fps?: number | undefined;
155
+ govLength?: number | undefined;
156
+ h264Profile?: "high" | "main" | "baseline" | undefined;
157
+ keyboard?: {
158
+ none: string | null;
159
+ fromSource: string | null;
160
+ } | undefined;
161
+ bitrateVapixParams?: string | null | undefined;
162
+ audioSampleRate?: number | undefined;
163
+ audioChannelCount?: 1 | 2 | undefined;
164
+ } | undefined>;
148
165
  getGlobalAudioSettings(options?: THttpRequestOptions): Promise<{
149
166
  type: "source" | "fromSource";
150
167
  source: string;
@@ -34,15 +34,13 @@ class CamSwitcherAPI extends BasicAPI_1.BasicAPI {
34
34
  return common_1.networkCameraListSchema.parse(res.data);
35
35
  }
36
36
  async generateSilence(sampleRate, channels, options) {
37
- const agent = this.getClient(options?.proxyParams);
38
- await agent.get({
39
- path: `${BASE_PATH}/generate_silence.cgi`,
40
- parameters: {
41
- sample_rate: sampleRate.toString(),
42
- channels,
43
- },
44
- timeout: options?.timeout,
45
- });
37
+ const res = await this._getJson(`${BASE_PATH}/generate_silence.cgi`, {
38
+ sample_rate: sampleRate.toString(),
39
+ channels,
40
+ }, options);
41
+ if (res.status !== 200) {
42
+ throw new errors_1.GenerateSilenceError(res.message);
43
+ }
46
44
  }
47
45
  async getMaxFps(source, options) {
48
46
  const res = await this._getJson(`${BASE_PATH}/get_max_framerate.cgi`, {
@@ -204,28 +202,34 @@ class CamSwitcherAPI extends BasicAPI_1.BasicAPI {
204
202
  async getCamSwitchOptions(options) {
205
203
  const saveData = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SETTINGS, options);
206
204
  if ((0, utils_1.isNullish)(saveData.video)) {
207
- return saveData;
205
+ return;
208
206
  }
209
- if (!(0, utils_1.isNullish)(saveData.video?.bitrateVapixParams)) {
207
+ const settings = {
208
+ audioSampleRate: saveData.audio?.sampleRate,
209
+ audioChannelCount: saveData.audio?.channelCount,
210
+ keyboard: saveData.keyboard,
211
+ fps: saveData.video.fps,
212
+ resolution: saveData.video.resolution,
213
+ h264Profile: saveData.video.h264Profile,
214
+ compression: saveData.video.compression,
215
+ govLength: saveData.video.govLength,
216
+ bitrateVapixParams: saveData.video.bitrateVapixParams,
217
+ };
218
+ if (!(0, utils_1.isNullish)(saveData.video.bitrateVapixParams)) {
210
219
  const bitrateOptions = (0, convertors_1.parseVapixParamsToBitrateOptions)(saveData.video.bitrateVapixParams);
211
- saveData.video.bitrateMode = bitrateOptions.bitrateMode;
212
- saveData.video.maximumBitRate = bitrateOptions.maximumBitRate;
213
- saveData.video.retentionTime = bitrateOptions.retentionTime;
214
- saveData.video.bitRateLimit = bitrateOptions.bitRateLimit;
220
+ settings.bitrateMode = bitrateOptions.bitrateMode;
221
+ settings.maximumBitRate = bitrateOptions.maximumBitRate;
222
+ settings.retentionTime = bitrateOptions.retentionTime;
223
+ settings.bitRateLimit = bitrateOptions.bitRateLimit;
215
224
  }
216
- if (!(0, utils_1.isNullish)(saveData.video?.bitrateLimit)) {
217
- saveData.video.maximumBitRate = saveData.video.bitrateLimit;
218
- saveData.video.bitrateMode = 'MBR';
225
+ if (!(0, utils_1.isNullish)(saveData.video.bitrateLimit)) {
226
+ settings.maximumBitRate = saveData.video.bitrateLimit;
227
+ settings.bitrateMode = 'MBR';
219
228
  }
220
- if (!(0, utils_1.isNullish)(saveData.video?.videoClipQuality)) {
221
- saveData.video.maximumBitRate = saveData.video.videoClipQuality;
229
+ if (!(0, utils_1.isNullish)(saveData.video.videoClipQuality)) {
230
+ settings.maximumBitRate = saveData.video.videoClipQuality;
222
231
  }
223
- return {
224
- ...saveData.video,
225
- audioSampleRate: saveData.audio.sampleRate,
226
- audioChannelCount: saveData.audio.channelCount,
227
- keyboard: saveData.keyboard,
228
- };
232
+ return CamSwitcherAPI_1.cameraOptionsSchema.parse(settings);
229
233
  }
230
234
  async getGlobalAudioSettings(options) {
231
235
  const settings = {
@@ -49,6 +49,9 @@ export declare class FetchDeviceInfoError extends Error {
49
49
  export declare class AddNewClipError extends Error {
50
50
  constructor(message: string);
51
51
  }
52
+ export declare class GenerateSilenceError extends Error {
53
+ constructor(message: string);
54
+ }
52
55
  export declare class PtzNotSupportedError extends Error {
53
56
  constructor();
54
57
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MigrationError = exports.BadRequestError = exports.ServerError = exports.InvalidAltitudeError = exports.InvalidLatLngError = exports.CannotSetCoordsInAutoModeError = exports.ImportSettingsError = exports.ResetCalibrationError = exports.TimezoneFetchError = exports.TimezoneNotSetupError = exports.UtcTimeFetchError = exports.WsAuthorizationError = exports.StorageDataFetchError = exports.PtzNotSupportedError = exports.AddNewClipError = exports.FetchDeviceInfoError = exports.NoDeviceInfoError = exports.MaxFPSError = exports.SDCardJobError = exports.SDCardActionError = exports.ApplicationAPIError = exports.SettingParameterError = exports.ParameterNotFoundError = exports.JsonParseError = exports.ParsingBlobError = exports.ServiceNotFoundError = exports.ServiceUnavailableError = exports.ErrorWithResponse = void 0;
3
+ exports.MigrationError = exports.BadRequestError = exports.ServerError = exports.InvalidAltitudeError = exports.InvalidLatLngError = exports.CannotSetCoordsInAutoModeError = exports.ImportSettingsError = exports.ResetCalibrationError = exports.TimezoneFetchError = exports.TimezoneNotSetupError = exports.UtcTimeFetchError = exports.WsAuthorizationError = exports.StorageDataFetchError = exports.PtzNotSupportedError = exports.GenerateSilenceError = exports.AddNewClipError = exports.FetchDeviceInfoError = exports.NoDeviceInfoError = exports.MaxFPSError = exports.SDCardJobError = exports.SDCardActionError = exports.ApplicationAPIError = exports.SettingParameterError = exports.ParameterNotFoundError = exports.JsonParseError = exports.ParsingBlobError = exports.ServiceNotFoundError = exports.ServiceUnavailableError = exports.ErrorWithResponse = void 0;
4
4
  class ErrorWithResponse extends Error {
5
5
  res;
6
6
  constructor(res) {
@@ -111,6 +111,13 @@ class AddNewClipError extends Error {
111
111
  }
112
112
  }
113
113
  exports.AddNewClipError = AddNewClipError;
114
+ class GenerateSilenceError extends Error {
115
+ constructor(message) {
116
+ super('Error generating silence clip: ' + message);
117
+ this.name = 'GenerateSilenceError';
118
+ }
119
+ }
120
+ exports.GenerateSilenceError = GenerateSilenceError;
114
121
  class PtzNotSupportedError extends Error {
115
122
  constructor() {
116
123
  super('Ptz not supported.');
@@ -1,10 +1,12 @@
1
1
  export type Options = {
2
2
  ip?: string;
3
+ host?: string;
3
4
  port?: number;
4
5
  user?: string;
5
6
  pass?: string;
6
7
  tls?: boolean;
7
8
  tlsInsecure?: boolean;
9
+ headers?: Record<string, string>;
8
10
  };
9
11
  export type HttpOptions = Options & {
10
12
  keepAlive?: boolean;
@@ -6,10 +6,11 @@ import { CamOverlayDrawingOptions, TCairoCreateResponse, TCairoResponse, TUpload
6
6
  export declare class CamOverlayDrawingAPI extends EventEmitter {
7
7
  private tls;
8
8
  private tlsInsecure;
9
- private ip;
9
+ private host;
10
10
  private port;
11
11
  private user;
12
12
  private pass;
13
+ private headers?;
13
14
  private cameraList;
14
15
  private zIndex;
15
16
  private callId;
@@ -6,10 +6,11 @@ const WsClient_1 = require("./WsClient");
6
6
  class CamOverlayDrawingAPI extends events_1.EventEmitter {
7
7
  tls;
8
8
  tlsInsecure;
9
- ip;
9
+ host;
10
10
  port;
11
11
  user;
12
12
  pass;
13
+ headers;
13
14
  cameraList;
14
15
  zIndex;
15
16
  callId;
@@ -21,10 +22,11 @@ class CamOverlayDrawingAPI extends events_1.EventEmitter {
21
22
  super();
22
23
  this.tls = options?.tls ?? false;
23
24
  this.tlsInsecure = options?.tlsInsecure ?? false;
24
- this.ip = options?.ip ?? '127.0.0.1';
25
+ this.host = options?.host ?? options?.ip ?? '127.0.0.1';
25
26
  this.port = options?.port ?? (this.tls ? 443 : 80);
26
27
  this.user = options?.user ?? '';
27
28
  this.pass = options?.pass ?? '';
29
+ this.headers = options?.headers;
28
30
  this.zIndex = options?.zIndex ?? 0;
29
31
  this.cameraList = [0];
30
32
  if (options && Array.isArray(options.camera)) {
@@ -91,7 +93,7 @@ class CamOverlayDrawingAPI extends events_1.EventEmitter {
91
93
  }
92
94
  createWsClient() {
93
95
  const options = {
94
- ip: this.ip,
96
+ host: this.host,
95
97
  port: this.port,
96
98
  address: '/local/camoverlay/ws',
97
99
  protocol: 'cairo-api',
@@ -99,6 +101,7 @@ class CamOverlayDrawingAPI extends events_1.EventEmitter {
99
101
  pass: this.pass,
100
102
  tls: this.tls,
101
103
  tlsInsecure: this.tlsInsecure,
104
+ headers: this.headers,
102
105
  };
103
106
  this.ws = new WsClient_1.WsClient(options);
104
107
  this.ws.onOpen = () => {
@@ -5,10 +5,11 @@ import { TCamScripterEvent, TEventDeclaration, TEventUndeclaration, TCamScripter
5
5
  export declare class CamScripterAPICameraEventsGenerator extends EventEmitter {
6
6
  private tls;
7
7
  private tlsInsecure;
8
- private ip;
8
+ private host;
9
9
  private port;
10
10
  private user;
11
11
  private pass;
12
+ private headers?;
12
13
  private callId;
13
14
  private sendMessages;
14
15
  private timeoutCheckTimer;
@@ -6,10 +6,11 @@ const WsClient_1 = require("./WsClient");
6
6
  class CamScripterAPICameraEventsGenerator extends events_1.EventEmitter {
7
7
  tls;
8
8
  tlsInsecure;
9
- ip;
9
+ host;
10
10
  port;
11
11
  user;
12
12
  pass;
13
+ headers;
13
14
  callId;
14
15
  sendMessages;
15
16
  timeoutCheckTimer;
@@ -19,10 +20,11 @@ class CamScripterAPICameraEventsGenerator extends events_1.EventEmitter {
19
20
  super();
20
21
  this.tls = options?.tls ?? false;
21
22
  this.tlsInsecure = options?.tlsInsecure ?? false;
22
- this.ip = options?.ip ?? '127.0.0.1';
23
+ this.host = options?.host ?? options?.ip ?? '127.0.0.1';
23
24
  this.port = options?.port ?? (this.tls ? 443 : 80);
24
25
  this.user = options?.user ?? '';
25
26
  this.pass = options?.pass ?? '';
27
+ this.headers = options?.headers;
26
28
  this.callId = 0;
27
29
  this.sendMessages = {};
28
30
  this.wsConnected = false;
@@ -64,10 +66,11 @@ class CamScripterAPICameraEventsGenerator extends events_1.EventEmitter {
64
66
  pass: this.pass,
65
67
  tlsInsecure: this.tlsInsecure,
66
68
  tls: this.tls,
67
- ip: this.ip,
69
+ host: this.host,
68
70
  port: this.port,
69
71
  address: `/local/camscripter/ws`,
70
72
  protocol: 'camera-events',
73
+ headers: this.headers,
71
74
  };
72
75
  this.ws = new WsClient_1.WsClient(options);
73
76
  this.ws.onOpen = () => {
@@ -4,10 +4,11 @@ import { IClient, HttpOptions, TGetParams, TPostParams } from '../internal/types
4
4
  import { FormData as UndiciFormData, Response as UndiciResponse } from 'undici';
5
5
  export declare class DefaultClient implements IClient<UndiciResponse, UndiciFormData | Buffer> {
6
6
  private tls;
7
- private ip;
7
+ private host;
8
8
  private port;
9
- private user;
10
- private pass;
9
+ private user?;
10
+ private pass?;
11
+ private headers;
11
12
  private httpRequestSender;
12
13
  constructor(opt?: HttpOptions);
13
14
  get(params: TGetParams): Promise<UndiciResponse>;
@@ -5,17 +5,19 @@ const utils_1 = require("../internal/utils");
5
5
  const HttpRequestSender_1 = require("./HttpRequestSender");
6
6
  class DefaultClient {
7
7
  tls;
8
- ip;
8
+ host;
9
9
  port;
10
10
  user;
11
11
  pass;
12
+ headers;
12
13
  httpRequestSender;
13
14
  constructor(opt = {}) {
14
15
  this.tls = opt.tls ?? false;
15
- this.ip = opt.ip ?? '127.0.0.1';
16
+ this.host = opt.host ?? opt.ip ?? '127.0.0.1';
16
17
  this.port = opt.port ?? (this.tls ? 443 : 80);
17
- this.user = opt.user ?? '';
18
- this.pass = opt.pass ?? '';
18
+ this.user = opt.user;
19
+ this.pass = opt.pass;
20
+ this.headers = opt.headers ?? {};
19
21
  let agentOptions;
20
22
  if (opt.tlsInsecure !== undefined || opt.keepAlive !== undefined) {
21
23
  agentOptions = {
@@ -39,12 +41,12 @@ class DefaultClient {
39
41
  return {
40
42
  method: method,
41
43
  protocol: this.tls ? 'https:' : 'http:',
42
- host: this.ip,
44
+ host: this.host,
43
45
  port: this.port,
44
46
  path: (0, utils_1.addParametersToPath)(path, params),
45
47
  user: this.user,
46
48
  pass: this.pass,
47
- headers,
49
+ headers: { ...this.headers, ...headers },
48
50
  timeout,
49
51
  };
50
52
  }
@@ -0,0 +1,9 @@
1
+ import { DefaultClient } from './DefaultClient';
2
+ type THttpOptions = {
3
+ tlsInsecure?: boolean;
4
+ keepAlive?: boolean;
5
+ };
6
+ export declare class DeviceConnectClient extends DefaultClient {
7
+ constructor(deviceAccessToken: string, host: string, opt?: THttpOptions);
8
+ }
9
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceConnectClient = void 0;
4
+ const DefaultClient_1 = require("./DefaultClient");
5
+ class DeviceConnectClient extends DefaultClient_1.DefaultClient {
6
+ constructor(deviceAccessToken, host, opt = {}) {
7
+ super({
8
+ ...opt,
9
+ tls: true,
10
+ host: host,
11
+ headers: { authorization: `Bearer ${deviceAccessToken}` },
12
+ });
13
+ }
14
+ }
15
+ exports.DeviceConnectClient = DeviceConnectClient;
@@ -0,0 +1,12 @@
1
+ import { WsClient } from './WsClient';
2
+ type TWsClientOptions = {
3
+ path: string;
4
+ headers?: Record<string, string>;
5
+ tlsInsecure?: boolean;
6
+ pingInterval?: number;
7
+ protocol?: string;
8
+ };
9
+ export declare class DeviceConnectWsClient extends WsClient {
10
+ constructor(deviceAccessToken: string, host: string, opt: TWsClientOptions);
11
+ }
12
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceConnectWsClient = void 0;
4
+ const WsClient_1 = require("./WsClient");
5
+ class DeviceConnectWsClient extends WsClient_1.WsClient {
6
+ constructor(deviceAccessToken, host, opt) {
7
+ const andChar = opt.path.includes('?') ? '&' : '?';
8
+ super({
9
+ ...opt,
10
+ tls: true,
11
+ host: host,
12
+ address: `${opt.path}${andChar}DEVICE_ACCESS_TOKEN=${deviceAccessToken}`,
13
+ });
14
+ this.wsOptions = {
15
+ auth: undefined,
16
+ rejectUnauthorized: !opt.tlsInsecure,
17
+ headers: { ...opt.headers },
18
+ };
19
+ }
20
+ }
21
+ exports.DeviceConnectWsClient = DeviceConnectWsClient;
@@ -3,10 +3,11 @@ import { Options } from '../internal/types';
3
3
  export declare class VapixEvents extends EventEmitter {
4
4
  private tls;
5
5
  private tlsInsecure;
6
- private ip;
6
+ private host;
7
7
  private port;
8
8
  private user;
9
9
  private pass;
10
+ private headers?;
10
11
  private ws;
11
12
  constructor(options?: Options);
12
13
  connect(): void;
@@ -6,19 +6,21 @@ const WsClient_1 = require("./WsClient");
6
6
  class VapixEvents extends eventemitter2_1.EventEmitter2 {
7
7
  tls;
8
8
  tlsInsecure;
9
- ip;
9
+ host;
10
10
  port;
11
11
  user;
12
12
  pass;
13
+ headers;
13
14
  ws;
14
15
  constructor(options = {}) {
15
16
  super();
16
17
  this.tls = options.tls ?? false;
17
18
  this.tlsInsecure = options.tlsInsecure ?? false;
18
- this.ip = options.ip ?? '127.0.0.1';
19
+ this.host = options.host ?? options.ip ?? '127.0.0.1';
19
20
  this.port = options.port ?? (this.tls ? 443 : 80);
20
21
  this.user = options.user ?? 'root';
21
22
  this.pass = options.pass ?? '';
23
+ this.headers = options.headers;
22
24
  this.createWsClient();
23
25
  eventemitter2_1.EventEmitter2.call(this);
24
26
  }
@@ -34,9 +36,10 @@ class VapixEvents extends eventemitter2_1.EventEmitter2 {
34
36
  tlsInsecure: this.tlsInsecure,
35
37
  user: this.user,
36
38
  pass: this.pass,
37
- ip: this.ip,
39
+ host: this.host,
38
40
  port: this.port,
39
41
  address: '/vapix/ws-data-stream?sources=events',
42
+ headers: this.headers,
40
43
  };
41
44
  this.ws = new WsClient_1.WsClient(options);
42
45
  this.ws.onOpen = () => {
@@ -1,17 +1,21 @@
1
1
  import { IWsClient, Options } from '../internal/types';
2
2
  export type WsClientOptions = Options & {
3
3
  address: string;
4
- headers?: Record<string, string>;
5
4
  pingInterval?: number;
6
5
  protocol?: string;
7
6
  };
7
+ type TWsoptions = {
8
+ auth?: string;
9
+ rejectUnauthorized: boolean;
10
+ headers: Record<string, string>;
11
+ };
8
12
  export declare class WsClient implements IWsClient {
9
13
  private user;
10
14
  private pass;
11
15
  private address;
12
16
  private protocol?;
13
17
  private pingInterval;
14
- private wsOptions;
18
+ protected wsOptions: TWsoptions;
15
19
  private digestAddress;
16
20
  private isAlive;
17
21
  private pingTimer?;
@@ -28,3 +32,4 @@ export declare class WsClient implements IWsClient {
28
32
  reconnect(): void;
29
33
  private closeWsConnection;
30
34
  }
35
+ export {};
@@ -18,12 +18,12 @@ class WsClient {
18
18
  constructor(options) {
19
19
  const tls = options.tls ?? false;
20
20
  const tlsInsecure = options.tlsInsecure ?? false;
21
- const ip = options.ip ?? '127.0.0.1';
21
+ const host = options.host ?? options.ip ?? '127.0.0.1';
22
22
  const port = options.port ?? (tls ? 443 : 80);
23
23
  this.user = options.user ?? '';
24
24
  this.pass = options.pass ?? '';
25
25
  const protocol = tls ? 'wss' : 'ws';
26
- this.address = `${protocol}://${ip}:${port}${options.address}`;
26
+ this.address = `${protocol}://${host}:${port}${options.address}`;
27
27
  this.digestAddress = options.address;
28
28
  this.pingInterval = options.pingInterval ?? 30000;
29
29
  this.protocol = options.protocol;
@@ -61,7 +61,7 @@ class WsClient {
61
61
  this.isAlive = true;
62
62
  });
63
63
  if (wwwAuthenticateHeader !== undefined) {
64
- this.wsOptions.headers['Authorization'] = new Digest_1.Digest().getAuthHeader(this.user, this.pass, 'GET', this.digestAddress, wwwAuthenticateHeader);
64
+ this.wsOptions.headers['authorization'] = new Digest_1.Digest().getAuthHeader(this.user, this.pass, 'GET', this.digestAddress, wwwAuthenticateHeader);
65
65
  }
66
66
  this.ws.on('unexpected-response', (req, res) => {
67
67
  if (res.statusCode === 401 && res.headers['www-authenticate'] !== undefined) {
@@ -1,4 +1,6 @@
1
1
  export * from './DefaultClient';
2
+ export * from './DeviceConnectClient';
3
+ export { DeviceConnectWsClient } from './DeviceConnectWsClient';
2
4
  export * from './WsClient';
3
5
  export * from './HttpServer';
4
6
  export * from './HttpRequestSender';
package/cjs/node/index.js CHANGED
@@ -14,8 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.VapixEvents = exports.CamScripterAPICameraEventsGenerator = exports.CamOverlayDrawingAPI = exports.Frame = exports.Painter = exports.ResourceManager = void 0;
17
+ exports.VapixEvents = exports.CamScripterAPICameraEventsGenerator = exports.CamOverlayDrawingAPI = exports.Frame = exports.Painter = exports.ResourceManager = exports.DeviceConnectWsClient = void 0;
18
18
  __exportStar(require("./DefaultClient"), exports);
19
+ __exportStar(require("./DeviceConnectClient"), exports);
20
+ var DeviceConnectWsClient_1 = require("./DeviceConnectWsClient");
21
+ Object.defineProperty(exports, "DeviceConnectWsClient", { enumerable: true, get: function () { return DeviceConnectWsClient_1.DeviceConnectWsClient; } });
19
22
  __exportStar(require("./WsClient"), exports);
20
23
  __exportStar(require("./HttpServer"), exports);
21
24
  __exportStar(require("./HttpRequestSender"), exports);
@@ -1,7 +1,8 @@
1
1
  import { IClient, TGetParams, TPostParams } from '../internal/types';
2
2
  export declare class DefaultClient implements IClient<Response, FormData | ArrayBuffer> {
3
3
  domain: string;
4
- constructor(domain?: string);
4
+ headers: Record<string, string>;
5
+ constructor(domain?: string, headers?: Record<string, string>);
5
6
  get: (params: TGetParams) => Promise<Response>;
6
7
  post: (params: TPostParams<FormData | ArrayBuffer>) => Promise<Response>;
7
8
  private fetchWithTimeout;
@@ -4,20 +4,22 @@ exports.DefaultClient = void 0;
4
4
  const utils_1 = require("../internal/utils");
5
5
  class DefaultClient {
6
6
  domain;
7
- constructor(domain = '') {
7
+ headers;
8
+ constructor(domain = '', headers = {}) {
8
9
  this.domain = domain;
10
+ this.headers = headers;
9
11
  }
10
12
  get = (params) => {
11
13
  return this.fetchWithTimeout((0, utils_1.addParametersToPath)(params.path, params.parameters), {
12
14
  method: 'GET',
13
- headers: params.headers,
15
+ headers: { ...this.headers, ...params.headers },
14
16
  }, params.timeout);
15
17
  };
16
18
  post = (params) => {
17
19
  return this.fetchWithTimeout((0, utils_1.addParametersToPath)(params.path, params.parameters), {
18
20
  method: 'POST',
19
21
  body: params.data,
20
- headers: params.headers,
22
+ headers: { ...this.headers, ...params.headers },
21
23
  }, params.timeout);
22
24
  };
23
25
  async fetchWithTimeout(path, options, timeout) {
@@ -0,0 +1,4 @@
1
+ import { DefaultClient } from './DefaultClient';
2
+ export declare class DeviceConnectClient extends DefaultClient {
3
+ constructor(deviceAccessToken: string, host: string);
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceConnectClient = void 0;
4
+ const DefaultClient_1 = require("./DefaultClient");
5
+ class DeviceConnectClient extends DefaultClient_1.DefaultClient {
6
+ constructor(deviceAccessToken, host) {
7
+ super(`https://${host}`, { authorization: `Bearer ${deviceAccessToken}` });
8
+ }
9
+ }
10
+ exports.DeviceConnectClient = DeviceConnectClient;
@@ -0,0 +1,4 @@
1
+ import { WsClient } from './WsClient';
2
+ export declare class DeviceConnectWsClient extends WsClient {
3
+ constructor(deviceAccessToken: string, host: string, getPath: () => string);
4
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceConnectWsClient = void 0;
4
+ const WsClient_1 = require("./WsClient");
5
+ class DeviceConnectWsClient extends WsClient_1.WsClient {
6
+ constructor(deviceAccessToken, host, getPath) {
7
+ super(() => {
8
+ const path = getPath();
9
+ const andChar = path.includes('?') ? '&' : '?';
10
+ return `wss://${host}${path}${andChar}DEVICE_ACCESS_TOKEN=${deviceAccessToken}`;
11
+ });
12
+ }
13
+ }
14
+ exports.DeviceConnectWsClient = DeviceConnectWsClient;
@@ -1,2 +1,4 @@
1
1
  export { DefaultClient } from './DefaultClient';
2
+ export { DeviceConnectClient } from './DeviceConnectClient';
3
+ export { DeviceConnectWsClient } from './DeviceConnectWsClient';
2
4
  export { WsClient } from './WsClient';
package/cjs/web/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WsClient = exports.DefaultClient = void 0;
3
+ exports.WsClient = exports.DeviceConnectWsClient = exports.DeviceConnectClient = exports.DefaultClient = void 0;
4
4
  var DefaultClient_1 = require("./DefaultClient");
5
5
  Object.defineProperty(exports, "DefaultClient", { enumerable: true, get: function () { return DefaultClient_1.DefaultClient; } });
6
+ var DeviceConnectClient_1 = require("./DeviceConnectClient");
7
+ Object.defineProperty(exports, "DeviceConnectClient", { enumerable: true, get: function () { return DeviceConnectClient_1.DeviceConnectClient; } });
8
+ var DeviceConnectWsClient_1 = require("./DeviceConnectWsClient");
9
+ Object.defineProperty(exports, "DeviceConnectWsClient", { enumerable: true, get: function () { return DeviceConnectWsClient_1.DeviceConnectWsClient; } });
6
10
  var WsClient_1 = require("./WsClient");
7
11
  Object.defineProperty(exports, "WsClient", { enumerable: true, get: function () { return WsClient_1.WsClient; } });
@@ -1,8 +1,8 @@
1
1
  import { z } from 'zod';
2
- import { AddNewClipError, ParameterNotFoundError } from './errors/errors';
2
+ import { AddNewClipError, GenerateSilenceError, ParameterNotFoundError } from './errors/errors';
3
3
  import { parseBitrateOptionsToVapixParams, parseVapixParamsToBitrateOptions } from './internal/convertors';
4
4
  import { isClip, isNullish } from './internal/utils';
5
- import { storageInfoListSchema, outputInfoSchema, audioPushInfoSchema, clipListSchema, playlistQueueSchema, streamSaveLoadSchema, clipSaveLoadSchema, playlistSaveLoadSchema, trackerSaveLoadSchema, secondaryAudioSettingsSchema, globalAudioSettingsSchema, clipFilesListSchema, } from './types/CamSwitcherAPI';
5
+ import { storageInfoListSchema, outputInfoSchema, audioPushInfoSchema, clipListSchema, playlistQueueSchema, streamSaveLoadSchema, clipSaveLoadSchema, playlistSaveLoadSchema, trackerSaveLoadSchema, secondaryAudioSettingsSchema, globalAudioSettingsSchema, clipFilesListSchema, cameraOptionsSchema, } from './types/CamSwitcherAPI';
6
6
  import { networkCameraListSchema, } from './types/common';
7
7
  import { VapixAPI } from './VapixAPI';
8
8
  import { BasicAPI } from './internal/BasicAPI';
@@ -31,15 +31,13 @@ export class CamSwitcherAPI extends BasicAPI {
31
31
  return networkCameraListSchema.parse(res.data);
32
32
  }
33
33
  async generateSilence(sampleRate, channels, options) {
34
- const agent = this.getClient(options?.proxyParams);
35
- await agent.get({
36
- path: `${BASE_PATH}/generate_silence.cgi`,
37
- parameters: {
38
- sample_rate: sampleRate.toString(),
39
- channels,
40
- },
41
- timeout: options?.timeout,
42
- });
34
+ const res = await this._getJson(`${BASE_PATH}/generate_silence.cgi`, {
35
+ sample_rate: sampleRate.toString(),
36
+ channels,
37
+ }, options);
38
+ if (res.status !== 200) {
39
+ throw new GenerateSilenceError(res.message);
40
+ }
43
41
  }
44
42
  async getMaxFps(source, options) {
45
43
  const res = await this._getJson(`${BASE_PATH}/get_max_framerate.cgi`, {
@@ -201,28 +199,34 @@ export class CamSwitcherAPI extends BasicAPI {
201
199
  async getCamSwitchOptions(options) {
202
200
  const saveData = await this.getParamFromCameraAndJSONParse(CSW_PARAM_NAMES.SETTINGS, options);
203
201
  if (isNullish(saveData.video)) {
204
- return saveData;
202
+ return;
205
203
  }
206
- if (!isNullish(saveData.video?.bitrateVapixParams)) {
204
+ const settings = {
205
+ audioSampleRate: saveData.audio?.sampleRate,
206
+ audioChannelCount: saveData.audio?.channelCount,
207
+ keyboard: saveData.keyboard,
208
+ fps: saveData.video.fps,
209
+ resolution: saveData.video.resolution,
210
+ h264Profile: saveData.video.h264Profile,
211
+ compression: saveData.video.compression,
212
+ govLength: saveData.video.govLength,
213
+ bitrateVapixParams: saveData.video.bitrateVapixParams,
214
+ };
215
+ if (!isNullish(saveData.video.bitrateVapixParams)) {
207
216
  const bitrateOptions = parseVapixParamsToBitrateOptions(saveData.video.bitrateVapixParams);
208
- saveData.video.bitrateMode = bitrateOptions.bitrateMode;
209
- saveData.video.maximumBitRate = bitrateOptions.maximumBitRate;
210
- saveData.video.retentionTime = bitrateOptions.retentionTime;
211
- saveData.video.bitRateLimit = bitrateOptions.bitRateLimit;
217
+ settings.bitrateMode = bitrateOptions.bitrateMode;
218
+ settings.maximumBitRate = bitrateOptions.maximumBitRate;
219
+ settings.retentionTime = bitrateOptions.retentionTime;
220
+ settings.bitRateLimit = bitrateOptions.bitRateLimit;
212
221
  }
213
- if (!isNullish(saveData.video?.bitrateLimit)) {
214
- saveData.video.maximumBitRate = saveData.video.bitrateLimit;
215
- saveData.video.bitrateMode = 'MBR';
222
+ if (!isNullish(saveData.video.bitrateLimit)) {
223
+ settings.maximumBitRate = saveData.video.bitrateLimit;
224
+ settings.bitrateMode = 'MBR';
216
225
  }
217
- if (!isNullish(saveData.video?.videoClipQuality)) {
218
- saveData.video.maximumBitRate = saveData.video.videoClipQuality;
226
+ if (!isNullish(saveData.video.videoClipQuality)) {
227
+ settings.maximumBitRate = saveData.video.videoClipQuality;
219
228
  }
220
- return {
221
- ...saveData.video,
222
- audioSampleRate: saveData.audio.sampleRate,
223
- audioChannelCount: saveData.audio.channelCount,
224
- keyboard: saveData.keyboard,
225
- };
229
+ return cameraOptionsSchema.parse(settings);
226
230
  }
227
231
  async getGlobalAudioSettings(options) {
228
232
  const settings = {
@@ -94,6 +94,12 @@ export class AddNewClipError extends Error {
94
94
  this.name = 'AddNewClipError';
95
95
  }
96
96
  }
97
+ export class GenerateSilenceError extends Error {
98
+ constructor(message) {
99
+ super('Error generating silence clip: ' + message);
100
+ this.name = 'GenerateSilenceError';
101
+ }
102
+ }
97
103
  export class PtzNotSupportedError extends Error {
98
104
  constructor() {
99
105
  super('Ptz not supported.');
@@ -3,10 +3,11 @@ import { WsClient } from './WsClient';
3
3
  export class CamOverlayDrawingAPI extends EventEmitter {
4
4
  tls;
5
5
  tlsInsecure;
6
- ip;
6
+ host;
7
7
  port;
8
8
  user;
9
9
  pass;
10
+ headers;
10
11
  cameraList;
11
12
  zIndex;
12
13
  callId;
@@ -18,10 +19,11 @@ export class CamOverlayDrawingAPI extends EventEmitter {
18
19
  super();
19
20
  this.tls = options?.tls ?? false;
20
21
  this.tlsInsecure = options?.tlsInsecure ?? false;
21
- this.ip = options?.ip ?? '127.0.0.1';
22
+ this.host = options?.host ?? options?.ip ?? '127.0.0.1';
22
23
  this.port = options?.port ?? (this.tls ? 443 : 80);
23
24
  this.user = options?.user ?? '';
24
25
  this.pass = options?.pass ?? '';
26
+ this.headers = options?.headers;
25
27
  this.zIndex = options?.zIndex ?? 0;
26
28
  this.cameraList = [0];
27
29
  if (options && Array.isArray(options.camera)) {
@@ -88,7 +90,7 @@ export class CamOverlayDrawingAPI extends EventEmitter {
88
90
  }
89
91
  createWsClient() {
90
92
  const options = {
91
- ip: this.ip,
93
+ host: this.host,
92
94
  port: this.port,
93
95
  address: '/local/camoverlay/ws',
94
96
  protocol: 'cairo-api',
@@ -96,6 +98,7 @@ export class CamOverlayDrawingAPI extends EventEmitter {
96
98
  pass: this.pass,
97
99
  tls: this.tls,
98
100
  tlsInsecure: this.tlsInsecure,
101
+ headers: this.headers,
99
102
  };
100
103
  this.ws = new WsClient(options);
101
104
  this.ws.onOpen = () => {
@@ -3,10 +3,11 @@ import { WsClient } from './WsClient';
3
3
  export class CamScripterAPICameraEventsGenerator extends EventEmitter {
4
4
  tls;
5
5
  tlsInsecure;
6
- ip;
6
+ host;
7
7
  port;
8
8
  user;
9
9
  pass;
10
+ headers;
10
11
  callId;
11
12
  sendMessages;
12
13
  timeoutCheckTimer;
@@ -16,10 +17,11 @@ export class CamScripterAPICameraEventsGenerator extends EventEmitter {
16
17
  super();
17
18
  this.tls = options?.tls ?? false;
18
19
  this.tlsInsecure = options?.tlsInsecure ?? false;
19
- this.ip = options?.ip ?? '127.0.0.1';
20
+ this.host = options?.host ?? options?.ip ?? '127.0.0.1';
20
21
  this.port = options?.port ?? (this.tls ? 443 : 80);
21
22
  this.user = options?.user ?? '';
22
23
  this.pass = options?.pass ?? '';
24
+ this.headers = options?.headers;
23
25
  this.callId = 0;
24
26
  this.sendMessages = {};
25
27
  this.wsConnected = false;
@@ -61,10 +63,11 @@ export class CamScripterAPICameraEventsGenerator extends EventEmitter {
61
63
  pass: this.pass,
62
64
  tlsInsecure: this.tlsInsecure,
63
65
  tls: this.tls,
64
- ip: this.ip,
66
+ host: this.host,
65
67
  port: this.port,
66
68
  address: `/local/camscripter/ws`,
67
69
  protocol: 'camera-events',
70
+ headers: this.headers,
68
71
  };
69
72
  this.ws = new WsClient(options);
70
73
  this.ws.onOpen = () => {
@@ -2,17 +2,19 @@ import { addParametersToPath } from '../internal/utils';
2
2
  import { HttpRequestSender } from './HttpRequestSender';
3
3
  export class DefaultClient {
4
4
  tls;
5
- ip;
5
+ host;
6
6
  port;
7
7
  user;
8
8
  pass;
9
+ headers;
9
10
  httpRequestSender;
10
11
  constructor(opt = {}) {
11
12
  this.tls = opt.tls ?? false;
12
- this.ip = opt.ip ?? '127.0.0.1';
13
+ this.host = opt.host ?? opt.ip ?? '127.0.0.1';
13
14
  this.port = opt.port ?? (this.tls ? 443 : 80);
14
- this.user = opt.user ?? '';
15
- this.pass = opt.pass ?? '';
15
+ this.user = opt.user;
16
+ this.pass = opt.pass;
17
+ this.headers = opt.headers ?? {};
16
18
  let agentOptions;
17
19
  if (opt.tlsInsecure !== undefined || opt.keepAlive !== undefined) {
18
20
  agentOptions = {
@@ -36,12 +38,12 @@ export class DefaultClient {
36
38
  return {
37
39
  method: method,
38
40
  protocol: this.tls ? 'https:' : 'http:',
39
- host: this.ip,
41
+ host: this.host,
40
42
  port: this.port,
41
43
  path: addParametersToPath(path, params),
42
44
  user: this.user,
43
45
  pass: this.pass,
44
- headers,
46
+ headers: { ...this.headers, ...headers },
45
47
  timeout,
46
48
  };
47
49
  }
@@ -0,0 +1,11 @@
1
+ import { DefaultClient } from './DefaultClient';
2
+ export class DeviceConnectClient extends DefaultClient {
3
+ constructor(deviceAccessToken, host, opt = {}) {
4
+ super({
5
+ ...opt,
6
+ tls: true,
7
+ host: host,
8
+ headers: { authorization: `Bearer ${deviceAccessToken}` },
9
+ });
10
+ }
11
+ }
@@ -0,0 +1,17 @@
1
+ import { WsClient } from './WsClient';
2
+ export class DeviceConnectWsClient extends WsClient {
3
+ constructor(deviceAccessToken, host, opt) {
4
+ const andChar = opt.path.includes('?') ? '&' : '?';
5
+ super({
6
+ ...opt,
7
+ tls: true,
8
+ host: host,
9
+ address: `${opt.path}${andChar}DEVICE_ACCESS_TOKEN=${deviceAccessToken}`,
10
+ });
11
+ this.wsOptions = {
12
+ auth: undefined,
13
+ rejectUnauthorized: !opt.tlsInsecure,
14
+ headers: { ...opt.headers },
15
+ };
16
+ }
17
+ }
@@ -3,19 +3,21 @@ import { WsClient } from './WsClient';
3
3
  export class VapixEvents extends EventEmitter {
4
4
  tls;
5
5
  tlsInsecure;
6
- ip;
6
+ host;
7
7
  port;
8
8
  user;
9
9
  pass;
10
+ headers;
10
11
  ws;
11
12
  constructor(options = {}) {
12
13
  super();
13
14
  this.tls = options.tls ?? false;
14
15
  this.tlsInsecure = options.tlsInsecure ?? false;
15
- this.ip = options.ip ?? '127.0.0.1';
16
+ this.host = options.host ?? options.ip ?? '127.0.0.1';
16
17
  this.port = options.port ?? (this.tls ? 443 : 80);
17
18
  this.user = options.user ?? 'root';
18
19
  this.pass = options.pass ?? '';
20
+ this.headers = options.headers;
19
21
  this.createWsClient();
20
22
  EventEmitter.call(this);
21
23
  }
@@ -31,9 +33,10 @@ export class VapixEvents extends EventEmitter {
31
33
  tlsInsecure: this.tlsInsecure,
32
34
  user: this.user,
33
35
  pass: this.pass,
34
- ip: this.ip,
36
+ host: this.host,
35
37
  port: this.port,
36
38
  address: '/vapix/ws-data-stream?sources=events',
39
+ headers: this.headers,
37
40
  };
38
41
  this.ws = new WsClient(options);
39
42
  this.ws.onOpen = () => {
@@ -15,12 +15,12 @@ export class WsClient {
15
15
  constructor(options) {
16
16
  const tls = options.tls ?? false;
17
17
  const tlsInsecure = options.tlsInsecure ?? false;
18
- const ip = options.ip ?? '127.0.0.1';
18
+ const host = options.host ?? options.ip ?? '127.0.0.1';
19
19
  const port = options.port ?? (tls ? 443 : 80);
20
20
  this.user = options.user ?? '';
21
21
  this.pass = options.pass ?? '';
22
22
  const protocol = tls ? 'wss' : 'ws';
23
- this.address = `${protocol}://${ip}:${port}${options.address}`;
23
+ this.address = `${protocol}://${host}:${port}${options.address}`;
24
24
  this.digestAddress = options.address;
25
25
  this.pingInterval = options.pingInterval ?? 30000;
26
26
  this.protocol = options.protocol;
@@ -58,7 +58,7 @@ export class WsClient {
58
58
  this.isAlive = true;
59
59
  });
60
60
  if (wwwAuthenticateHeader !== undefined) {
61
- this.wsOptions.headers['Authorization'] = new Digest().getAuthHeader(this.user, this.pass, 'GET', this.digestAddress, wwwAuthenticateHeader);
61
+ this.wsOptions.headers['authorization'] = new Digest().getAuthHeader(this.user, this.pass, 'GET', this.digestAddress, wwwAuthenticateHeader);
62
62
  }
63
63
  this.ws.on('unexpected-response', (req, res) => {
64
64
  if (res.statusCode === 401 && res.headers['www-authenticate'] !== undefined) {
package/esm/node/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './DefaultClient';
2
+ export * from './DeviceConnectClient';
3
+ export { DeviceConnectWsClient } from './DeviceConnectWsClient';
2
4
  export * from './WsClient';
3
5
  export * from './HttpServer';
4
6
  export * from './HttpRequestSender';
@@ -1,20 +1,22 @@
1
1
  import { addParametersToPath } from '../internal/utils';
2
2
  export class DefaultClient {
3
3
  domain;
4
- constructor(domain = '') {
4
+ headers;
5
+ constructor(domain = '', headers = {}) {
5
6
  this.domain = domain;
7
+ this.headers = headers;
6
8
  }
7
9
  get = (params) => {
8
10
  return this.fetchWithTimeout(addParametersToPath(params.path, params.parameters), {
9
11
  method: 'GET',
10
- headers: params.headers,
12
+ headers: { ...this.headers, ...params.headers },
11
13
  }, params.timeout);
12
14
  };
13
15
  post = (params) => {
14
16
  return this.fetchWithTimeout(addParametersToPath(params.path, params.parameters), {
15
17
  method: 'POST',
16
18
  body: params.data,
17
- headers: params.headers,
19
+ headers: { ...this.headers, ...params.headers },
18
20
  }, params.timeout);
19
21
  };
20
22
  async fetchWithTimeout(path, options, timeout) {
@@ -0,0 +1,6 @@
1
+ import { DefaultClient } from './DefaultClient';
2
+ export class DeviceConnectClient extends DefaultClient {
3
+ constructor(deviceAccessToken, host) {
4
+ super(`https://${host}`, { authorization: `Bearer ${deviceAccessToken}` });
5
+ }
6
+ }
@@ -0,0 +1,10 @@
1
+ import { WsClient } from './WsClient';
2
+ export class DeviceConnectWsClient extends WsClient {
3
+ constructor(deviceAccessToken, host, getPath) {
4
+ super(() => {
5
+ const path = getPath();
6
+ const andChar = path.includes('?') ? '&' : '?';
7
+ return `wss://${host}${path}${andChar}DEVICE_ACCESS_TOKEN=${deviceAccessToken}`;
8
+ });
9
+ }
10
+ }
package/esm/web/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  export { DefaultClient } from './DefaultClient';
2
+ export { DeviceConnectClient } from './DeviceConnectClient';
3
+ export { DeviceConnectWsClient } from './DeviceConnectWsClient';
2
4
  export { WsClient } from './WsClient';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camstreamerlib",
3
- "version": "4.0.30-fd4e027",
3
+ "version": "4.0.31-2493e55",
4
4
  "description": "Helper library for CamStreamer ACAP applications.",
5
5
  "prettier": "@camstreamer/prettier-config",
6
6
  "engine": {
@@ -144,7 +144,24 @@ export declare class CamSwitcherAPI<Client extends IClient<TResponse, any>> exte
144
144
  setSecondaryAudioSettings(settings: TSecondaryAudioSettings, options?: THttpRequestOptions): Promise<void>;
145
145
  setDefaultPlaylist(playlistId: string, options?: THttpRequestOptions): Promise<void>;
146
146
  setPermanentRtspUrlToken(token: string, options?: THttpRequestOptions): Promise<void>;
147
- getCamSwitchOptions(options?: THttpRequestOptions): Promise<any>;
147
+ getCamSwitchOptions(options?: THttpRequestOptions): Promise<{
148
+ resolution?: string | undefined;
149
+ compression?: number | undefined;
150
+ bitrateMode?: "VBR" | "MBR" | "ABR" | undefined;
151
+ maximumBitRate?: number | undefined;
152
+ retentionTime?: number | undefined;
153
+ bitRateLimit?: number | undefined;
154
+ fps?: number | undefined;
155
+ govLength?: number | undefined;
156
+ h264Profile?: "high" | "main" | "baseline" | undefined;
157
+ keyboard?: {
158
+ none: string | null;
159
+ fromSource: string | null;
160
+ } | undefined;
161
+ bitrateVapixParams?: string | null | undefined;
162
+ audioSampleRate?: number | undefined;
163
+ audioChannelCount?: 1 | 2 | undefined;
164
+ } | undefined>;
148
165
  getGlobalAudioSettings(options?: THttpRequestOptions): Promise<{
149
166
  type: "source" | "fromSource";
150
167
  source: string;
@@ -49,6 +49,9 @@ export declare class FetchDeviceInfoError extends Error {
49
49
  export declare class AddNewClipError extends Error {
50
50
  constructor(message: string);
51
51
  }
52
+ export declare class GenerateSilenceError extends Error {
53
+ constructor(message: string);
54
+ }
52
55
  export declare class PtzNotSupportedError extends Error {
53
56
  constructor();
54
57
  }
@@ -1,10 +1,12 @@
1
1
  export type Options = {
2
2
  ip?: string;
3
+ host?: string;
3
4
  port?: number;
4
5
  user?: string;
5
6
  pass?: string;
6
7
  tls?: boolean;
7
8
  tlsInsecure?: boolean;
9
+ headers?: Record<string, string>;
8
10
  };
9
11
  export type HttpOptions = Options & {
10
12
  keepAlive?: boolean;
@@ -6,10 +6,11 @@ import { CamOverlayDrawingOptions, TCairoCreateResponse, TCairoResponse, TUpload
6
6
  export declare class CamOverlayDrawingAPI extends EventEmitter {
7
7
  private tls;
8
8
  private tlsInsecure;
9
- private ip;
9
+ private host;
10
10
  private port;
11
11
  private user;
12
12
  private pass;
13
+ private headers?;
13
14
  private cameraList;
14
15
  private zIndex;
15
16
  private callId;
@@ -5,10 +5,11 @@ import { TCamScripterEvent, TEventDeclaration, TEventUndeclaration, TCamScripter
5
5
  export declare class CamScripterAPICameraEventsGenerator extends EventEmitter {
6
6
  private tls;
7
7
  private tlsInsecure;
8
- private ip;
8
+ private host;
9
9
  private port;
10
10
  private user;
11
11
  private pass;
12
+ private headers?;
12
13
  private callId;
13
14
  private sendMessages;
14
15
  private timeoutCheckTimer;
@@ -4,10 +4,11 @@ import { IClient, HttpOptions, TGetParams, TPostParams } from '../internal/types
4
4
  import { FormData as UndiciFormData, Response as UndiciResponse } from 'undici';
5
5
  export declare class DefaultClient implements IClient<UndiciResponse, UndiciFormData | Buffer> {
6
6
  private tls;
7
- private ip;
7
+ private host;
8
8
  private port;
9
- private user;
10
- private pass;
9
+ private user?;
10
+ private pass?;
11
+ private headers;
11
12
  private httpRequestSender;
12
13
  constructor(opt?: HttpOptions);
13
14
  get(params: TGetParams): Promise<UndiciResponse>;
@@ -0,0 +1,9 @@
1
+ import { DefaultClient } from './DefaultClient';
2
+ type THttpOptions = {
3
+ tlsInsecure?: boolean;
4
+ keepAlive?: boolean;
5
+ };
6
+ export declare class DeviceConnectClient extends DefaultClient {
7
+ constructor(deviceAccessToken: string, host: string, opt?: THttpOptions);
8
+ }
9
+ export {};
@@ -0,0 +1,12 @@
1
+ import { WsClient } from './WsClient';
2
+ type TWsClientOptions = {
3
+ path: string;
4
+ headers?: Record<string, string>;
5
+ tlsInsecure?: boolean;
6
+ pingInterval?: number;
7
+ protocol?: string;
8
+ };
9
+ export declare class DeviceConnectWsClient extends WsClient {
10
+ constructor(deviceAccessToken: string, host: string, opt: TWsClientOptions);
11
+ }
12
+ export {};
@@ -3,10 +3,11 @@ import { Options } from '../internal/types';
3
3
  export declare class VapixEvents extends EventEmitter {
4
4
  private tls;
5
5
  private tlsInsecure;
6
- private ip;
6
+ private host;
7
7
  private port;
8
8
  private user;
9
9
  private pass;
10
+ private headers?;
10
11
  private ws;
11
12
  constructor(options?: Options);
12
13
  connect(): void;
@@ -1,17 +1,21 @@
1
1
  import { IWsClient, Options } from '../internal/types';
2
2
  export type WsClientOptions = Options & {
3
3
  address: string;
4
- headers?: Record<string, string>;
5
4
  pingInterval?: number;
6
5
  protocol?: string;
7
6
  };
7
+ type TWsoptions = {
8
+ auth?: string;
9
+ rejectUnauthorized: boolean;
10
+ headers: Record<string, string>;
11
+ };
8
12
  export declare class WsClient implements IWsClient {
9
13
  private user;
10
14
  private pass;
11
15
  private address;
12
16
  private protocol?;
13
17
  private pingInterval;
14
- private wsOptions;
18
+ protected wsOptions: TWsoptions;
15
19
  private digestAddress;
16
20
  private isAlive;
17
21
  private pingTimer?;
@@ -28,3 +32,4 @@ export declare class WsClient implements IWsClient {
28
32
  reconnect(): void;
29
33
  private closeWsConnection;
30
34
  }
35
+ export {};
@@ -1,4 +1,6 @@
1
1
  export * from './DefaultClient';
2
+ export * from './DeviceConnectClient';
3
+ export { DeviceConnectWsClient } from './DeviceConnectWsClient';
2
4
  export * from './WsClient';
3
5
  export * from './HttpServer';
4
6
  export * from './HttpRequestSender';
@@ -1,7 +1,8 @@
1
1
  import { IClient, TGetParams, TPostParams } from '../internal/types';
2
2
  export declare class DefaultClient implements IClient<Response, FormData | ArrayBuffer> {
3
3
  domain: string;
4
- constructor(domain?: string);
4
+ headers: Record<string, string>;
5
+ constructor(domain?: string, headers?: Record<string, string>);
5
6
  get: (params: TGetParams) => Promise<Response>;
6
7
  post: (params: TPostParams<FormData | ArrayBuffer>) => Promise<Response>;
7
8
  private fetchWithTimeout;
@@ -0,0 +1,4 @@
1
+ import { DefaultClient } from './DefaultClient';
2
+ export declare class DeviceConnectClient extends DefaultClient {
3
+ constructor(deviceAccessToken: string, host: string);
4
+ }
@@ -0,0 +1,4 @@
1
+ import { WsClient } from './WsClient';
2
+ export declare class DeviceConnectWsClient extends WsClient {
3
+ constructor(deviceAccessToken: string, host: string, getPath: () => string);
4
+ }
@@ -1,2 +1,4 @@
1
1
  export { DefaultClient } from './DefaultClient';
2
+ export { DeviceConnectClient } from './DeviceConnectClient';
3
+ export { DeviceConnectWsClient } from './DeviceConnectWsClient';
2
4
  export { WsClient } from './WsClient';