camstreamerlib 3.5.2 → 4.0.0-beta.2

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 (72) hide show
  1. package/CamOverlayAPI.d.ts +11 -28
  2. package/CamOverlayAPI.js +116 -138
  3. package/CamOverlayDrawingAPI.js +26 -18
  4. package/CamOverlayPainter/Frame.js +167 -182
  5. package/CamOverlayPainter/Painter.js +80 -101
  6. package/CamOverlayPainter/ResourceManager.js +31 -46
  7. package/CamScripterAPI.d.ts +19 -0
  8. package/CamScripterAPI.js +66 -0
  9. package/CamScripterAPICameraEventsGenerator.js +22 -16
  10. package/CamStreamerAPI.d.ts +5 -27
  11. package/CamStreamerAPI.js +45 -71
  12. package/CamSwitcherAPI.d.ts +38 -71
  13. package/CamSwitcherAPI.js +329 -91
  14. package/CamSwitcherEvents.d.ts +15 -33
  15. package/CamSwitcherEvents.js +53 -97
  16. package/CreatePackage.js +5 -7
  17. package/README.md +3 -1
  18. package/VapixAPI.d.ts +66 -0
  19. package/VapixAPI.js +454 -0
  20. package/VapixEvents.js +18 -16
  21. package/errors/errors.d.ts +34 -0
  22. package/errors/errors.js +66 -0
  23. package/events/AxisCameraStationEvents.js +29 -42
  24. package/events/GenetecAgent.d.ts +14 -15
  25. package/events/GenetecAgent.js +81 -100
  26. package/internal/Digest.js +5 -11
  27. package/internal/ProxyClient.d.ts +11 -0
  28. package/internal/ProxyClient.js +40 -0
  29. package/internal/common.d.ts +19 -4
  30. package/internal/common.js +11 -26
  31. package/internal/constants.d.ts +1 -0
  32. package/internal/constants.js +1 -0
  33. package/internal/transformers.d.ts +5 -0
  34. package/internal/transformers.js +25 -0
  35. package/internal/utils.d.ts +11 -0
  36. package/internal/utils.js +34 -0
  37. package/internal/versionCompare.d.ts +6 -0
  38. package/internal/versionCompare.js +44 -0
  39. package/node/DefaultClient.d.ts +15 -0
  40. package/node/DefaultClient.js +50 -0
  41. package/{internal → node}/HttpRequestSender.d.ts +2 -2
  42. package/node/HttpRequestSender.js +85 -0
  43. package/{HttpServer.d.ts → node/HttpServer.d.ts} +1 -1
  44. package/{HttpServer.js → node/HttpServer.js} +22 -24
  45. package/{internal → node}/WsClient.d.ts +1 -1
  46. package/{internal → node}/WsClient.js +32 -39
  47. package/node/WsEventClient.d.ts +13 -0
  48. package/node/WsEventClient.js +18 -0
  49. package/package.json +7 -3
  50. package/types/CamOverlayAPI.d.ts +188 -0
  51. package/types/CamOverlayAPI.js +44 -0
  52. package/types/CamScripterAPI.d.ts +67 -0
  53. package/types/CamScripterAPI.js +17 -0
  54. package/types/CamStreamerAPI.d.ts +139 -0
  55. package/types/CamStreamerAPI.js +25 -0
  56. package/types/CamSwitcherAPI.d.ts +814 -0
  57. package/types/CamSwitcherAPI.js +134 -0
  58. package/types/CamswitcherEvents.d.ts +491 -0
  59. package/types/CamswitcherEvents.js +59 -0
  60. package/types/VapixAPI.d.ts +1704 -0
  61. package/types/VapixAPI.js +129 -0
  62. package/types/common.d.ts +37 -0
  63. package/types/common.js +11 -0
  64. package/web/DefaultClient.d.ts +6 -0
  65. package/web/DefaultClient.js +16 -0
  66. package/web/WsClient.d.ts +13 -0
  67. package/web/WsClient.js +58 -0
  68. package/CameraVapix.d.ts +0 -98
  69. package/CameraVapix.js +0 -441
  70. package/DefaultAgent.d.ts +0 -15
  71. package/DefaultAgent.js +0 -68
  72. package/internal/HttpRequestSender.js +0 -117
