camstreamerlib 4.0.0-beta.2 → 4.0.0-beta.20
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/README.md +5 -1
- package/cjs/CamOverlayAPI.d.ts +629 -0
- package/cjs/CamOverlayAPI.js +255 -0
- package/{CamOverlayDrawingAPI.d.ts → cjs/CamOverlayDrawingAPI.d.ts} +1 -1
- package/cjs/CamOverlayDrawingAPI.js +235 -0
- package/cjs/CamOverlayPainter/Frame.js +301 -0
- package/{CamOverlayPainter → cjs/CamOverlayPainter}/Painter.d.ts +14 -3
- package/cjs/CamOverlayPainter/Painter.js +171 -0
- package/cjs/CamOverlayPainter/ResourceManager.js +46 -0
- package/{CamScripterAPI.d.ts → cjs/CamScripterAPI.d.ts} +5 -5
- package/cjs/CamScripterAPI.js +64 -0
- package/{CamScripterAPICameraEventsGenerator.d.ts → cjs/CamScripterAPICameraEventsGenerator.d.ts} +1 -1
- package/cjs/CamScripterAPICameraEventsGenerator.js +162 -0
- package/{CamStreamerAPI.d.ts → cjs/CamStreamerAPI.d.ts} +5 -5
- package/cjs/CamStreamerAPI.js +59 -0
- package/{CamSwitcherAPI.d.ts → cjs/CamSwitcherAPI.d.ts} +10 -6
- package/cjs/CamSwitcherAPI.js +351 -0
- package/{CamSwitcherEvents.d.ts → cjs/CamSwitcherEvents.d.ts} +2 -2
- package/cjs/CamSwitcherEvents.js +67 -0
- package/cjs/CreatePackage.js +106 -0
- package/cjs/PlaneTrackerAPI.d.ts +47 -0
- package/cjs/PlaneTrackerAPI.js +176 -0
- package/{VapixAPI.d.ts → cjs/VapixAPI.d.ts} +19 -7
- package/cjs/VapixAPI.js +491 -0
- package/{VapixEvents.d.ts → cjs/VapixEvents.d.ts} +1 -1
- package/cjs/VapixEvents.js +88 -0
- package/{errors → cjs/errors}/errors.d.ts +3 -0
- package/cjs/errors/errors.js +86 -0
- package/{events → cjs/events}/AxisCameraStationEvents.d.ts +3 -2
- package/cjs/events/AxisCameraStationEvents.js +48 -0
- package/{events → cjs/events}/GenetecAgent.d.ts +4 -3
- package/cjs/events/GenetecAgent.js +123 -0
- package/cjs/index.d.ts +18 -0
- package/cjs/index.js +42 -0
- package/cjs/internal/Digest.js +42 -0
- package/cjs/internal/ProxyClient.d.ts +11 -0
- package/cjs/internal/ProxyClient.js +46 -0
- package/cjs/internal/constants.js +4 -0
- package/cjs/internal/transformers.js +32 -0
- package/cjs/internal/types.d.ts +35 -0
- package/cjs/internal/types.js +2 -0
- package/{internal → cjs/internal}/utils.d.ts +5 -1
- package/cjs/internal/utils.js +69 -0
- package/{internal → cjs/internal}/versionCompare.d.ts +2 -2
- package/cjs/internal/versionCompare.js +53 -0
- package/cjs/models/CamOverlayAPI/accuweatherSchema.d.ts +84 -0
- package/cjs/models/CamOverlayAPI/accuweatherSchema.js +48 -0
- package/cjs/models/CamOverlayAPI/constants.d.ts +11 -0
- package/cjs/models/CamOverlayAPI/constants.js +14 -0
- package/cjs/models/CamOverlayAPI/customGraphicsSchema.d.ts +699 -0
- package/cjs/models/CamOverlayAPI/customGraphicsSchema.js +73 -0
- package/cjs/models/CamOverlayAPI/fileSchema.d.ts +28 -0
- package/cjs/models/CamOverlayAPI/fileSchema.js +17 -0
- package/cjs/models/CamOverlayAPI/imagesSchema.d.ts +95 -0
- package/cjs/models/CamOverlayAPI/imagesSchema.js +10 -0
- package/cjs/models/CamOverlayAPI/index.d.ts +13 -0
- package/cjs/models/CamOverlayAPI/index.js +29 -0
- package/cjs/models/CamOverlayAPI/infotickerSchema.d.ts +96 -0
- package/cjs/models/CamOverlayAPI/infotickerSchema.js +27 -0
- package/cjs/models/CamOverlayAPI/pipSchema.d.ts +125 -0
- package/cjs/models/CamOverlayAPI/pipSchema.js +40 -0
- package/cjs/models/CamOverlayAPI/ptzCompassSchema.d.ts +93 -0
- package/cjs/models/CamOverlayAPI/ptzCompassSchema.js +26 -0
- package/cjs/models/CamOverlayAPI/ptzSchema.d.ts +118 -0
- package/cjs/models/CamOverlayAPI/ptzSchema.js +13 -0
- package/cjs/models/CamOverlayAPI/screenSharingSchema.d.ts +58 -0
- package/cjs/models/CamOverlayAPI/screenSharingSchema.js +9 -0
- package/cjs/models/CamOverlayAPI/webCameraSharingSchema.d.ts +58 -0
- package/cjs/models/CamOverlayAPI/webCameraSharingSchema.js +9 -0
- package/cjs/models/CamOverlayAPI/widgetCommonSchema.d.ts +126 -0
- package/cjs/models/CamOverlayAPI/widgetCommonSchema.js +76 -0
- package/cjs/models/CamOverlayAPI/widgetsSchema.d.ts +2823 -0
- package/cjs/models/CamOverlayAPI/widgetsSchema.js +27 -0
- package/cjs/node/DefaultClient.d.ts +16 -0
- package/cjs/node/DefaultClient.js +56 -0
- package/cjs/node/HttpRequestSender.js +89 -0
- package/cjs/node/HttpServer.js +96 -0
- package/{node → cjs/node}/WsClient.d.ts +1 -1
- package/cjs/node/WsClient.js +149 -0
- package/{node → cjs/node}/WsEventClient.d.ts +1 -1
- package/cjs/node/WsEventClient.js +22 -0
- package/cjs/node/index.d.ts +2 -0
- package/cjs/node/index.js +7 -0
- package/cjs/types/CamOverlayAPI.d.ts +328 -0
- package/cjs/types/CamOverlayAPI.js +26 -0
- package/{types → cjs/types}/CamScripterAPI.d.ts +55 -7
- package/cjs/types/CamScripterAPI.js +31 -0
- package/{types → cjs/types}/CamStreamerAPI.d.ts +16 -5
- package/cjs/types/CamStreamerAPI.js +32 -0
- package/{types → cjs/types}/CamSwitcherAPI.d.ts +5 -5
- package/cjs/types/CamSwitcherAPI.js +137 -0
- package/{types/CamswitcherEvents.d.ts → cjs/types/CamSwitcherEvents.d.ts} +77 -0
- package/cjs/types/CamSwitcherEvents.js +70 -0
- package/cjs/types/PlaneTrackerAPI.d.ts +2 -0
- package/cjs/types/PlaneTrackerAPI.js +2 -0
- package/{types → cjs/types}/VapixAPI.d.ts +479 -519
- package/cjs/types/VapixAPI.js +139 -0
- package/cjs/types/common.js +14 -0
- package/cjs/web/DefaultClient.d.ts +6 -0
- package/cjs/web/DefaultClient.js +22 -0
- package/cjs/web/WsClient.js +62 -0
- package/cjs/web/index.d.ts +2 -0
- package/cjs/web/index.js +7 -0
- package/esm/CamOverlayAPI.d.ts +629 -0
- package/esm/CamOverlayAPI.js +251 -0
- package/esm/CamOverlayDrawingAPI.d.ts +86 -0
- package/{CamOverlayDrawingAPI.js → esm/CamOverlayDrawingAPI.js} +6 -3
- package/esm/CamOverlayPainter/Frame.d.ts +96 -0
- package/esm/CamOverlayPainter/Painter.d.ts +48 -0
- package/{CamOverlayPainter → esm/CamOverlayPainter}/Painter.js +4 -1
- package/esm/CamOverlayPainter/ResourceManager.d.ts +14 -0
- package/{CamOverlayPainter → esm/CamOverlayPainter}/ResourceManager.js +6 -10
- package/esm/CamScripterAPI.d.ts +19 -0
- package/{CamScripterAPI.js → esm/CamScripterAPI.js} +4 -10
- package/esm/CamScripterAPICameraEventsGenerator.d.ts +74 -0
- package/{CamScripterAPICameraEventsGenerator.js → esm/CamScripterAPICameraEventsGenerator.js} +6 -3
- package/esm/CamStreamerAPI.d.ts +16 -0
- package/{CamStreamerAPI.js → esm/CamStreamerAPI.js} +4 -10
- package/esm/CamSwitcherAPI.d.ts +52 -0
- package/{CamSwitcherAPI.js → esm/CamSwitcherAPI.js} +24 -27
- package/esm/CamSwitcherEvents.d.ts +18 -0
- package/{CamSwitcherEvents.js → esm/CamSwitcherEvents.js} +1 -1
- package/esm/CreatePackage.d.ts +1 -0
- package/esm/PlaneTrackerAPI.d.ts +47 -0
- package/esm/PlaneTrackerAPI.js +172 -0
- package/esm/VapixAPI.d.ts +78 -0
- package/{VapixAPI.js → esm/VapixAPI.js} +93 -60
- package/esm/VapixEvents.d.ts +43 -0
- package/{VapixEvents.js → esm/VapixEvents.js} +3 -3
- package/esm/errors/errors.d.ts +37 -0
- package/{errors → esm/errors}/errors.js +6 -0
- package/esm/events/AxisCameraStationEvents.d.ts +10 -0
- package/{events → esm/events}/AxisCameraStationEvents.js +1 -1
- package/esm/events/GenetecAgent.d.ts +175 -0
- package/{events → esm/events}/GenetecAgent.js +5 -5
- package/esm/index.d.ts +18 -0
- package/esm/index.js +18 -0
- package/esm/internal/Digest.d.ts +4 -0
- package/{internal → esm/internal}/Digest.js +6 -6
- package/esm/internal/ProxyClient.d.ts +11 -0
- package/{internal → esm/internal}/ProxyClient.js +6 -4
- package/esm/internal/constants.d.ts +1 -0
- package/esm/internal/transformers.d.ts +5 -0
- package/esm/internal/types.d.ts +35 -0
- package/esm/internal/types.js +1 -0
- package/esm/internal/utils.d.ts +15 -0
- package/{internal → esm/internal}/utils.js +20 -1
- package/esm/internal/versionCompare.d.ts +6 -0
- package/esm/models/CamOverlayAPI/accuweatherSchema.d.ts +84 -0
- package/esm/models/CamOverlayAPI/accuweatherSchema.js +45 -0
- package/esm/models/CamOverlayAPI/constants.d.ts +11 -0
- package/esm/models/CamOverlayAPI/constants.js +11 -0
- package/esm/models/CamOverlayAPI/customGraphicsSchema.d.ts +699 -0
- package/esm/models/CamOverlayAPI/customGraphicsSchema.js +70 -0
- package/esm/models/CamOverlayAPI/fileSchema.d.ts +28 -0
- package/esm/models/CamOverlayAPI/fileSchema.js +14 -0
- package/esm/models/CamOverlayAPI/imagesSchema.d.ts +95 -0
- package/esm/models/CamOverlayAPI/imagesSchema.js +7 -0
- package/esm/models/CamOverlayAPI/index.d.ts +13 -0
- package/esm/models/CamOverlayAPI/index.js +13 -0
- package/esm/models/CamOverlayAPI/infotickerSchema.d.ts +96 -0
- package/esm/models/CamOverlayAPI/infotickerSchema.js +24 -0
- package/esm/models/CamOverlayAPI/pipSchema.d.ts +125 -0
- package/esm/models/CamOverlayAPI/pipSchema.js +37 -0
- package/esm/models/CamOverlayAPI/ptzCompassSchema.d.ts +93 -0
- package/esm/models/CamOverlayAPI/ptzCompassSchema.js +23 -0
- package/esm/models/CamOverlayAPI/ptzSchema.d.ts +118 -0
- package/esm/models/CamOverlayAPI/ptzSchema.js +10 -0
- package/esm/models/CamOverlayAPI/screenSharingSchema.d.ts +58 -0
- package/esm/models/CamOverlayAPI/screenSharingSchema.js +6 -0
- package/esm/models/CamOverlayAPI/webCameraSharingSchema.d.ts +58 -0
- package/esm/models/CamOverlayAPI/webCameraSharingSchema.js +6 -0
- package/esm/models/CamOverlayAPI/widgetCommonSchema.d.ts +126 -0
- package/esm/models/CamOverlayAPI/widgetCommonSchema.js +73 -0
- package/esm/models/CamOverlayAPI/widgetsSchema.d.ts +2823 -0
- package/esm/models/CamOverlayAPI/widgetsSchema.js +24 -0
- package/esm/node/DefaultClient.d.ts +16 -0
- package/{node → esm/node}/DefaultClient.js +9 -7
- package/esm/node/HttpRequestSender.d.ts +28 -0
- package/esm/node/HttpServer.d.ts +21 -0
- package/{node → esm/node}/HttpServer.js +1 -1
- package/esm/node/WsClient.d.ts +39 -0
- package/esm/node/WsEventClient.d.ts +13 -0
- package/esm/node/index.d.ts +2 -0
- package/esm/node/index.js +2 -0
- package/esm/types/CamOverlayAPI.d.ts +328 -0
- package/esm/types/CamOverlayAPI.js +14 -0
- package/esm/types/CamScripterAPI.d.ts +115 -0
- package/esm/types/CamScripterAPI.js +28 -0
- package/esm/types/CamStreamerAPI.d.ts +150 -0
- package/{types → esm/types}/CamStreamerAPI.js +4 -0
- package/esm/types/CamSwitcherAPI.d.ts +814 -0
- package/esm/types/CamSwitcherEvents.d.ts +568 -0
- package/{types/CamswitcherEvents.js → esm/types/CamSwitcherEvents.js} +8 -0
- package/esm/types/PlaneTrackerAPI.d.ts +2 -0
- package/esm/types/PlaneTrackerAPI.js +1 -0
- package/esm/types/VapixAPI.d.ts +1664 -0
- package/{types → esm/types}/VapixAPI.js +30 -23
- package/esm/types/common.d.ts +37 -0
- package/esm/web/DefaultClient.d.ts +6 -0
- package/{web → esm/web}/DefaultClient.js +6 -4
- package/esm/web/WsClient.d.ts +13 -0
- package/{web → esm/web}/WsClient.js +2 -2
- package/esm/web/index.d.ts +2 -0
- package/esm/web/index.js +2 -0
- package/package.json +6 -6
- package/CamOverlayAPI.d.ts +0 -31
- package/CamOverlayAPI.js +0 -172
- package/internal/ProxyClient.d.ts +0 -11
- package/internal/common.d.ts +0 -40
- package/internal/common.js +0 -23
- package/node/DefaultClient.d.ts +0 -15
- package/types/CamOverlayAPI.d.ts +0 -188
- package/types/CamOverlayAPI.js +0 -44
- package/types/CamScripterAPI.js +0 -17
- package/web/DefaultClient.d.ts +0 -6
- package/{CamOverlayPainter → cjs/CamOverlayPainter}/Frame.d.ts +0 -0
- package/{CamOverlayPainter → cjs/CamOverlayPainter}/ResourceManager.d.ts +0 -0
- package/{CreatePackage.d.ts → cjs/CreatePackage.d.ts} +0 -0
- package/{internal → cjs/internal}/Digest.d.ts +0 -0
- package/{internal → cjs/internal}/constants.d.ts +0 -0
- package/{internal → cjs/internal}/transformers.d.ts +0 -0
- package/{node → cjs/node}/HttpRequestSender.d.ts +0 -0
- package/{node → cjs/node}/HttpServer.d.ts +0 -0
- package/{types → cjs/types}/common.d.ts +2 -2
- /package/{web → cjs/web}/WsClient.d.ts +0 -0
- /package/{CamOverlayPainter → esm/CamOverlayPainter}/Frame.js +0 -0
- /package/{CreatePackage.js → esm/CreatePackage.js} +0 -0
- /package/{internal → esm/internal}/constants.js +0 -0
- /package/{internal → esm/internal}/transformers.js +0 -0
- /package/{internal → esm/internal}/versionCompare.js +0 -0
- /package/{node → esm/node}/HttpRequestSender.js +0 -0
- /package/{node → esm/node}/WsClient.js +0 -0
- /package/{node → esm/node}/WsEventClient.js +0 -0
- /package/{types → esm/types}/CamSwitcherAPI.js +0 -0
- /package/{types → esm/types}/common.js +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { IClient, HttpOptions } from '../internal/
|
|
1
|
+
import { IClient, HttpOptions } from '../internal/types';
|
|
2
|
+
import { Response } from 'undici';
|
|
2
3
|
export type AcsEventsOptions = HttpOptions;
|
|
3
4
|
export declare class AxisCameraStationEvents {
|
|
4
5
|
private sourceKey;
|
|
5
6
|
private client;
|
|
6
|
-
constructor(sourceKey: string, opt?: AcsEventsOptions | IClient);
|
|
7
|
+
constructor(sourceKey: string, opt?: AcsEventsOptions | IClient<Response>);
|
|
7
8
|
sendEvent(data: Record<string, string>, eventType: string): Promise<void>;
|
|
8
9
|
private getDate;
|
|
9
10
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AxisCameraStationEvents = void 0;
|
|
4
|
+
const DefaultClient_1 = require("../node/DefaultClient");
|
|
5
|
+
const utils_1 = require("../internal/utils");
|
|
6
|
+
class AxisCameraStationEvents {
|
|
7
|
+
sourceKey;
|
|
8
|
+
client;
|
|
9
|
+
constructor(sourceKey, opt = {}) {
|
|
10
|
+
this.sourceKey = sourceKey;
|
|
11
|
+
if ((0, utils_1.isClient)(opt)) {
|
|
12
|
+
this.client = opt;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
this.client = new DefaultClient_1.DefaultClient(opt);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async sendEvent(data, eventType) {
|
|
19
|
+
const dateString = this.getDate();
|
|
20
|
+
const event = {
|
|
21
|
+
addExternalDataRequest: {
|
|
22
|
+
occurrenceTime: dateString,
|
|
23
|
+
source: this.sourceKey,
|
|
24
|
+
externalDataType: eventType,
|
|
25
|
+
data: data,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const eventData = JSON.stringify(event);
|
|
29
|
+
const res = await this.client.post('/Acs/Api/ExternalDataFacade/AddExternalData', eventData, undefined, {
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
'Content-Length': eventData.length.toString(),
|
|
32
|
+
});
|
|
33
|
+
if (!res.ok) {
|
|
34
|
+
throw new Error(`ACS status code: ${res.status}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
getDate() {
|
|
38
|
+
const date = new Date();
|
|
39
|
+
const year = date.getUTCFullYear();
|
|
40
|
+
const month = (0, utils_1.pad)(date.getUTCMonth() + 1, 2);
|
|
41
|
+
const day = (0, utils_1.pad)(date.getUTCDate(), 2);
|
|
42
|
+
const hours = (0, utils_1.pad)(date.getUTCHours(), 2);
|
|
43
|
+
const minutes = (0, utils_1.pad)(date.getUTCMinutes(), 2);
|
|
44
|
+
const seconds = (0, utils_1.pad)(date.getUTCSeconds(), 2);
|
|
45
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.AxisCameraStationEvents = AxisCameraStationEvents;
|
|
@@ -148,14 +148,15 @@ export declare const cameraDetailsResponseSchema: z.ZodObject<{
|
|
|
148
148
|
export type TCameraDetailsResponse = z.infer<typeof cameraDetailsResponseSchema>;
|
|
149
149
|
export type TCameraDetail = z.infer<typeof cameraDetailSchema>;
|
|
150
150
|
export type TParams = Array<'Guid' | 'Name' | 'EntityType'>;
|
|
151
|
+
export type TProtocol = 'http' | 'https' | 'https_insecure';
|
|
151
152
|
export type GenetecAgentOptions = {
|
|
152
|
-
protocol?:
|
|
153
|
+
protocol?: TProtocol;
|
|
153
154
|
ip?: string;
|
|
154
155
|
port?: number;
|
|
155
|
-
|
|
156
|
+
baseUri?: string;
|
|
156
157
|
user?: string;
|
|
157
158
|
pass?: string;
|
|
158
|
-
|
|
159
|
+
appId?: string;
|
|
159
160
|
};
|
|
160
161
|
export declare class GenetecAgent {
|
|
161
162
|
private settings;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GenetecAgent = exports.cameraDetailsResponseSchema = exports.cameraDetailSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const utils_1 = require("../internal/utils");
|
|
6
|
+
const ACTION = 'AddCameraBookmark';
|
|
7
|
+
const GET_CAMERAS_URL = 'report/EntityConfiguration?q=EntityTypes@Camera';
|
|
8
|
+
const GET_CAMERAS_DETAILS_URL = '/entity?q=';
|
|
9
|
+
const cameraGuidsResponseSchema = zod_1.z.object({
|
|
10
|
+
Rsp: zod_1.z.object({
|
|
11
|
+
Status: zod_1.z.string(),
|
|
12
|
+
Result: zod_1.z.array(zod_1.z.object({ Guid: zod_1.z.string() })),
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
15
|
+
const connectionResponseSchema = zod_1.z.object({
|
|
16
|
+
Rsp: zod_1.z.object({
|
|
17
|
+
Status: zod_1.z.string(),
|
|
18
|
+
}),
|
|
19
|
+
});
|
|
20
|
+
exports.cameraDetailSchema = zod_1.z.object({
|
|
21
|
+
Guid: zod_1.z.string().optional(),
|
|
22
|
+
Name: zod_1.z.string().optional(),
|
|
23
|
+
EntityType: zod_1.z.string().optional(),
|
|
24
|
+
});
|
|
25
|
+
exports.cameraDetailsResponseSchema = zod_1.z.object({
|
|
26
|
+
Rsp: zod_1.z.object({
|
|
27
|
+
Status: zod_1.z.string(),
|
|
28
|
+
Result: zod_1.z.union([zod_1.z.array(exports.cameraDetailSchema), exports.cameraDetailSchema]),
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
class GenetecAgent {
|
|
32
|
+
settings;
|
|
33
|
+
baseUrl;
|
|
34
|
+
credentials;
|
|
35
|
+
constructor(options = {}) {
|
|
36
|
+
this.settings = {
|
|
37
|
+
protocol: options.protocol ?? 'http',
|
|
38
|
+
ip: options.ip ?? '127.0.0.1',
|
|
39
|
+
port: options.port ?? 80,
|
|
40
|
+
baseUri: options.baseUri ?? 'WebSdk',
|
|
41
|
+
user: options.user ?? 'root',
|
|
42
|
+
pass: options.pass ?? '',
|
|
43
|
+
appId: options.appId ?? '',
|
|
44
|
+
};
|
|
45
|
+
this.baseUrl = `${this.settings.protocol}://${this.settings.ip}:${this.settings.port}/${this.settings.baseUri}`;
|
|
46
|
+
this.credentials = btoa(`${this.settings.user};${this.settings.appId}:${this.settings.pass}`);
|
|
47
|
+
}
|
|
48
|
+
async checkConnection() {
|
|
49
|
+
const requestOptions = this.getRequestOptions('GET');
|
|
50
|
+
const res = await fetch(`${this.baseUrl}/`, requestOptions);
|
|
51
|
+
if (!res.ok) {
|
|
52
|
+
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
53
|
+
}
|
|
54
|
+
return connectionResponseSchema.parse(await res.json());
|
|
55
|
+
}
|
|
56
|
+
async getAllCameraGuids() {
|
|
57
|
+
const requestOptions = this.getRequestOptions('GET');
|
|
58
|
+
const res = await fetch(`${this.baseUrl}/${GET_CAMERAS_URL}`, requestOptions);
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
61
|
+
}
|
|
62
|
+
return cameraGuidsResponseSchema.parse(await res.json());
|
|
63
|
+
}
|
|
64
|
+
async getCameraDetails(guids, parameters) {
|
|
65
|
+
const params = parameters.join(',');
|
|
66
|
+
let camerasGuids = [];
|
|
67
|
+
const requestOptions = this.getRequestOptions('GET');
|
|
68
|
+
const allCameras = [];
|
|
69
|
+
const chunkSize = 10;
|
|
70
|
+
while (guids.length > 0) {
|
|
71
|
+
const chunk = guids.slice(0, chunkSize);
|
|
72
|
+
guids.splice(0, chunkSize);
|
|
73
|
+
camerasGuids = chunk.map((item) => item.Guid);
|
|
74
|
+
const camerasDetailsUrl = [];
|
|
75
|
+
for (const guid of camerasGuids) {
|
|
76
|
+
camerasDetailsUrl.push(`entity=${guid},${params}`);
|
|
77
|
+
}
|
|
78
|
+
const res = await fetch(`${this.baseUrl}/${GET_CAMERAS_DETAILS_URL}${camerasDetailsUrl.join(',')}`, requestOptions);
|
|
79
|
+
if (!res.ok) {
|
|
80
|
+
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
81
|
+
}
|
|
82
|
+
const data = exports.cameraDetailsResponseSchema.parse(await res.json());
|
|
83
|
+
const resultArray = Array.isArray(data.Rsp.Result) ? data.Rsp.Result : [data.Rsp.Result];
|
|
84
|
+
allCameras.push(...resultArray);
|
|
85
|
+
}
|
|
86
|
+
return allCameras;
|
|
87
|
+
}
|
|
88
|
+
async sendBookmark(guids, bookmarkText) {
|
|
89
|
+
const cameraEntitiesUrl = [];
|
|
90
|
+
const timeStamp = this.getTimeStamp();
|
|
91
|
+
const requestOptions = this.getRequestOptions('POST');
|
|
92
|
+
for (const guid of guids) {
|
|
93
|
+
cameraEntitiesUrl.push(`${ACTION}(${guid},${timeStamp},${bookmarkText})`);
|
|
94
|
+
}
|
|
95
|
+
const res = await fetch(`${this.baseUrl}/action?q=${cameraEntitiesUrl.join(',')}`, requestOptions);
|
|
96
|
+
if (!res.ok) {
|
|
97
|
+
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
98
|
+
}
|
|
99
|
+
return res;
|
|
100
|
+
}
|
|
101
|
+
getRequestOptions(method) {
|
|
102
|
+
return {
|
|
103
|
+
method,
|
|
104
|
+
headers: new Headers({
|
|
105
|
+
Authorization: `Basic ${this.credentials}`,
|
|
106
|
+
Accept: 'text/json',
|
|
107
|
+
}),
|
|
108
|
+
redirect: 'follow',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
getTimeStamp() {
|
|
112
|
+
const date = new Date();
|
|
113
|
+
const year = date.getUTCFullYear();
|
|
114
|
+
const month = (0, utils_1.pad)(date.getUTCMonth() + 1, 2);
|
|
115
|
+
const day = (0, utils_1.pad)(date.getUTCDate(), 2);
|
|
116
|
+
const hours = (0, utils_1.pad)(date.getUTCHours(), 2);
|
|
117
|
+
const minutes = (0, utils_1.pad)(date.getUTCMinutes(), 2);
|
|
118
|
+
const seconds = (0, utils_1.pad)(date.getUTCSeconds(), 2);
|
|
119
|
+
const miliSeconds = (0, utils_1.pad)(date.getUTCMilliseconds(), 2);
|
|
120
|
+
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${miliSeconds}Z`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.GenetecAgent = GenetecAgent;
|
package/cjs/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './internal/types';
|
|
2
|
+
export * from './internal/constants';
|
|
3
|
+
export * from './internal/utils';
|
|
4
|
+
export * from './internal/versionCompare';
|
|
5
|
+
export * from './types/common';
|
|
6
|
+
export { CamSwitcherAPI } from './CamSwitcherAPI';
|
|
7
|
+
export { CamSwitcherEvents } from './CamSwitcherEvents';
|
|
8
|
+
export { VapixAPI } from './VapixAPI';
|
|
9
|
+
export { CamOverlayAPI } from './CamOverlayAPI';
|
|
10
|
+
export { CamScripterAPI } from './CamScripterAPI';
|
|
11
|
+
export { CamStreamerAPI } from './CamStreamerAPI';
|
|
12
|
+
export { PlaneTrackerAPI } from './PlaneTrackerAPI';
|
|
13
|
+
export * from './types/CamSwitcherEvents';
|
|
14
|
+
export * from './types/CamSwitcherAPI';
|
|
15
|
+
export * from './types/VapixAPI';
|
|
16
|
+
export * from './types/CamOverlayAPI';
|
|
17
|
+
export * from './models/CamOverlayAPI';
|
|
18
|
+
export * from './types/PlaneTrackerAPI';
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.PlaneTrackerAPI = exports.CamStreamerAPI = exports.CamScripterAPI = exports.CamOverlayAPI = exports.VapixAPI = exports.CamSwitcherEvents = exports.CamSwitcherAPI = void 0;
|
|
18
|
+
__exportStar(require("./internal/types"), exports);
|
|
19
|
+
__exportStar(require("./internal/constants"), exports);
|
|
20
|
+
__exportStar(require("./internal/utils"), exports);
|
|
21
|
+
__exportStar(require("./internal/versionCompare"), exports);
|
|
22
|
+
__exportStar(require("./types/common"), exports);
|
|
23
|
+
var CamSwitcherAPI_1 = require("./CamSwitcherAPI");
|
|
24
|
+
Object.defineProperty(exports, "CamSwitcherAPI", { enumerable: true, get: function () { return CamSwitcherAPI_1.CamSwitcherAPI; } });
|
|
25
|
+
var CamSwitcherEvents_1 = require("./CamSwitcherEvents");
|
|
26
|
+
Object.defineProperty(exports, "CamSwitcherEvents", { enumerable: true, get: function () { return CamSwitcherEvents_1.CamSwitcherEvents; } });
|
|
27
|
+
var VapixAPI_1 = require("./VapixAPI");
|
|
28
|
+
Object.defineProperty(exports, "VapixAPI", { enumerable: true, get: function () { return VapixAPI_1.VapixAPI; } });
|
|
29
|
+
var CamOverlayAPI_1 = require("./CamOverlayAPI");
|
|
30
|
+
Object.defineProperty(exports, "CamOverlayAPI", { enumerable: true, get: function () { return CamOverlayAPI_1.CamOverlayAPI; } });
|
|
31
|
+
var CamScripterAPI_1 = require("./CamScripterAPI");
|
|
32
|
+
Object.defineProperty(exports, "CamScripterAPI", { enumerable: true, get: function () { return CamScripterAPI_1.CamScripterAPI; } });
|
|
33
|
+
var CamStreamerAPI_1 = require("./CamStreamerAPI");
|
|
34
|
+
Object.defineProperty(exports, "CamStreamerAPI", { enumerable: true, get: function () { return CamStreamerAPI_1.CamStreamerAPI; } });
|
|
35
|
+
var PlaneTrackerAPI_1 = require("./PlaneTrackerAPI");
|
|
36
|
+
Object.defineProperty(exports, "PlaneTrackerAPI", { enumerable: true, get: function () { return PlaneTrackerAPI_1.PlaneTrackerAPI; } });
|
|
37
|
+
__exportStar(require("./types/CamSwitcherEvents"), exports);
|
|
38
|
+
__exportStar(require("./types/CamSwitcherAPI"), exports);
|
|
39
|
+
__exportStar(require("./types/VapixAPI"), exports);
|
|
40
|
+
__exportStar(require("./types/CamOverlayAPI"), exports);
|
|
41
|
+
__exportStar(require("./models/CamOverlayAPI"), exports);
|
|
42
|
+
__exportStar(require("./types/PlaneTrackerAPI"), exports);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Digest = void 0;
|
|
4
|
+
const crypto = require("crypto");
|
|
5
|
+
class Digest {
|
|
6
|
+
nonceCount = 1;
|
|
7
|
+
getAuthHeader(user, pass, method, uri, wwwAuthenticateHeader) {
|
|
8
|
+
const digestItems = {};
|
|
9
|
+
const digestArr = wwwAuthenticateHeader.substring(wwwAuthenticateHeader.indexOf('Digest') + 6).split(',');
|
|
10
|
+
for (const arg of digestArr) {
|
|
11
|
+
const pos = arg.indexOf('=');
|
|
12
|
+
const key = arg.substring(0, pos).trim();
|
|
13
|
+
const value = arg.substring(pos + 1).trim();
|
|
14
|
+
digestItems[key] = value.replace(/"/g, '');
|
|
15
|
+
}
|
|
16
|
+
const HA1 = crypto.createHash('md5').update(`${user}:${digestItems['realm']}:${pass}`).digest('hex');
|
|
17
|
+
const HA2 = crypto.createHash('md5').update(`${method}:${uri}`).digest('hex');
|
|
18
|
+
const ncValue = ('00000000' + this.nonceCount.toString(16)).slice(-8);
|
|
19
|
+
let response;
|
|
20
|
+
if (digestItems['qop'] !== undefined) {
|
|
21
|
+
response = crypto
|
|
22
|
+
.createHash('md5')
|
|
23
|
+
.update(`${HA1}:${digestItems['nonce']}:${ncValue}:162d50aa594e9648:auth:${HA2}`)
|
|
24
|
+
.digest('hex');
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
response = crypto.createHash('md5').update(`${HA1}:${digestItems['nonce']}:${HA2}`).digest('hex');
|
|
28
|
+
}
|
|
29
|
+
let header = 'Digest ' +
|
|
30
|
+
`username="${user}",` +
|
|
31
|
+
`realm="${digestItems['realm']}",` +
|
|
32
|
+
`nonce="${digestItems['nonce']}",` +
|
|
33
|
+
`uri="${uri}",` +
|
|
34
|
+
`response="${response}"`;
|
|
35
|
+
if (digestItems['qop'] !== undefined) {
|
|
36
|
+
header += `,qop=auth,nc=${ncValue},cnonce="162d50aa594e9648"`;
|
|
37
|
+
}
|
|
38
|
+
this.nonceCount++;
|
|
39
|
+
return header;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Digest = Digest;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IClient, TResponse } from './types';
|
|
3
|
+
import { TProxyParam } from '../types/common';
|
|
4
|
+
export declare class ProxyClient<Client extends IClient<TResponse> = IClient<TResponse>> {
|
|
5
|
+
client: Client;
|
|
6
|
+
getProxyUrl: () => string;
|
|
7
|
+
constructor(client: Client, getProxyUrl: () => string);
|
|
8
|
+
get: (proxy: TProxyParam, url: string, parameters?: import("./types").TParameters | undefined, headers?: Record<string, string> | undefined) => Promise<TResponse>;
|
|
9
|
+
post: (proxy: TProxyParam, url: string, data: string | Buffer | FormData, parameters?: import("./types").TParameters | undefined, headers?: Record<string, string> | undefined) => Promise<TResponse>;
|
|
10
|
+
private getReal;
|
|
11
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProxyClient = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
class ProxyClient {
|
|
6
|
+
client;
|
|
7
|
+
getProxyUrl;
|
|
8
|
+
constructor(client, getProxyUrl) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
this.getProxyUrl = getProxyUrl;
|
|
11
|
+
}
|
|
12
|
+
get = (proxy, ...args) => {
|
|
13
|
+
const [path, parameters, headers] = args;
|
|
14
|
+
const url = (0, utils_1.addParametersToPath)(path, parameters);
|
|
15
|
+
const { realUrl, realHeaders } = this.getReal(proxy, url, headers);
|
|
16
|
+
return this.client.get(realUrl, {}, realHeaders);
|
|
17
|
+
};
|
|
18
|
+
post = (proxy, ...args) => {
|
|
19
|
+
const [path, data, parameters, headers] = args;
|
|
20
|
+
const url = (0, utils_1.addParametersToPath)(path, parameters);
|
|
21
|
+
const { realUrl, realHeaders } = this.getReal(proxy, url, headers);
|
|
22
|
+
return this.client.post(realUrl, data, {}, realHeaders);
|
|
23
|
+
};
|
|
24
|
+
getReal = (proxy, url, headers) => {
|
|
25
|
+
if (proxy !== null) {
|
|
26
|
+
return {
|
|
27
|
+
realUrl: this.getProxyUrl(),
|
|
28
|
+
realHeaders: {
|
|
29
|
+
...(headers ?? {}),
|
|
30
|
+
'x-target-camera-protocol': proxy.port === 443 ? 'https' : 'http',
|
|
31
|
+
'x-target-camera-path': url,
|
|
32
|
+
'x-target-camera-ip': proxy.ip,
|
|
33
|
+
'x-target-camera-mdns': proxy.mdnsName,
|
|
34
|
+
'x-target-camera-port': String(proxy.port),
|
|
35
|
+
'x-target-camera-pass': proxy.pass,
|
|
36
|
+
'x-target-camera-user': proxy.user,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
realUrl: url,
|
|
42
|
+
realHeaders: headers,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.ProxyClient = ProxyClient;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toSnakeCaseDeep = exports.toSnakeCase = exports.toCamelCaseDeep = exports.toCamelCase = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const toCamelCase = (o) => (0, lodash_1.mapKeys)(o, camelCaseKey);
|
|
6
|
+
exports.toCamelCase = toCamelCase;
|
|
7
|
+
const toCamelCaseDeep = (o) => {
|
|
8
|
+
return mapKeysDeep(o, camelCaseKey);
|
|
9
|
+
};
|
|
10
|
+
exports.toCamelCaseDeep = toCamelCaseDeep;
|
|
11
|
+
const toSnakeCase = (o) => (0, lodash_1.mapKeys)(o, snakeCaseKey);
|
|
12
|
+
exports.toSnakeCase = toSnakeCase;
|
|
13
|
+
const toSnakeCaseDeep = (o) => {
|
|
14
|
+
return mapKeysDeep(o, snakeCaseKey);
|
|
15
|
+
};
|
|
16
|
+
exports.toSnakeCaseDeep = toSnakeCaseDeep;
|
|
17
|
+
const camelCaseKey = (_, key) => (0, lodash_1.camelCase)(key);
|
|
18
|
+
const snakeCaseKey = (_, key) => (0, lodash_1.snakeCase)(key);
|
|
19
|
+
const mapKeysDeep = (obj, cb) => {
|
|
20
|
+
if (Array.isArray(obj)) {
|
|
21
|
+
return obj.map((item) => {
|
|
22
|
+
return mapKeysDeep(item, cb);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (typeof obj !== 'object' || (0, lodash_1.isPlainObject)(obj) === false) {
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
const result = (0, lodash_1.mapKeys)(obj, cb);
|
|
29
|
+
return (0, lodash_1.mapValues)(result, (value) => {
|
|
30
|
+
return mapKeysDeep(value, cb);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Response as UndiciResponse } from 'undici';
|
|
3
|
+
export type Options = {
|
|
4
|
+
ip?: string;
|
|
5
|
+
port?: number;
|
|
6
|
+
user?: string;
|
|
7
|
+
pass?: string;
|
|
8
|
+
tls?: boolean;
|
|
9
|
+
tlsInsecure?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type HttpOptions = Options & {
|
|
12
|
+
keepAlive?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type WsOptions = Options;
|
|
15
|
+
export type TParameters = Record<string, string | number | boolean | null | undefined>;
|
|
16
|
+
export type TResponse = Response | UndiciResponse;
|
|
17
|
+
export type TGetParams = [url: string, parameters?: TParameters, headers?: Record<string, string>];
|
|
18
|
+
export type TPostParams = [
|
|
19
|
+
url: string,
|
|
20
|
+
data: string | Buffer | FormData,
|
|
21
|
+
parameters?: TParameters,
|
|
22
|
+
headers?: Record<string, string>
|
|
23
|
+
];
|
|
24
|
+
export interface IClient<TRes extends TResponse> {
|
|
25
|
+
get: (...params: TGetParams) => Promise<TRes>;
|
|
26
|
+
post: (...params: TPostParams) => Promise<TRes>;
|
|
27
|
+
}
|
|
28
|
+
export type TBlobResponse<Client extends IClient<TResponse>> = Awaited<ReturnType<Awaited<ReturnType<Client['get']>>['blob']>>;
|
|
29
|
+
export interface IWebsocket<Event extends {
|
|
30
|
+
readonly data: string;
|
|
31
|
+
}> {
|
|
32
|
+
destroy: () => void;
|
|
33
|
+
onmessage: null | ((event: Event) => void);
|
|
34
|
+
send: (data: string) => void;
|
|
35
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TPlaylistPlayType } from '../types/CamSwitcherAPI';
|
|
2
|
-
import { TParameters } from './
|
|
2
|
+
import { IClient, Options, TParameters, TResponse } from './types';
|
|
3
3
|
export declare const addParametersToPath: (path: string, params?: TParameters) => string;
|
|
4
4
|
export declare const paramToUrl: (params?: TParameters) => string;
|
|
5
5
|
export declare const arrayToUrl: (arr: string | string[]) => string;
|
|
@@ -9,3 +9,7 @@ export declare const isClip: (id?: string) => boolean;
|
|
|
9
9
|
export declare const isTracker: (id?: string) => boolean;
|
|
10
10
|
export declare const isPlaylist: (id?: string) => boolean;
|
|
11
11
|
export declare const isLoopPlayType: (playType: TPlaylistPlayType) => boolean;
|
|
12
|
+
export declare function isClient(arg?: Options | IClient<TResponse>): arg is IClient<TResponse>;
|
|
13
|
+
export declare function responseStringify(res: TResponse): Promise<string>;
|
|
14
|
+
export declare function pad(num: number, size: number): string;
|
|
15
|
+
export declare function isNullish<T>(value: T | undefined | null): value is undefined | null;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNullish = exports.pad = exports.responseStringify = exports.isClient = exports.isLoopPlayType = exports.isPlaylist = exports.isTracker = exports.isClip = exports.isStream = exports.isCamera = exports.arrayToUrl = exports.paramToUrl = exports.addParametersToPath = void 0;
|
|
4
|
+
const addParametersToPath = (path, params) => {
|
|
5
|
+
if (params === undefined || Object.keys(params).length === 0) {
|
|
6
|
+
return path;
|
|
7
|
+
}
|
|
8
|
+
const joinChar = path.indexOf('?') === -1 ? '?' : '&';
|
|
9
|
+
return `${path}${joinChar}${(0, exports.paramToUrl)(params)}`;
|
|
10
|
+
};
|
|
11
|
+
exports.addParametersToPath = addParametersToPath;
|
|
12
|
+
const paramToUrl = (params) => {
|
|
13
|
+
if (params === undefined) {
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
let output = '';
|
|
17
|
+
for (const key in params) {
|
|
18
|
+
const value = params[key];
|
|
19
|
+
if (isNullish(value)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
output += `${encodeURIComponent(key)}=${encodeURIComponent(value)}&`;
|
|
23
|
+
}
|
|
24
|
+
return output.slice(0, output.length - 1);
|
|
25
|
+
};
|
|
26
|
+
exports.paramToUrl = paramToUrl;
|
|
27
|
+
const arrayToUrl = (arr) => {
|
|
28
|
+
if (Array.isArray(arr)) {
|
|
29
|
+
return arr.join(',');
|
|
30
|
+
}
|
|
31
|
+
return arr;
|
|
32
|
+
};
|
|
33
|
+
exports.arrayToUrl = arrayToUrl;
|
|
34
|
+
const isCamera = (id) => id?.charAt(0) === 'c';
|
|
35
|
+
exports.isCamera = isCamera;
|
|
36
|
+
const isStream = (id) => id?.charAt(0) === 'c' || id?.charAt(0) === 'a';
|
|
37
|
+
exports.isStream = isStream;
|
|
38
|
+
const isClip = (id) => id?.charAt(0) === 's';
|
|
39
|
+
exports.isClip = isClip;
|
|
40
|
+
const isTracker = (id) => id?.charAt(0) === 't';
|
|
41
|
+
exports.isTracker = isTracker;
|
|
42
|
+
const isPlaylist = (id) => id?.charAt(0) === 'p';
|
|
43
|
+
exports.isPlaylist = isPlaylist;
|
|
44
|
+
const isLoopPlayType = (playType) => playType.includes('LOOP');
|
|
45
|
+
exports.isLoopPlayType = isLoopPlayType;
|
|
46
|
+
function isClient(arg = {}) {
|
|
47
|
+
return 'get' in arg && 'post' in arg;
|
|
48
|
+
}
|
|
49
|
+
exports.isClient = isClient;
|
|
50
|
+
async function responseStringify(res) {
|
|
51
|
+
return JSON.stringify({
|
|
52
|
+
status: res.status,
|
|
53
|
+
body: await res.text(),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
exports.responseStringify = responseStringify;
|
|
57
|
+
function pad(num, size) {
|
|
58
|
+
const sign = Math.sign(num) === -1 ? '-' : '';
|
|
59
|
+
return (sign +
|
|
60
|
+
new Array(size)
|
|
61
|
+
.concat([Math.abs(num)])
|
|
62
|
+
.join('0')
|
|
63
|
+
.slice(-size));
|
|
64
|
+
}
|
|
65
|
+
exports.pad = pad;
|
|
66
|
+
function isNullish(value) {
|
|
67
|
+
return value === null || value === undefined;
|
|
68
|
+
}
|
|
69
|
+
exports.isNullish = isNullish;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const assertVersionString: (s: string, msg?: string) => void;
|
|
2
2
|
export declare const isFirmwareVersionAtLeast: (version: string, compareVersion: string) => boolean;
|
|
3
3
|
export declare const isVersionAtLeast: (version: string, compareVersion: string) => boolean;
|
|
4
|
-
export declare const firmwareVersionCompare: (a: string, b: string) =>
|
|
5
|
-
export declare const versionCompare: (a: string, b: string) =>
|
|
4
|
+
export declare const firmwareVersionCompare: (a: string, b: string) => 0 | 1 | -1;
|
|
5
|
+
export declare const versionCompare: (a: string, b: string) => 0 | 1 | -1;
|
|
6
6
|
export declare const fixVersionToDots: (version: string) => string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fixVersionToDots = exports.versionCompare = exports.firmwareVersionCompare = exports.isVersionAtLeast = exports.isFirmwareVersionAtLeast = exports.assertVersionString = void 0;
|
|
4
|
+
const assertVersionString = (s, msg) => {
|
|
5
|
+
if (!s.match(/^[0-9]+(\.[0-9]+){1,3}$/)) {
|
|
6
|
+
throw new Error(msg ?? `${s} is not a version`);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
exports.assertVersionString = assertVersionString;
|
|
10
|
+
const isFirmwareVersionAtLeast = (version, compareVersion) => {
|
|
11
|
+
return (0, exports.firmwareVersionCompare)(version, compareVersion) >= 0;
|
|
12
|
+
};
|
|
13
|
+
exports.isFirmwareVersionAtLeast = isFirmwareVersionAtLeast;
|
|
14
|
+
const isVersionAtLeast = (version, compareVersion) => {
|
|
15
|
+
return (0, exports.versionCompare)(version, compareVersion) >= 0;
|
|
16
|
+
};
|
|
17
|
+
exports.isVersionAtLeast = isVersionAtLeast;
|
|
18
|
+
const firmwareVersionCompare = (a, b) => {
|
|
19
|
+
const versions = [a, b];
|
|
20
|
+
const matchBetaFirmwareVersion = (x) => /^CVP-/.test(x) || /^[0-9]+.*beta/.test(x);
|
|
21
|
+
if (versions.every(matchBetaFirmwareVersion)) {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
if (matchBetaFirmwareVersion(a)) {
|
|
25
|
+
return -1;
|
|
26
|
+
}
|
|
27
|
+
if (matchBetaFirmwareVersion(b)) {
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
return (0, exports.versionCompare)(a, b);
|
|
31
|
+
};
|
|
32
|
+
exports.firmwareVersionCompare = firmwareVersionCompare;
|
|
33
|
+
const versionCompare = (a, b) => {
|
|
34
|
+
(0, exports.assertVersionString)(a);
|
|
35
|
+
(0, exports.assertVersionString)(b);
|
|
36
|
+
const aSplit = parseVersion(a);
|
|
37
|
+
const bSplit = parseVersion(b);
|
|
38
|
+
for (let i = 0; i < aSplit.length; i++) {
|
|
39
|
+
if (aSplit[i] !== bSplit[i]) {
|
|
40
|
+
return aSplit[i] < bSplit[i] ? -1 : 1;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return 0;
|
|
44
|
+
};
|
|
45
|
+
exports.versionCompare = versionCompare;
|
|
46
|
+
const fixVersionToDots = (version) => version.replaceAll('-', '.');
|
|
47
|
+
exports.fixVersionToDots = fixVersionToDots;
|
|
48
|
+
const parseVersion = (version) => {
|
|
49
|
+
(0, exports.assertVersionString)(version);
|
|
50
|
+
const parsed = version.split('.').map((s) => parseInt(s));
|
|
51
|
+
parsed.push(...Array(4 - parsed.length).fill(0));
|
|
52
|
+
return parsed;
|
|
53
|
+
};
|