camstreamerlib 4.0.0-beta.2 → 4.0.0-beta.21
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/cjs/CamScripterAPI.d.ts +36 -0
- package/cjs/CamScripterAPI.js +73 -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 +66 -7
- package/cjs/types/CamScripterAPI.js +35 -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 +36 -0
- package/esm/CamScripterAPI.js +69 -0
- 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 +126 -0
- package/esm/types/CamScripterAPI.js +32 -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/CamScripterAPI.d.ts +0 -19
- package/CamScripterAPI.js +0 -66
- 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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.widgetListSchema = exports.widgetsSchema = void 0;
|
|
4
|
+
const customGraphicsSchema_1 = require("./customGraphicsSchema");
|
|
5
|
+
const imagesSchema_1 = require("./imagesSchema");
|
|
6
|
+
const accuweatherSchema_1 = require("./accuweatherSchema");
|
|
7
|
+
const infotickerSchema_1 = require("./infotickerSchema");
|
|
8
|
+
const pipSchema_1 = require("./pipSchema");
|
|
9
|
+
const ptzCompassSchema_1 = require("./ptzCompassSchema");
|
|
10
|
+
const ptzSchema_1 = require("./ptzSchema");
|
|
11
|
+
const screenSharingSchema_1 = require("./screenSharingSchema");
|
|
12
|
+
const webCameraSharingSchema_1 = require("./webCameraSharingSchema");
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
exports.widgetsSchema = zod_1.z.discriminatedUnion('name', [
|
|
15
|
+
infotickerSchema_1.infoTickerSchema,
|
|
16
|
+
accuweatherSchema_1.accuweatherSchema,
|
|
17
|
+
ptzCompassSchema_1.ptzCompassSchema,
|
|
18
|
+
imagesSchema_1.imagesSchema,
|
|
19
|
+
ptzSchema_1.ptzSchema,
|
|
20
|
+
pipSchema_1.pipSchema,
|
|
21
|
+
customGraphicsSchema_1.customGraphicsSchema,
|
|
22
|
+
screenSharingSchema_1.screenSharingSchema,
|
|
23
|
+
webCameraSharingSchema_1.webCameraSharingSchema,
|
|
24
|
+
]);
|
|
25
|
+
exports.widgetListSchema = zod_1.z.object({
|
|
26
|
+
services: zod_1.z.array(exports.widgetsSchema),
|
|
27
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IClient, HttpOptions, TParameters } from '../internal/types';
|
|
3
|
+
import { Response as UndiciResponse } from 'undici';
|
|
4
|
+
export declare class DefaultClient implements IClient<UndiciResponse> {
|
|
5
|
+
private tls;
|
|
6
|
+
private ip;
|
|
7
|
+
private port;
|
|
8
|
+
private user;
|
|
9
|
+
private pass;
|
|
10
|
+
private httpRequestSender;
|
|
11
|
+
constructor(opt?: HttpOptions);
|
|
12
|
+
get url(): string;
|
|
13
|
+
get: (url: string, parameters?: TParameters | undefined, headers?: Record<string, string> | undefined) => Promise<UndiciResponse>;
|
|
14
|
+
post: (url: string, data: string | Buffer | FormData, parameters?: TParameters | undefined, headers?: Record<string, string> | undefined) => Promise<UndiciResponse>;
|
|
15
|
+
private getBaseConnectionParams;
|
|
16
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultClient = void 0;
|
|
4
|
+
const utils_1 = require("../internal/utils");
|
|
5
|
+
const HttpRequestSender_1 = require("./HttpRequestSender");
|
|
6
|
+
class DefaultClient {
|
|
7
|
+
tls;
|
|
8
|
+
ip;
|
|
9
|
+
port;
|
|
10
|
+
user;
|
|
11
|
+
pass;
|
|
12
|
+
httpRequestSender;
|
|
13
|
+
constructor(opt = {}) {
|
|
14
|
+
this.tls = opt.tls ?? false;
|
|
15
|
+
this.ip = opt.ip ?? '127.0.0.1';
|
|
16
|
+
this.port = opt.port ?? (this.tls ? 443 : 80);
|
|
17
|
+
this.user = opt.user ?? '';
|
|
18
|
+
this.pass = opt.pass ?? '';
|
|
19
|
+
let agentOptions;
|
|
20
|
+
if (opt.tlsInsecure !== undefined || opt.keepAlive !== undefined) {
|
|
21
|
+
agentOptions = {
|
|
22
|
+
rejectUnaurhorized: !opt.tlsInsecure,
|
|
23
|
+
keepAlive: opt.keepAlive,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
this.httpRequestSender = new HttpRequestSender_1.HttpRequestSender(agentOptions);
|
|
27
|
+
}
|
|
28
|
+
get url() {
|
|
29
|
+
return `${this.tls ? 'https' : 'http'}://${this.user}:${this.pass}@${this.ip}:${this.port}`;
|
|
30
|
+
}
|
|
31
|
+
get = (...params) => {
|
|
32
|
+
const [path, parameters, headers] = params;
|
|
33
|
+
const options = this.getBaseConnectionParams('GET', path, parameters ?? {});
|
|
34
|
+
options.headers = headers;
|
|
35
|
+
return this.httpRequestSender.sendRequest(options);
|
|
36
|
+
};
|
|
37
|
+
post = (...params) => {
|
|
38
|
+
const [path, data, parameters, headers] = params;
|
|
39
|
+
const options = this.getBaseConnectionParams('POST', path, parameters ?? {});
|
|
40
|
+
options.headers = headers;
|
|
41
|
+
return this.httpRequestSender.sendRequest(options, data);
|
|
42
|
+
};
|
|
43
|
+
getBaseConnectionParams(method, path, params) {
|
|
44
|
+
const pathName = (0, utils_1.addParametersToPath)(path, params);
|
|
45
|
+
return {
|
|
46
|
+
method: method,
|
|
47
|
+
protocol: this.tls ? 'https:' : 'http:',
|
|
48
|
+
host: this.ip,
|
|
49
|
+
port: this.port,
|
|
50
|
+
path: pathName,
|
|
51
|
+
user: this.user,
|
|
52
|
+
pass: this.pass,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.DefaultClient = DefaultClient;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpRequestSender = void 0;
|
|
4
|
+
const Digest_1 = require("../internal/Digest");
|
|
5
|
+
const undici_1 = require("undici");
|
|
6
|
+
class HttpRequestSender {
|
|
7
|
+
agent;
|
|
8
|
+
authData;
|
|
9
|
+
constructor(agentOptions) {
|
|
10
|
+
this.agent = new undici_1.Agent({
|
|
11
|
+
connect: { rejectUnauthorized: agentOptions?.rejectUnaurhorized, keepAlive: agentOptions?.keepAlive },
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
sendRequest(options, postData) {
|
|
15
|
+
return this.sendRequestWithAuth(options, postData);
|
|
16
|
+
}
|
|
17
|
+
async sendRequestWithAuth(options, postData, wwwAuthenticateHeader) {
|
|
18
|
+
options.timeout ??= 10000;
|
|
19
|
+
const url = HttpRequestSender.getURL(options);
|
|
20
|
+
const authorization = this.getAuthorization(options, wwwAuthenticateHeader);
|
|
21
|
+
if (authorization !== undefined) {
|
|
22
|
+
options.headers ??= {};
|
|
23
|
+
options.headers['Authorization'] = authorization;
|
|
24
|
+
}
|
|
25
|
+
const req = new undici_1.Request(url, { body: postData, method: options.method, headers: options.headers });
|
|
26
|
+
const res = await (0, undici_1.fetch)(req, { signal: AbortSignal.timeout(options.timeout), dispatcher: this.agent });
|
|
27
|
+
if (!res.ok) {
|
|
28
|
+
this.invalidateAuthorization();
|
|
29
|
+
}
|
|
30
|
+
if (res.status === 401) {
|
|
31
|
+
const authenticateHeader = res.headers.get('www-authenticate');
|
|
32
|
+
if (authenticateHeader !== null &&
|
|
33
|
+
authenticateHeader.indexOf('Digest') !== -1 &&
|
|
34
|
+
wwwAuthenticateHeader === undefined) {
|
|
35
|
+
return this.sendRequestWithAuth(options, postData, authenticateHeader);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return res;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
static getURL(options) {
|
|
46
|
+
const url = new URL(`${options.protocol}//${options.host}:${options.port}${options.path}`);
|
|
47
|
+
return url.toString();
|
|
48
|
+
}
|
|
49
|
+
getAuthorization(options, wwwAuthenticateHeader) {
|
|
50
|
+
if (options.user === undefined || options.pass === undefined) {
|
|
51
|
+
this.authData = undefined;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (this.authData &&
|
|
55
|
+
(this.authData.host !== options.host ||
|
|
56
|
+
this.authData.port !== options.port ||
|
|
57
|
+
this.authData.user !== options.user ||
|
|
58
|
+
this.authData.pass !== options.pass ||
|
|
59
|
+
(wwwAuthenticateHeader !== undefined && this.authData.wwwAuthenticateHeader !== wwwAuthenticateHeader))) {
|
|
60
|
+
this.authData = undefined;
|
|
61
|
+
}
|
|
62
|
+
if (this.authData === undefined) {
|
|
63
|
+
this.authData = {
|
|
64
|
+
host: options.host,
|
|
65
|
+
port: options.port,
|
|
66
|
+
user: options.user,
|
|
67
|
+
pass: options.pass,
|
|
68
|
+
wwwAuthenticateHeader,
|
|
69
|
+
digest: new Digest_1.Digest(),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return HttpRequestSender.getAuthHeader(options, this.authData);
|
|
73
|
+
}
|
|
74
|
+
invalidateAuthorization() {
|
|
75
|
+
this.authData = undefined;
|
|
76
|
+
}
|
|
77
|
+
static getAuthHeader(options, authData) {
|
|
78
|
+
if (options.user === undefined || options.pass === undefined) {
|
|
79
|
+
throw new Error('No credentials found');
|
|
80
|
+
}
|
|
81
|
+
if (authData.wwwAuthenticateHeader !== undefined && authData.wwwAuthenticateHeader.indexOf('Digest') !== -1) {
|
|
82
|
+
return authData.digest.getAuthHeader(options.user, options.pass, options.method ?? 'GET', options.path, authData.wwwAuthenticateHeader);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return `Basic ${btoa(options.user + ':' + options.pass)}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.HttpRequestSender = HttpRequestSender;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpServer = void 0;
|
|
4
|
+
const http = require("http");
|
|
5
|
+
const url = require("url");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const EventEmitter = require("events");
|
|
9
|
+
class HttpServer extends EventEmitter {
|
|
10
|
+
host;
|
|
11
|
+
port;
|
|
12
|
+
registeredPaths;
|
|
13
|
+
server;
|
|
14
|
+
sockets;
|
|
15
|
+
constructor(options) {
|
|
16
|
+
super();
|
|
17
|
+
this.host = options?.host ?? process.env.HTTP_HOST ?? '0.0.0.0';
|
|
18
|
+
this.port = options?.port ?? parseInt(process.env.HTTP_PORT ?? '80');
|
|
19
|
+
this.registeredPaths = new Map();
|
|
20
|
+
this.server = http.createServer((req, res) => {
|
|
21
|
+
this.emit('access', req.method + ' ' + req.url);
|
|
22
|
+
const parsedUrl = url.parse(req.url ?? '');
|
|
23
|
+
parsedUrl.pathname ??= '';
|
|
24
|
+
const requestCallback = this.registeredPaths.get(parsedUrl.pathname);
|
|
25
|
+
if (requestCallback) {
|
|
26
|
+
requestCallback(req, res);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let pathname = `./html${parsedUrl.pathname}`;
|
|
30
|
+
const ext = path.parse(pathname).ext;
|
|
31
|
+
const map = {
|
|
32
|
+
'.ico': 'image/x-icon',
|
|
33
|
+
'.html': 'text/html',
|
|
34
|
+
'.js': 'text/javascript',
|
|
35
|
+
'.json': 'application/json',
|
|
36
|
+
'.css': 'text/css',
|
|
37
|
+
'.png': 'image/png',
|
|
38
|
+
'.jpg': 'image/jpeg',
|
|
39
|
+
'.wav': 'audio/wav',
|
|
40
|
+
'.mp3': 'audio/mpeg',
|
|
41
|
+
'.svg': 'image/svg+xml',
|
|
42
|
+
'.pdf': 'application/pdf',
|
|
43
|
+
'.doc': 'application/msword',
|
|
44
|
+
};
|
|
45
|
+
fs.access(pathname, fs.constants.R_OK, (err) => {
|
|
46
|
+
if (err) {
|
|
47
|
+
res.statusCode = 404;
|
|
48
|
+
res.end(`File ${pathname} not found!`);
|
|
49
|
+
this.emit('error', `File ${pathname} not found!`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (fs.statSync(pathname).isDirectory()) {
|
|
53
|
+
pathname += `/index${ext}`;
|
|
54
|
+
}
|
|
55
|
+
fs.readFile(pathname, (error, data) => {
|
|
56
|
+
if (error) {
|
|
57
|
+
res.statusCode = 500;
|
|
58
|
+
res.end(`Error getting the file: ${error}`);
|
|
59
|
+
this.emit('error', `Error getting the file: ${error}`);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
res.setHeader('Content-type', map[ext] ?? 'text/plain');
|
|
63
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
64
|
+
res.end(data);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
this.server.on('error', (err) => {
|
|
70
|
+
this.emit('error', err);
|
|
71
|
+
});
|
|
72
|
+
this.server.listen(this.port, this.host);
|
|
73
|
+
this.sockets = {};
|
|
74
|
+
let idTracker = 0;
|
|
75
|
+
this.server.on('connection', (socket) => {
|
|
76
|
+
const socketID = idTracker++;
|
|
77
|
+
this.sockets[socketID] = socket;
|
|
78
|
+
socket.on('close', () => {
|
|
79
|
+
delete this.sockets[socketID];
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
getServer() {
|
|
84
|
+
return this.server;
|
|
85
|
+
}
|
|
86
|
+
onRequest(pathName, callback) {
|
|
87
|
+
this.registeredPaths.set(pathName, callback);
|
|
88
|
+
}
|
|
89
|
+
close() {
|
|
90
|
+
this.server.close();
|
|
91
|
+
for (const key in this.sockets) {
|
|
92
|
+
this.sockets[key]?.destroy();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.HttpServer = HttpServer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import * as EventEmitter from 'events';
|
|
4
|
-
import { WsOptions } from '../internal/
|
|
4
|
+
import { WsOptions } from '../internal/types';
|
|
5
5
|
export type WsClientOptions = WsOptions & {
|
|
6
6
|
address: string;
|
|
7
7
|
headers?: Record<string, string>;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WsClient = void 0;
|
|
4
|
+
const EventEmitter = require("events");
|
|
5
|
+
const WebSocket = require("ws");
|
|
6
|
+
const Digest_1 = require("../internal/Digest");
|
|
7
|
+
class WsClient extends EventEmitter {
|
|
8
|
+
user;
|
|
9
|
+
pass;
|
|
10
|
+
address;
|
|
11
|
+
protocol;
|
|
12
|
+
pingInterval;
|
|
13
|
+
wsOptions;
|
|
14
|
+
digestAddress;
|
|
15
|
+
isAlive = true;
|
|
16
|
+
pingTimer;
|
|
17
|
+
ws;
|
|
18
|
+
isClosed = false;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
super();
|
|
21
|
+
const tls = options.tls ?? false;
|
|
22
|
+
const tlsInsecure = options.tlsInsecure ?? false;
|
|
23
|
+
const ip = options.ip ?? '127.0.0.1';
|
|
24
|
+
const port = options.port ?? (tls ? 443 : 80);
|
|
25
|
+
this.user = options.user ?? '';
|
|
26
|
+
this.pass = options.pass ?? '';
|
|
27
|
+
const protocol = tls ? 'wss' : 'ws';
|
|
28
|
+
this.address = `${protocol}://${ip}:${port}${options.address}`;
|
|
29
|
+
this.digestAddress = options.address;
|
|
30
|
+
this.pingInterval = options.pingInterval ?? 30000;
|
|
31
|
+
this.protocol = options.protocol;
|
|
32
|
+
this.wsOptions = {
|
|
33
|
+
auth: `${this.user}:${this.pass}`,
|
|
34
|
+
rejectUnauthorized: !tlsInsecure,
|
|
35
|
+
headers: options.headers ?? {},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
open(wwwAuthenticateHeader) {
|
|
39
|
+
try {
|
|
40
|
+
if (this.ws !== undefined) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this.isClosed = false;
|
|
44
|
+
if (this.protocol === undefined) {
|
|
45
|
+
this.ws = new WebSocket(this.address, this.wsOptions);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.ws = new WebSocket(this.address, this.protocol, this.wsOptions);
|
|
49
|
+
}
|
|
50
|
+
this.ws.binaryType = 'arraybuffer';
|
|
51
|
+
this.isAlive = true;
|
|
52
|
+
this.pingTimer = setInterval(async () => {
|
|
53
|
+
if ((this.ws && this.ws.readyState !== WebSocket.OPEN) || this.isAlive === false) {
|
|
54
|
+
this.emit('error', new Error('Connection timeout'));
|
|
55
|
+
await this.closeWsConnection();
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.isAlive = false;
|
|
59
|
+
this.ws?.ping();
|
|
60
|
+
}
|
|
61
|
+
}, this.pingInterval);
|
|
62
|
+
this.ws.on('pong', () => {
|
|
63
|
+
this.isAlive = true;
|
|
64
|
+
});
|
|
65
|
+
if (wwwAuthenticateHeader !== undefined) {
|
|
66
|
+
this.wsOptions.headers['Authorization'] = new Digest_1.Digest().getAuthHeader(this.user, this.pass, 'GET', this.digestAddress, wwwAuthenticateHeader);
|
|
67
|
+
}
|
|
68
|
+
this.ws.on('unexpected-response', (req, res) => {
|
|
69
|
+
if (res.statusCode === 401 && res.headers['www-authenticate'] !== undefined) {
|
|
70
|
+
if (this.pingTimer) {
|
|
71
|
+
clearInterval(this.pingTimer);
|
|
72
|
+
}
|
|
73
|
+
this.ws?.removeAllListeners();
|
|
74
|
+
this.ws = undefined;
|
|
75
|
+
this.open(res.headers['www-authenticate']);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.emit('error', new Error('Status code: ' + res.statusCode));
|
|
79
|
+
this.closeWsConnection();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
this.ws.on('open', () => this.emit('open'));
|
|
83
|
+
this.ws.on('message', (data) => this.emit('message', data));
|
|
84
|
+
this.ws.on('error', (error) => {
|
|
85
|
+
this.emit('error', error);
|
|
86
|
+
this.closeWsConnection();
|
|
87
|
+
});
|
|
88
|
+
this.ws.on('close', () => this.closeWsConnection());
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
this.emit('error', error instanceof Error ? error : new Error('Unknown error'));
|
|
92
|
+
this.closeWsConnection();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
send(data) {
|
|
96
|
+
if (this.ws === undefined) {
|
|
97
|
+
throw new Error("This websocket hasn't been opened yet.");
|
|
98
|
+
}
|
|
99
|
+
if (this.ws.readyState === this.ws.OPEN) {
|
|
100
|
+
this.ws.send(data);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
close() {
|
|
104
|
+
if (this.isClosed) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.isClosed = true;
|
|
108
|
+
this.closeWsConnection();
|
|
109
|
+
}
|
|
110
|
+
reconnect() {
|
|
111
|
+
this.closeWsConnection();
|
|
112
|
+
}
|
|
113
|
+
closeWsConnection() {
|
|
114
|
+
if (this.ws === undefined) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const wsCopy = this.ws;
|
|
118
|
+
this.ws = undefined;
|
|
119
|
+
try {
|
|
120
|
+
if (this.pingTimer) {
|
|
121
|
+
clearInterval(this.pingTimer);
|
|
122
|
+
}
|
|
123
|
+
wsCopy.removeAllListeners();
|
|
124
|
+
wsCopy.on('error', () => { });
|
|
125
|
+
if (wsCopy.readyState !== WebSocket.CLOSING && wsCopy.readyState !== WebSocket.CLOSED) {
|
|
126
|
+
wsCopy.close();
|
|
127
|
+
}
|
|
128
|
+
setTimeout(() => {
|
|
129
|
+
if (wsCopy.readyState !== WebSocket.CLOSED) {
|
|
130
|
+
wsCopy.terminate();
|
|
131
|
+
}
|
|
132
|
+
}, 5000);
|
|
133
|
+
this.emit('close');
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
console.error(err);
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
const shouldRestart = !this.isClosed;
|
|
140
|
+
setTimeout(() => {
|
|
141
|
+
wsCopy.removeAllListeners();
|
|
142
|
+
if (shouldRestart && !this.isClosed) {
|
|
143
|
+
this.open();
|
|
144
|
+
}
|
|
145
|
+
}, 10000);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.WsClient = WsClient;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WsEventClient = void 0;
|
|
4
|
+
const WsClient_1 = require("./WsClient");
|
|
5
|
+
class WsEventClient {
|
|
6
|
+
wsClient;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.wsClient = new WsClient_1.WsClient(options);
|
|
9
|
+
this.wsClient.on('message', (data) => {
|
|
10
|
+
this.onmessage?.({ data: data.toString() });
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
send = (data) => {
|
|
14
|
+
this.wsClient.send(data);
|
|
15
|
+
};
|
|
16
|
+
destroy = () => {
|
|
17
|
+
this.wsClient.close();
|
|
18
|
+
this.onmessage = null;
|
|
19
|
+
};
|
|
20
|
+
onmessage = null;
|
|
21
|
+
}
|
|
22
|
+
exports.WsEventClient = WsEventClient;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WsClient = exports.DefaultClient = void 0;
|
|
4
|
+
var DefaultClient_1 = require("./DefaultClient");
|
|
5
|
+
Object.defineProperty(exports, "DefaultClient", { enumerable: true, get: function () { return DefaultClient_1.DefaultClient; } });
|
|
6
|
+
var WsClient_1 = require("./WsClient");
|
|
7
|
+
Object.defineProperty(exports, "WsClient", { enumerable: true, get: function () { return WsClient_1.WsClient; } });
|