@@ -0,0 +1,66 @@
1
+ export class ServiceUnavailableError extends Error {
2
+ constructor() {
3
+ super('Service is unavailable.');
4
+ this.name = 'ServiceUnavailableError';
5
+ }
6
+ }
7
+ export class ServiceNotFoundError extends Error {
8
+ constructor() {
9
+ super('Service not found.');
10
+ this.name = 'ServiceNotFoundError';
11
+ }
12
+ }
13
+ export class ParsingBlobError extends Error {
14
+ constructor(err) {
15
+ super('Error parsing response as Blob: ' + err);
16
+ this.name = 'ParsingBlobError';
17
+ }
18
+ }
19
+ export class ApplicationAPIError extends Error {
20
+ constructor(action, res) {
21
+ super(`[APP ${action}] Error: ` + res);
22
+ this.name = 'ApplicationAPIError';
23
+ }
24
+ }
25
+ export class SDCardActionError extends Error {
26
+ constructor(action, res) {
27
+ super(`[SD_CARD ${action}] Error: ` + res);
28
+ this.name = 'SDCardActionError';
29
+ }
30
+ }
31
+ export class SDCardJobError extends Error {
32
+ constructor() {
33
+ super('Error while fetching SD card job progress');
34
+ this.name = 'SDCardJobError';
35
+ }
36
+ }
37
+ const MAX_FPS_ERROR_MESSAGES = {
38
+ MALFORMED_REPLY: 'Malformed reply from camera',
39
+ CHANNEL_NOT_FOUND: 'Video channel not found.',
40
+ CAPTURE_MODE_NOT_FOUND: 'No enabled capture mode found.',
41
+ FPS_NOT_SPECIFIED: 'Max fps not specified for given capture mode.',
42
+ };
43
+ export class MaxFPSError extends Error {
44
+ constructor(state) {
45
+ super(`[MAX_FPS ${state}] Error: ` + MAX_FPS_ERROR_MESSAGES[state]);
46
+ this.name = 'MaxFPSError';
47
+ }
48
+ }
49
+ export class NoDeviceInfoError extends Error {
50
+ constructor() {
51
+ super('Did not get any data from remote camera');
52
+ this.name = 'NoDeviceInfoError';
53
+ }
54
+ }
55
+ export class FetchDeviceInfoError extends Error {
56
+ constructor(err) {
57
+ super('Error fetching remote camera data: ' + err);
58
+ this.name = 'NoDeviceInfoFromCameraError';
59
+ }
60
+ }
61
+ export class AddNewClipError extends Error {
62
+ constructor(message) {
63
+ super('Error adding new clip: ' + message);
64
+ this.name = 'AddNewClipError';
65
+ }
66
+ }
@@ -1,57 +1,44 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AxisCameraStationEvents = void 0;
13
- const DefaultAgent_1 = require("../DefaultAgent");
14
- const common_1 = require("../internal/common");
15
- class AxisCameraStationEvents {
1
+ import { DefaultClient } from '../node/DefaultClient';
2
+ import { isClient, pad } from '../internal/common';
3
+ export class AxisCameraStationEvents {
4
+ sourceKey;
5
+ client;
16
6
  constructor(sourceKey, opt = {}) {
17
7
  this.sourceKey = sourceKey;
18
- if ((0, common_1.isClient)(opt)) {
8
+ if (isClient(opt)) {
19
9
  this.client = opt;
20
10
  }
21
11
  else {
22
- this.client = new DefaultAgent_1.DefaultAgent(opt);
12
+ this.client = new DefaultClient(opt);
23
13
  }
24
14
  }
25
- sendEvent(data, eventType) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const dateString = this.getDate();
28
- const event = {
29
- addExternalDataRequest: {
30
- occurrenceTime: dateString,
31
- source: this.sourceKey,
32
- externalDataType: eventType,
33
- data: data,
34
- },
35
- };
36
- const eventData = JSON.stringify(event);
37
- const res = yield this.client.post('/Acs/Api/ExternalDataFacade/AddExternalData', eventData, undefined, {
38
- 'Content-Type': 'application/json',
39
- 'Content-Length': eventData.length.toString(),
40
- });
41
- if (!res.ok) {
42
- throw new Error(`ACS status code: ${res.status}`);
43
- }
15
+ async sendEvent(data, eventType) {
16
+ const dateString = this.getDate();
17
+ const event = {
18
+ addExternalDataRequest: {
19
+ occurrenceTime: dateString,
20
+ source: this.sourceKey,
21
+ externalDataType: eventType,
22
+ data: data,
23
+ },
24
+ };
25
+ const eventData = JSON.stringify(event);
26
+ const res = await this.client.post('/Acs/Api/ExternalDataFacade/AddExternalData', eventData, undefined, {
27
+ 'Content-Type': 'application/json',
28
+ 'Content-Length': eventData.length.toString(),
44
29
  });
30
+ if (!res.ok) {
31
+ throw new Error(`ACS status code: ${res.status}`);
32
+ }
45
33
  }
46
34
  getDate() {
47
35
  const date = new Date();
48
36
  const year = date.getUTCFullYear();
49
- const month = (0, common_1.pad)(date.getUTCMonth() + 1, 2);
50
- const day = (0, common_1.pad)(date.getUTCDate(), 2);
51
- const hours = (0, common_1.pad)(date.getUTCHours(), 2);
52
- const minutes = (0, common_1.pad)(date.getUTCMinutes(), 2);
53
- const seconds = (0, common_1.pad)(date.getUTCSeconds(), 2);
37
+ const month = pad(date.getUTCMonth() + 1, 2);
38
+ const day = pad(date.getUTCDate(), 2);
39
+ const hours = pad(date.getUTCHours(), 2);
40
+ const minutes = pad(date.getUTCMinutes(), 2);
41
+ const seconds = pad(date.getUTCSeconds(), 2);
54
42
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
55
43
  }
56
44
  }
57
- exports.AxisCameraStationEvents = AxisCameraStationEvents;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { z } from 'zod';
3
2
  declare const cameraGuidsResponseSchema: z.ZodObject<{
4
3
  Rsp: z.ZodObject<{
@@ -60,12 +59,12 @@ export declare const cameraDetailSchema: z.ZodObject<{
60
59
  Name: z.ZodOptional<z.ZodString>;
61
60
  EntityType: z.ZodOptional<z.ZodString>;
62
61
  }, "strip", z.ZodTypeAny, {
63
- Guid?: string | undefined;
64
62
  Name?: string | undefined;
63
+ Guid?: string | undefined;
65
64
  EntityType?: string | undefined;
66
65
  }, {
67
- Guid?: string | undefined;
68
66
  Name?: string | undefined;
67
+ Guid?: string | undefined;
69
68
  EntityType?: string | undefined;
70
69
  }>;
71
70
  export declare const cameraDetailsResponseSchema: z.ZodObject<{
@@ -76,46 +75,46 @@ export declare const cameraDetailsResponseSchema: z.ZodObject<{
76
75
  Name: z.ZodOptional<z.ZodString>;
77
76
  EntityType: z.ZodOptional<z.ZodString>;
78
77
  }, "strip", z.ZodTypeAny, {
79
- Guid?: string | undefined;
80
78
  Name?: string | undefined;
79
+ Guid?: string | undefined;
81
80
  EntityType?: string | undefined;
82
81
  }, {
83
- Guid?: string | undefined;
84
82
  Name?: string | undefined;
83
+ Guid?: string | undefined;
85
84
  EntityType?: string | undefined;
86
85
  }>, "many">, z.ZodObject<{
87
86
  Guid: z.ZodOptional<z.ZodString>;
88
87
  Name: z.ZodOptional<z.ZodString>;
89
88
  EntityType: z.ZodOptional<z.ZodString>;
90
89
  }, "strip", z.ZodTypeAny, {
91
- Guid?: string | undefined;
92
90
  Name?: string | undefined;
91
+ Guid?: string | undefined;
93
92
  EntityType?: string | undefined;
94
93
  }, {
95
- Guid?: string | undefined;
96
94
  Name?: string | undefined;
95
+ Guid?: string | undefined;
97
96
  EntityType?: string | undefined;
98
97
  }>]>;
99
98
  }, "strip", z.ZodTypeAny, {
100
99
  Status: string;
101
100
  Result: {
102
- Guid?: string | undefined;
103
101
  Name?: string | undefined;
102
+ Guid?: string | undefined;
104
103
  EntityType?: string | undefined;
105
104
  } | {
106
- Guid?: string | undefined;
107
105
  Name?: string | undefined;
106
+ Guid?: string | undefined;
108
107
  EntityType?: string | undefined;
109
108
  }[];
110
109
  }, {
111
110
  Status: string;
112
111
  Result: {
113
- Guid?: string | undefined;
114
112
  Name?: string | undefined;
113
+ Guid?: string | undefined;
115
114
  EntityType?: string | undefined;
116
115
  } | {
117
- Guid?: string | undefined;
118
116
  Name?: string | undefined;
117
+ Guid?: string | undefined;
119
118
  EntityType?: string | undefined;
120
119
  }[];
121
120
  }>;
@@ -123,12 +122,12 @@ export declare const cameraDetailsResponseSchema: z.ZodObject<{
123
122
  Rsp: {
124
123
  Status: string;
125
124
  Result: {
126
- Guid?: string | undefined;
127
125
  Name?: string | undefined;
126
+ Guid?: string | undefined;
128
127
  EntityType?: string | undefined;
129
128
  } | {
130
- Guid?: string | undefined;
131
129
  Name?: string | undefined;
130
+ Guid?: string | undefined;
132
131
  EntityType?: string | undefined;
133
132
  }[];
134
133
  };
@@ -136,12 +135,12 @@ export declare const cameraDetailsResponseSchema: z.ZodObject<{
136
135
  Rsp: {
137
136
  Status: string;
138
137
  Result: {
139
- Guid?: string | undefined;
140
138
  Name?: string | undefined;
139
+ Guid?: string | undefined;
141
140
  EntityType?: string | undefined;
142
141
  } | {
143
- Guid?: string | undefined;
144
142
  Name?: string | undefined;
143
+ Guid?: string | undefined;
145
144
  EntityType?: string | undefined;
146
145
  }[];
147
146
  };
@@ -1,117 +1,99 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.GenetecAgent = exports.cameraDetailsResponseSchema = exports.cameraDetailSchema = void 0;
13
- const zod_1 = require("zod");
14
- const common_1 = require("../internal/common");
1
+ import { z } from 'zod';
2
+ import { responseStringify, pad } from '../internal/common';
15
3
  const ACTION = 'AddCameraBookmark';
16
4
  const GET_CAMERAS_URL = 'report/EntityConfiguration?q=EntityTypes@Camera';
17
5
  const GET_CAMERAS_DETAILS_URL = '/entity?q=';
18
- const cameraGuidsResponseSchema = zod_1.z.object({
19
- Rsp: zod_1.z.object({
20
- Status: zod_1.z.string(),
21
- Result: zod_1.z.array(zod_1.z.object({ Guid: zod_1.z.string() })),
6
+ const cameraGuidsResponseSchema = z.object({
7
+ Rsp: z.object({
8
+ Status: z.string(),
9
+ Result: z.array(z.object({ Guid: z.string() })),
22
10
  }),
23
11
  });
24
- const connectionResponseSchema = zod_1.z.object({
25
- Rsp: zod_1.z.object({
26
- Status: zod_1.z.string(),
12
+ const connectionResponseSchema = z.object({
13
+ Rsp: z.object({
14
+ Status: z.string(),
27
15
  }),
28
16
  });
29
- exports.cameraDetailSchema = zod_1.z.object({
30
- Guid: zod_1.z.string().optional(),
31
- Name: zod_1.z.string().optional(),
32
- EntityType: zod_1.z.string().optional(),
17
+ export const cameraDetailSchema = z.object({
18
+ Guid: z.string().optional(),
19
+ Name: z.string().optional(),
20
+ EntityType: z.string().optional(),
33
21
  });
34
- exports.cameraDetailsResponseSchema = zod_1.z.object({
35
- Rsp: zod_1.z.object({
36
- Status: zod_1.z.string(),
37
- Result: zod_1.z.union([zod_1.z.array(exports.cameraDetailSchema), exports.cameraDetailSchema]),
22
+ export const cameraDetailsResponseSchema = z.object({
23
+ Rsp: z.object({
24
+ Status: z.string(),
25
+ Result: z.union([z.array(cameraDetailSchema), cameraDetailSchema]),
38
26
  }),
39
27
  });
40
- class GenetecAgent {
28
+ export class GenetecAgent {
29
+ settings;
30
+ baseUrl;
31
+ credentials;
41
32
  constructor(options = {}) {
42
- var _a, _b, _c, _d, _e, _f, _g;
43
33
  this.settings = {
44
- protocol: (_a = options.protocol) !== null && _a !== void 0 ? _a : 'http',
45
- ip: (_b = options.ip) !== null && _b !== void 0 ? _b : '127.0.0.1',
46
- port: (_c = options.port) !== null && _c !== void 0 ? _c : 80,
47
- base_uri: (_d = options.base_uri) !== null && _d !== void 0 ? _d : 'WebSdk',
48
- user: (_e = options.user) !== null && _e !== void 0 ? _e : 'root',
49
- pass: (_f = options.pass) !== null && _f !== void 0 ? _f : '',
50
- app_id: (_g = options.app_id) !== null && _g !== void 0 ? _g : '',
34
+ protocol: options.protocol ?? 'http',
35
+ ip: options.ip ?? '127.0.0.1',
36
+ port: options.port ?? 80,
37
+ base_uri: options.base_uri ?? 'WebSdk',
38
+ user: options.user ?? 'root',
39
+ pass: options.pass ?? '',
40
+ app_id: options.app_id ?? '',
51
41
  };
52
42
  this.baseUrl = `${this.settings.protocol}://${this.settings.ip}:${this.settings.port}/${this.settings.base_uri}`;
53
43
  this.credentials = btoa(`${this.settings.user};${this.settings.app_id}:${this.settings.pass}`);
54
44
  }
55
- checkConnection() {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const requestOptions = this.getRequestOptions('GET');
58
- const res = yield fetch(`${this.baseUrl}/`, requestOptions);
59
- if (!res.ok) {
60
- throw new Error(yield (0, common_1.responseStringify)(res));
61
- }
62
- return connectionResponseSchema.parse(yield res.json());
63
- });
45
+ async checkConnection() {
46
+ const requestOptions = this.getRequestOptions('GET');
47
+ const res = await fetch(`${this.baseUrl}/`, requestOptions);
48
+ if (!res.ok) {
49
+ throw new Error(await responseStringify(res));
50
+ }
51
+ return connectionResponseSchema.parse(await res.json());
64
52
  }
65
- getAllCameraGuids() {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const requestOptions = this.getRequestOptions('GET');
68
- const res = yield fetch(`${this.baseUrl}/${GET_CAMERAS_URL}`, requestOptions);
69
- if (!res.ok) {
70
- throw new Error(yield (0, common_1.responseStringify)(res));
71
- }
72
- return cameraGuidsResponseSchema.parse(yield res.json());
73
- });
53
+ async getAllCameraGuids() {
54
+ const requestOptions = this.getRequestOptions('GET');
55
+ const res = await fetch(`${this.baseUrl}/${GET_CAMERAS_URL}`, requestOptions);
56
+ if (!res.ok) {
57
+ throw new Error(await responseStringify(res));
58
+ }
59
+ return cameraGuidsResponseSchema.parse(await res.json());
74
60
  }
75
- getCameraDetails(guids, parameters) {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- const params = parameters.join(',');
78
- let camerasGuids = [];
79
- const requestOptions = this.getRequestOptions('GET');
80
- const allCameras = [];
81
- const chunkSize = 10;
82
- while (guids.length > 0) {
83
- const chunk = guids.slice(0, chunkSize);
84
- guids.splice(0, chunkSize);
85
- camerasGuids = chunk.map((item) => item.Guid);
86
- const camerasDetailsUrl = [];
87
- for (const guid of camerasGuids) {
88
- camerasDetailsUrl.push(`entity=${guid},${params}`);
89
- }
90
- const res = yield fetch(`${this.baseUrl}/${GET_CAMERAS_DETAILS_URL}${camerasDetailsUrl.join(',')}`, requestOptions);
91
- if (!res.ok) {
92
- throw new Error(yield (0, common_1.responseStringify)(res));
93
- }
94
- const data = exports.cameraDetailsResponseSchema.parse(yield res.json());
95
- const resultArray = Array.isArray(data.Rsp.Result) ? data.Rsp.Result : [data.Rsp.Result];
96
- allCameras.push(...resultArray);
61
+ async getCameraDetails(guids, parameters) {
62
+ const params = parameters.join(',');
63
+ let camerasGuids = [];
64
+ const requestOptions = this.getRequestOptions('GET');
65
+ const allCameras = [];
66
+ const chunkSize = 10;
67
+ while (guids.length > 0) {
68
+ const chunk = guids.slice(0, chunkSize);
69
+ guids.splice(0, chunkSize);
70
+ camerasGuids = chunk.map((item) => item.Guid);
71
+ const camerasDetailsUrl = [];
72
+ for (const guid of camerasGuids) {
73
+ camerasDetailsUrl.push(`entity=${guid},${params}`);
97
74
  }
98
- return allCameras;
99
- });
100
- }
101
- sendBookmark(guids, bookmarkText) {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- const cameraEntitiesUrl = [];
104
- const timeStamp = this.getTimeStamp();
105
- const requestOptions = this.getRequestOptions('POST');
106
- for (const guid of guids) {
107
- cameraEntitiesUrl.push(`${ACTION}(${guid},${timeStamp},${bookmarkText})`);
108
- }
109
- const res = yield fetch(`${this.baseUrl}/action?q=${cameraEntitiesUrl.join(',')}`, requestOptions);
75
+ const res = await fetch(`${this.baseUrl}/${GET_CAMERAS_DETAILS_URL}${camerasDetailsUrl.join(',')}`, requestOptions);
110
76
  if (!res.ok) {
111
- throw new Error(yield (0, common_1.responseStringify)(res));
77
+ throw new Error(await responseStringify(res));
112
78
  }
113
- return res;
114
- });
79
+ const data = cameraDetailsResponseSchema.parse(await res.json());
80
+ const resultArray = Array.isArray(data.Rsp.Result) ? data.Rsp.Result : [data.Rsp.Result];
81
+ allCameras.push(...resultArray);
82
+ }
83
+ return allCameras;
84
+ }
85
+ async sendBookmark(guids, bookmarkText) {
86
+ const cameraEntitiesUrl = [];
87
+ const timeStamp = this.getTimeStamp();
88
+ const requestOptions = this.getRequestOptions('POST');
89
+ for (const guid of guids) {
90
+ cameraEntitiesUrl.push(`${ACTION}(${guid},${timeStamp},${bookmarkText})`);
91
+ }
92
+ const res = await fetch(`${this.baseUrl}/action?q=${cameraEntitiesUrl.join(',')}`, requestOptions);
93
+ if (!res.ok) {
94
+ throw new Error(await responseStringify(res));
95
+ }
96
+ return res;
115
97
  }
116
98
  getRequestOptions(method) {
117
99
  return {
@@ -126,13 +108,12 @@ class GenetecAgent {
126
108
  getTimeStamp() {
127
109
  const date = new Date();
128
110
  const year = date.getUTCFullYear();
129
- const month = (0, common_1.pad)(date.getUTCMonth() + 1, 2);
130
- const day = (0, common_1.pad)(date.getUTCDate(), 2);
131
- const hours = (0, common_1.pad)(date.getUTCHours(), 2);
132
- const minutes = (0, common_1.pad)(date.getUTCMinutes(), 2);
133
- const seconds = (0, common_1.pad)(date.getUTCSeconds(), 2);
134
- const miliSeconds = (0, common_1.pad)(date.getUTCMilliseconds(), 2);
111
+ const month = pad(date.getUTCMonth() + 1, 2);
112
+ const day = pad(date.getUTCDate(), 2);
113
+ const hours = pad(date.getUTCHours(), 2);
114
+ const minutes = pad(date.getUTCMinutes(), 2);
115
+ const seconds = pad(date.getUTCSeconds(), 2);
116
+ const miliSeconds = pad(date.getUTCMilliseconds(), 2);
135
117
  return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${miliSeconds}Z`;
136
118
  }
137
119
  }
138
- exports.GenetecAgent = GenetecAgent;
@@ -1,11 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Digest = void 0;
4
- const crypto = require("crypto");
5
- class Digest {
6
- constructor() {
7
- this.nonceCount = 1;
8
- }
1
+ import * as crypto from 'crypto';
2
+ export class Digest {
3
+ nonceCount = 1;
9
4
  getAuthHeader(user, pass, method, uri, wwwAuthenticateHeader) {
10
5
  const digestItems = {};
11
6
  const digestArr = wwwAuthenticateHeader.substring(wwwAuthenticateHeader.indexOf('Digest') + 6).split(',');
@@ -19,7 +14,7 @@ class Digest {
19
14
  const HA2 = crypto.createHash('md5').update(`${method}:${uri}`).digest('hex');
20
15
  const ncValue = ('00000000' + this.nonceCount.toString(16)).slice(-8);
21
16
  let response;
22
- if (digestItems['qop'] !== undefined) {
17
+ if (digestItems['qop']) {
23
18
  response = crypto
24
19
  .createHash('md5')
25
20
  .update(`${HA1}:${digestItems['nonce']}:${ncValue}:162d50aa594e9648:auth:${HA2}`)
@@ -34,11 +29,10 @@ class Digest {
34
29
  `nonce="${digestItems['nonce']}",` +
35
30
  `uri="${uri}",` +
36
31
  `response="${response}"`;
37
- if (digestItems['qop'] !== undefined) {
32
+ if (digestItems['qop']) {
38
33
  header += `,qop=auth,nc=${ncValue},cnonce="162d50aa594e9648"`;
39
34
  }
40
35
  this.nonceCount++;
41
36
  return header;
42
37
  }
43
38
  }
44
- exports.Digest = Digest;
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import { IClient, TParameters } from './common';
3
+ import { TProxyParam } from '../types/common';
4
+ export declare class ProxyClient<Client extends IClient = IClient> {
5
+ client: Client;
6
+ getProxyUrl: () => string;
7
+ constructor(client: Client, getProxyUrl: () => string);
8
+ get: (proxy: TProxyParam, path: string, parameters?: TParameters, headers?: Record<string, string>) => Promise<import("./common").TResponse>;
9
+ post: (proxy: TProxyParam, path: string, data: string | Buffer | FormData, parameters?: TParameters, headers?: Record<string, string>) => Promise<import("./common").TResponse>;
10
+ private getReal;
11
+ }
@@ -0,0 +1,40 @@
1
+ import { addParametersToPath } from './utils';
2
+ export class ProxyClient {
3
+ client;
4
+ getProxyUrl;
5
+ constructor(client, getProxyUrl) {
6
+ this.client = client;
7
+ this.getProxyUrl = getProxyUrl;
8
+ }
9
+ get = (proxy, path, parameters, headers = {}) => {
10
+ const url = addParametersToPath(path, parameters);
11
+ const { realUrl, realHeaders } = this.getReal(proxy, url, headers);
12
+ return this.client.get(realUrl, {}, realHeaders);
13
+ };
14
+ post = (proxy, path, data, parameters, headers) => {
15
+ const url = addParametersToPath(path, parameters);
16
+ const { realUrl, realHeaders } = this.getReal(proxy, url, headers);
17
+ return this.client.post(realUrl, data, {}, realHeaders);
18
+ };
19
+ getReal = (proxy, url, headers) => {
20
+ if (proxy !== null) {
21
+ return {
22
+ realUrl: this.getProxyUrl(),
23
+ realHeaders: {
24
+ ...(headers ?? {}),
25
+ 'x-target-camera-protocol': proxy.port === 443 ? 'https' : 'http',
26
+ 'x-target-camera-path': url,
27
+ 'x-target-camera-ip': proxy.ip,
28
+ 'x-target-camera-mdns': proxy.mdnsName,
29
+ 'x-target-camera-port': String(proxy.port),
30
+ 'x-target-camera-pass': encodeURIComponent(proxy.pass),
31
+ 'x-target-camera-user': encodeURIComponent(proxy.user),
32
+ },
33
+ };
34
+ }
35
+ return {
36
+ realUrl: url,
37
+ realHeaders: headers,
38
+ };
39
+ };
40
+ }
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  type Options = {
4
3
  ip?: string;
5
4
  port?: number;
@@ -12,14 +11,30 @@ export type HttpOptions = Options & {
12
11
  keepAlive?: boolean;
13
12
  };
14
13
  export type WsOptions = Options;
15
- export type TGetFunction = (url: string, parameters?: Record<string, string>, headers?: Record<string, string>) => Promise<Response>;
16
- export type TPostFunction = (url: string, data: string | Buffer | FormData, parameters?: Record<string, string>, headers?: Record<string, string>) => Promise<Response>;
14
+ export type TResponse = {
15
+ ok: boolean;
16
+ json: () => Promise<any>;
17
+ text: () => Promise<string>;
18
+ status: number;
19
+ body: any | null;
20
+ };
21
+ export type TParameters = Record<string, string | number | boolean | null | undefined>;
22
+ export type TGetFunction = (url: string, parameters?: TParameters, headers?: Record<string, string>) => Promise<TResponse>;
23
+ export type TPostFunction = (url: string, data: string | Buffer | FormData, parameters?: TParameters, headers?: Record<string, string>) => Promise<TResponse>;
17
24
  export interface IClient {
18
25
  get: TGetFunction;
19
26
  post: TPostFunction;
20
27
  }
28
+ export interface IWebsocket<Event extends {
29
+ readonly data: string;
30
+ }> {
31
+ destroy: () => void;
32
+ onmessage: null | ((event: Event) => void);
33
+ send: (data: string) => void;
34
+ }
21
35
  export declare function isClient(arg?: Options | IClient): arg is IClient;
22
36
  export declare function isBrowserEnvironment(): boolean;
23
- export declare function responseStringify(res: Response): Promise<string>;
37
+ export declare function responseStringify(res: TResponse): Promise<string>;
24
38
  export declare function pad(num: number, size: number): string;
39
+ export declare function isNullish<T>(value: T | undefined | null): value is undefined | null;
25
40
  export {};
@@ -1,33 +1,16 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.pad = exports.responseStringify = exports.isBrowserEnvironment = exports.isClient = void 0;
13
- function isClient(arg = {}) {
1
+ export function isClient(arg = {}) {
14
2
  return 'get' in arg && 'post' in arg;
15
3
  }
16
- exports.isClient = isClient;
17
- function isBrowserEnvironment() {
18
- return typeof process === 'undefined' || process.versions === null || process.versions.node === null;
4
+ export function isBrowserEnvironment() {
5
+ return typeof process === 'undefined' || !process.versions.node;
19
6
  }
20
- exports.isBrowserEnvironment = isBrowserEnvironment;
21
- function responseStringify(res) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- return JSON.stringify({
24
- status: res.status,
25
- body: yield res.text(),
26
- });
7
+ export async function responseStringify(res) {
8
+ return JSON.stringify({
9
+ status: res.status,
10
+ body: await res.text(),
27
11
  });
28
12
  }
29
- exports.responseStringify = responseStringify;
30
- function pad(num, size) {
13
+ export function pad(num, size) {
31
14
  const sign = Math.sign(num) === -1 ? '-' : '';
32
15
  return (sign +
33
16
  new Array(size)
@@ -35,4 +18,6 @@ function pad(num, size) {
35
18
  .join('0')
36
19
  .slice(-size));
37
20
  }
38
- exports.pad = pad;
21
+ export function isNullish(value) {
22
+ return value === null || value === undefined;
23
+ }
@@ -0,0 +1 @@
1
+ export declare const FIRMWARE_WITH_BITRATE_MODES_SUPPORT = "11.11.73";
@@ -0,0 +1 @@
1
+ export const FIRMWARE_WITH_BITRATE_MODES_SUPPORT = '11.11.73';