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.
- package/CamOverlayAPI.d.ts +11 -28
- package/CamOverlayAPI.js +116 -138
- package/CamOverlayDrawingAPI.js +26 -18
- package/CamOverlayPainter/Frame.js +167 -182
- package/CamOverlayPainter/Painter.js +80 -101
- package/CamOverlayPainter/ResourceManager.js +31 -46
- package/CamScripterAPI.d.ts +19 -0
- package/CamScripterAPI.js +66 -0
- package/CamScripterAPICameraEventsGenerator.js +22 -16
- package/CamStreamerAPI.d.ts +5 -27
- package/CamStreamerAPI.js +45 -71
- package/CamSwitcherAPI.d.ts +38 -71
- package/CamSwitcherAPI.js +329 -91
- package/CamSwitcherEvents.d.ts +15 -33
- package/CamSwitcherEvents.js +53 -97
- package/CreatePackage.js +5 -7
- package/README.md +3 -1
- package/VapixAPI.d.ts +66 -0
- package/VapixAPI.js +454 -0
- package/VapixEvents.js +18 -16
- package/errors/errors.d.ts +34 -0
- package/errors/errors.js +66 -0
- package/events/AxisCameraStationEvents.js +29 -42
- package/events/GenetecAgent.d.ts +14 -15
- package/events/GenetecAgent.js +81 -100
- package/internal/Digest.js +5 -11
- package/internal/ProxyClient.d.ts +11 -0
- package/internal/ProxyClient.js +40 -0
- package/internal/common.d.ts +19 -4
- package/internal/common.js +11 -26
- package/internal/constants.d.ts +1 -0
- package/internal/constants.js +1 -0
- package/internal/transformers.d.ts +5 -0
- package/internal/transformers.js +25 -0
- package/internal/utils.d.ts +11 -0
- package/internal/utils.js +34 -0
- package/internal/versionCompare.d.ts +6 -0
- package/internal/versionCompare.js +44 -0
- package/node/DefaultClient.d.ts +15 -0
- package/node/DefaultClient.js +50 -0
- package/{internal → node}/HttpRequestSender.d.ts +2 -2
- package/node/HttpRequestSender.js +85 -0
- package/{HttpServer.d.ts → node/HttpServer.d.ts} +1 -1
- package/{HttpServer.js → node/HttpServer.js} +22 -24
- package/{internal → node}/WsClient.d.ts +1 -1
- package/{internal → node}/WsClient.js +32 -39
- package/node/WsEventClient.d.ts +13 -0
- package/node/WsEventClient.js +18 -0
- package/package.json +7 -3
- package/types/CamOverlayAPI.d.ts +188 -0
- package/types/CamOverlayAPI.js +44 -0
- package/types/CamScripterAPI.d.ts +67 -0
- package/types/CamScripterAPI.js +17 -0
- package/types/CamStreamerAPI.d.ts +139 -0
- package/types/CamStreamerAPI.js +25 -0
- package/types/CamSwitcherAPI.d.ts +814 -0
- package/types/CamSwitcherAPI.js +134 -0
- package/types/CamswitcherEvents.d.ts +491 -0
- package/types/CamswitcherEvents.js +59 -0
- package/types/VapixAPI.d.ts +1704 -0
- package/types/VapixAPI.js +129 -0
- package/types/common.d.ts +37 -0
- package/types/common.js +11 -0
- package/web/DefaultClient.d.ts +6 -0
- package/web/DefaultClient.js +16 -0
- package/web/WsClient.d.ts +13 -0
- package/web/WsClient.js +58 -0
- package/CameraVapix.d.ts +0 -98
- package/CameraVapix.js +0 -441
- package/DefaultAgent.d.ts +0 -15
- package/DefaultAgent.js +0 -68
- package/internal/HttpRequestSender.js +0 -117
package/errors/errors.js
ADDED
|
@@ -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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 (
|
|
8
|
+
if (isClient(opt)) {
|
|
19
9
|
this.client = opt;
|
|
20
10
|
}
|
|
21
11
|
else {
|
|
22
|
-
this.client = new
|
|
12
|
+
this.client = new DefaultClient(opt);
|
|
23
13
|
}
|
|
24
14
|
}
|
|
25
|
-
sendEvent(data, eventType) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 =
|
|
50
|
-
const day =
|
|
51
|
-
const hours =
|
|
52
|
-
const minutes =
|
|
53
|
-
const seconds =
|
|
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;
|
package/events/GenetecAgent.d.ts
CHANGED
|
@@ -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
|
};
|
package/events/GenetecAgent.js
CHANGED
|
@@ -1,117 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 =
|
|
19
|
-
Rsp:
|
|
20
|
-
Status:
|
|
21
|
-
Result:
|
|
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 =
|
|
25
|
-
Rsp:
|
|
26
|
-
Status:
|
|
12
|
+
const connectionResponseSchema = z.object({
|
|
13
|
+
Rsp: z.object({
|
|
14
|
+
Status: z.string(),
|
|
27
15
|
}),
|
|
28
16
|
});
|
|
29
|
-
|
|
30
|
-
Guid:
|
|
31
|
-
Name:
|
|
32
|
-
EntityType:
|
|
17
|
+
export const cameraDetailSchema = z.object({
|
|
18
|
+
Guid: z.string().optional(),
|
|
19
|
+
Name: z.string().optional(),
|
|
20
|
+
EntityType: z.string().optional(),
|
|
33
21
|
});
|
|
34
|
-
|
|
35
|
-
Rsp:
|
|
36
|
-
Status:
|
|
37
|
-
Result:
|
|
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:
|
|
45
|
-
ip:
|
|
46
|
-
port:
|
|
47
|
-
base_uri:
|
|
48
|
-
user:
|
|
49
|
-
pass:
|
|
50
|
-
app_id:
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
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(
|
|
77
|
+
throw new Error(await responseStringify(res));
|
|
112
78
|
}
|
|
113
|
-
|
|
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 =
|
|
130
|
-
const day =
|
|
131
|
-
const hours =
|
|
132
|
-
const minutes =
|
|
133
|
-
const seconds =
|
|
134
|
-
const miliSeconds =
|
|
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;
|
package/internal/Digest.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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']
|
|
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']
|
|
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
|
+
}
|
package/internal/common.d.ts
CHANGED
|
@@ -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
|
|
16
|
-
|
|
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:
|
|
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 {};
|
package/internal/common.js
CHANGED
|
@@ -1,33 +1,16 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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';
|