camstreamerlib 4.0.0-beta.29 → 4.0.0-beta.30
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 +6 -2
- package/cjs/CamOverlayAPI.d.ts +38 -615
- package/cjs/CamOverlayAPI.js +128 -104
- package/cjs/CamOverlayDrawingAPI.d.ts +2 -47
- package/cjs/CamOverlayPainter/Frame.d.ts +8 -37
- package/cjs/CamOverlayPainter/Frame.js +33 -0
- package/cjs/CamOverlayPainter/Painter.d.ts +5 -10
- package/cjs/CamOverlayPainter/Painter.js +2 -4
- package/cjs/CamOverlayPainter/ResourceManager.d.ts +3 -2
- package/cjs/CamOverlayPainter/ResourceManager.js +2 -1
- package/cjs/CamScripterAPI.d.ts +12 -12
- package/cjs/CamScripterAPI.js +33 -27
- package/cjs/CamStreamerAPI.d.ts +11 -9
- package/cjs/CamStreamerAPI.js +28 -22
- package/cjs/CamSwitcherAPI.d.ts +35 -34
- package/cjs/CamSwitcherAPI.js +94 -82
- package/cjs/PlaneTrackerAPI.d.ts +30 -36
- package/cjs/PlaneTrackerAPI.js +132 -71
- package/cjs/VapixAPI.d.ts +43 -40
- package/cjs/VapixAPI.js +205 -183
- package/cjs/events/AxisCameraStationEvents.d.ts +5 -5
- package/cjs/events/AxisCameraStationEvents.js +17 -12
- package/cjs/events/GenetecAgent.d.ts +2 -0
- package/cjs/events/GenetecAgent.js +15 -4
- package/cjs/index.d.ts +7 -1
- package/cjs/index.js +12 -2
- package/cjs/internal/ProxyClient.d.ts +7 -8
- package/cjs/internal/ProxyClient.js +25 -31
- package/cjs/internal/types.d.ts +16 -9
- package/cjs/internal/utils.d.ts +1 -2
- package/cjs/internal/utils.js +1 -5
- package/cjs/node/DefaultClient.d.ts +3 -5
- package/cjs/node/DefaultClient.js +10 -14
- package/cjs/node/HttpRequestSender.d.ts +1 -0
- package/cjs/node/HttpRequestSender.js +13 -3
- package/cjs/node/WsClient.d.ts +1 -0
- package/cjs/node/index.d.ts +2 -0
- package/cjs/node/index.js +18 -1
- package/cjs/{models/CamOverlayAPI/widgetsSchema.d.ts → types/CamOverlayAPI/CamOverlayAPI.d.ts} +625 -375
- package/cjs/{models/CamOverlayAPI/widgetCommonSchema.js → types/CamOverlayAPI/CamOverlayAPI.js} +65 -14
- package/cjs/{models → types}/CamOverlayAPI/accuweatherSchema.d.ts +40 -10
- package/cjs/{models → types}/CamOverlayAPI/accuweatherSchema.js +11 -9
- package/cjs/{models → types}/CamOverlayAPI/customGraphicsSchema.d.ts +89 -5
- package/cjs/{models → types}/CamOverlayAPI/customGraphicsSchema.js +9 -7
- package/{esm/models → cjs/types}/CamOverlayAPI/imagesSchema.d.ts +40 -13
- package/cjs/types/CamOverlayAPI/imagesSchema.js +12 -0
- package/cjs/{models → types}/CamOverlayAPI/index.d.ts +0 -4
- package/cjs/{models → types}/CamOverlayAPI/index.js +0 -4
- package/{esm/models → cjs/types}/CamOverlayAPI/infotickerSchema.d.ts +43 -9
- package/cjs/{models → types}/CamOverlayAPI/infotickerSchema.js +10 -8
- package/{esm/models → cjs/types}/CamOverlayAPI/pipSchema.d.ts +48 -7
- package/cjs/{models → types}/CamOverlayAPI/pipSchema.js +8 -6
- package/{esm/models → cjs/types}/CamOverlayAPI/ptzCompassSchema.d.ts +40 -7
- package/cjs/{models → types}/CamOverlayAPI/ptzCompassSchema.js +8 -6
- package/cjs/{models → types}/CamOverlayAPI/ptzSchema.d.ts +42 -14
- package/cjs/types/CamOverlayAPI/ptzSchema.js +15 -0
- package/{esm/models → cjs/types}/CamOverlayAPI/screenSharingSchema.d.ts +26 -5
- package/cjs/types/CamOverlayAPI/screenSharingSchema.js +11 -0
- package/cjs/{models → types}/CamOverlayAPI/webCameraSharingSchema.d.ts +26 -5
- package/cjs/types/CamOverlayAPI/webCameraSharingSchema.js +11 -0
- package/cjs/types/CamOverlayDrawingAPI.d.ts +58 -0
- package/cjs/types/CamOverlayDrawingAPI.js +2 -0
- package/cjs/types/CamOverlayPainter.d.ts +74 -0
- package/cjs/types/CamOverlayPainter.js +2 -0
- package/cjs/types/CamStreamerAPI.d.ts +4 -4
- package/cjs/types/PlaneTrackerAPI.d.ts +6 -0
- package/cjs/types/common.d.ts +12 -3
- package/cjs/web/DefaultClient.d.ts +4 -4
- package/cjs/web/DefaultClient.js +21 -11
- package/esm/CamOverlayAPI.d.ts +38 -615
- package/esm/CamOverlayAPI.js +127 -103
- package/esm/CamOverlayDrawingAPI.d.ts +2 -47
- package/esm/CamOverlayPainter/Frame.d.ts +8 -37
- package/esm/CamOverlayPainter/Frame.js +33 -0
- package/esm/CamOverlayPainter/Painter.d.ts +5 -10
- package/esm/CamOverlayPainter/Painter.js +1 -2
- package/esm/CamOverlayPainter/ResourceManager.d.ts +3 -2
- package/esm/CamOverlayPainter/ResourceManager.js +1 -1
- package/esm/CamScripterAPI.d.ts +12 -12
- package/esm/CamScripterAPI.js +32 -26
- package/esm/CamStreamerAPI.d.ts +11 -9
- package/esm/CamStreamerAPI.js +28 -22
- package/esm/CamSwitcherAPI.d.ts +35 -34
- package/esm/CamSwitcherAPI.js +95 -83
- package/esm/PlaneTrackerAPI.d.ts +30 -36
- package/esm/PlaneTrackerAPI.js +131 -70
- package/esm/VapixAPI.d.ts +43 -40
- package/esm/VapixAPI.js +204 -182
- package/esm/events/AxisCameraStationEvents.d.ts +5 -5
- package/esm/events/AxisCameraStationEvents.js +18 -13
- package/esm/events/GenetecAgent.d.ts +2 -0
- package/esm/events/GenetecAgent.js +15 -4
- package/esm/index.d.ts +7 -1
- package/esm/index.js +7 -1
- package/esm/internal/ProxyClient.d.ts +7 -8
- package/esm/internal/ProxyClient.js +25 -31
- package/esm/internal/types.d.ts +16 -9
- package/esm/internal/utils.d.ts +1 -2
- package/esm/internal/utils.js +0 -3
- package/esm/node/DefaultClient.d.ts +3 -5
- package/esm/node/DefaultClient.js +10 -14
- package/esm/node/HttpRequestSender.d.ts +1 -0
- package/esm/node/HttpRequestSender.js +13 -3
- package/esm/node/WsClient.d.ts +1 -0
- package/esm/node/index.d.ts +2 -0
- package/esm/node/index.js +2 -0
- package/esm/{models/CamOverlayAPI/widgetsSchema.d.ts → types/CamOverlayAPI/CamOverlayAPI.d.ts} +625 -375
- package/esm/{models/CamOverlayAPI/widgetCommonSchema.js → types/CamOverlayAPI/CamOverlayAPI.js} +64 -13
- package/esm/{models → types}/CamOverlayAPI/accuweatherSchema.d.ts +40 -10
- package/esm/{models → types}/CamOverlayAPI/accuweatherSchema.js +3 -2
- package/esm/{models → types}/CamOverlayAPI/customGraphicsSchema.d.ts +89 -5
- package/esm/{models → types}/CamOverlayAPI/customGraphicsSchema.js +3 -2
- package/{cjs/models → esm/types}/CamOverlayAPI/imagesSchema.d.ts +40 -13
- package/esm/types/CamOverlayAPI/imagesSchema.js +8 -0
- package/esm/{models → types}/CamOverlayAPI/index.d.ts +0 -4
- package/esm/{models → types}/CamOverlayAPI/index.js +0 -4
- package/{cjs/models → esm/types}/CamOverlayAPI/infotickerSchema.d.ts +43 -9
- package/esm/{models → types}/CamOverlayAPI/infotickerSchema.js +3 -2
- package/{cjs/models → esm/types}/CamOverlayAPI/pipSchema.d.ts +48 -7
- package/esm/{models → types}/CamOverlayAPI/pipSchema.js +3 -2
- package/{cjs/models → esm/types}/CamOverlayAPI/ptzCompassSchema.d.ts +40 -7
- package/esm/{models → types}/CamOverlayAPI/ptzCompassSchema.js +3 -2
- package/esm/{models → types}/CamOverlayAPI/ptzSchema.d.ts +42 -14
- package/esm/{models → types}/CamOverlayAPI/ptzSchema.js +3 -2
- package/{cjs/models → esm/types}/CamOverlayAPI/screenSharingSchema.d.ts +26 -5
- package/esm/types/CamOverlayAPI/screenSharingSchema.js +7 -0
- package/esm/{models → types}/CamOverlayAPI/webCameraSharingSchema.d.ts +26 -5
- package/esm/types/CamOverlayAPI/webCameraSharingSchema.js +7 -0
- package/esm/types/CamOverlayDrawingAPI.d.ts +58 -0
- package/esm/types/CamOverlayDrawingAPI.js +1 -0
- package/esm/types/CamOverlayPainter.d.ts +74 -0
- package/esm/types/CamOverlayPainter.js +1 -0
- package/esm/types/CamStreamerAPI.d.ts +4 -4
- package/esm/types/PlaneTrackerAPI.d.ts +6 -0
- package/esm/types/common.d.ts +12 -3
- package/esm/web/DefaultClient.d.ts +4 -4
- package/esm/web/DefaultClient.js +21 -11
- package/package.json +2 -2
- package/cjs/models/CamOverlayAPI/constants.d.ts +0 -11
- package/cjs/models/CamOverlayAPI/constants.js +0 -14
- package/cjs/models/CamOverlayAPI/fileSchema.d.ts +0 -28
- package/cjs/models/CamOverlayAPI/fileSchema.js +0 -17
- package/cjs/models/CamOverlayAPI/imagesSchema.js +0 -10
- package/cjs/models/CamOverlayAPI/ptzSchema.js +0 -13
- package/cjs/models/CamOverlayAPI/screenSharingSchema.js +0 -9
- package/cjs/models/CamOverlayAPI/webCameraSharingSchema.js +0 -9
- package/cjs/models/CamOverlayAPI/widgetCommonSchema.d.ts +0 -126
- package/cjs/models/CamOverlayAPI/widgetsSchema.js +0 -27
- package/cjs/types/CamOverlayAPI.d.ts +0 -328
- package/cjs/types/CamOverlayAPI.js +0 -26
- package/esm/models/CamOverlayAPI/constants.d.ts +0 -11
- package/esm/models/CamOverlayAPI/constants.js +0 -11
- package/esm/models/CamOverlayAPI/fileSchema.d.ts +0 -28
- package/esm/models/CamOverlayAPI/fileSchema.js +0 -14
- package/esm/models/CamOverlayAPI/imagesSchema.js +0 -7
- package/esm/models/CamOverlayAPI/screenSharingSchema.js +0 -6
- package/esm/models/CamOverlayAPI/webCameraSharingSchema.js +0 -6
- package/esm/models/CamOverlayAPI/widgetCommonSchema.d.ts +0 -126
- package/esm/models/CamOverlayAPI/widgetsSchema.js +0 -24
- package/esm/types/CamOverlayAPI.d.ts +0 -328
- package/esm/types/CamOverlayAPI.js +0 -14
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AxisCameraStationEvents = void 0;
|
|
4
|
-
const DefaultClient_1 = require("../node/DefaultClient");
|
|
5
4
|
const utils_1 = require("../internal/utils");
|
|
5
|
+
const ProxyClient_1 = require("../internal/ProxyClient");
|
|
6
|
+
const node_1 = require("../node");
|
|
6
7
|
class AxisCameraStationEvents {
|
|
7
8
|
sourceKey;
|
|
8
9
|
client;
|
|
9
|
-
constructor(
|
|
10
|
+
constructor(clientOptions, sourceKey) {
|
|
10
11
|
this.sourceKey = sourceKey;
|
|
11
|
-
|
|
12
|
-
this.client = opt;
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
this.client = new DefaultClient_1.DefaultClient(opt);
|
|
16
|
-
}
|
|
12
|
+
this.client = new node_1.DefaultClient(clientOptions);
|
|
17
13
|
}
|
|
18
|
-
async sendEvent(data, eventType) {
|
|
14
|
+
async sendEvent(data, eventType, options) {
|
|
19
15
|
const dateString = this.getDate();
|
|
20
16
|
const event = {
|
|
21
17
|
addExternalDataRequest: {
|
|
@@ -26,9 +22,15 @@ class AxisCameraStationEvents {
|
|
|
26
22
|
},
|
|
27
23
|
};
|
|
28
24
|
const eventData = JSON.stringify(event);
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
'
|
|
25
|
+
const agent = this.getAgent(options?.proxyParams);
|
|
26
|
+
const res = await agent.post({
|
|
27
|
+
path: '/Acs/Api/ExternalDataFacade/AddExternalData',
|
|
28
|
+
data: eventData,
|
|
29
|
+
headers: {
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
'Content-Length': eventData.length.toString(),
|
|
32
|
+
},
|
|
33
|
+
timeout: options?.timeout,
|
|
32
34
|
});
|
|
33
35
|
if (!res.ok) {
|
|
34
36
|
throw new Error(`ACS status code: ${res.status}`);
|
|
@@ -44,5 +46,8 @@ class AxisCameraStationEvents {
|
|
|
44
46
|
const seconds = (0, utils_1.pad)(date.getUTCSeconds(), 2);
|
|
45
47
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
46
48
|
}
|
|
49
|
+
getAgent(proxyParams) {
|
|
50
|
+
return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
|
|
51
|
+
}
|
|
47
52
|
}
|
|
48
53
|
exports.AxisCameraStationEvents = AxisCameraStationEvents;
|
|
@@ -157,6 +157,7 @@ export type GenetecAgentOptions = {
|
|
|
157
157
|
user?: string;
|
|
158
158
|
pass?: string;
|
|
159
159
|
appId?: string;
|
|
160
|
+
timeout?: number;
|
|
160
161
|
};
|
|
161
162
|
export declare class GenetecAgent {
|
|
162
163
|
private settings;
|
|
@@ -171,5 +172,6 @@ export declare class GenetecAgent {
|
|
|
171
172
|
sendBookmark(guids: string[], bookmarkText: string): Promise<Response>;
|
|
172
173
|
private getRequestOptions;
|
|
173
174
|
private getTimeStamp;
|
|
175
|
+
private fetchWithTimeout;
|
|
174
176
|
}
|
|
175
177
|
export {};
|
|
@@ -41,13 +41,14 @@ class GenetecAgent {
|
|
|
41
41
|
user: options.user ?? 'root',
|
|
42
42
|
pass: options.pass ?? '',
|
|
43
43
|
appId: options.appId ?? '',
|
|
44
|
+
timeout: options.timeout ?? 10000,
|
|
44
45
|
};
|
|
45
46
|
this.baseUrl = `${this.settings.protocol}://${this.settings.ip}:${this.settings.port}/${this.settings.baseUri}`;
|
|
46
47
|
this.credentials = btoa(`${this.settings.user};${this.settings.appId}:${this.settings.pass}`);
|
|
47
48
|
}
|
|
48
49
|
async checkConnection() {
|
|
49
50
|
const requestOptions = this.getRequestOptions('GET');
|
|
50
|
-
const res = await
|
|
51
|
+
const res = await this.fetchWithTimeout(`${this.baseUrl}/`, requestOptions);
|
|
51
52
|
if (!res.ok) {
|
|
52
53
|
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
53
54
|
}
|
|
@@ -55,7 +56,7 @@ class GenetecAgent {
|
|
|
55
56
|
}
|
|
56
57
|
async getAllCameraGuids() {
|
|
57
58
|
const requestOptions = this.getRequestOptions('GET');
|
|
58
|
-
const res = await
|
|
59
|
+
const res = await this.fetchWithTimeout(`${this.baseUrl}/${GET_CAMERAS_URL}`, requestOptions);
|
|
59
60
|
if (!res.ok) {
|
|
60
61
|
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
61
62
|
}
|
|
@@ -75,7 +76,7 @@ class GenetecAgent {
|
|
|
75
76
|
for (const guid of camerasGuids) {
|
|
76
77
|
camerasDetailsUrl.push(`entity=${guid},${params}`);
|
|
77
78
|
}
|
|
78
|
-
const res = await
|
|
79
|
+
const res = await this.fetchWithTimeout(`${this.baseUrl}/${GET_CAMERAS_DETAILS_URL}${camerasDetailsUrl.join(',')}`, requestOptions);
|
|
79
80
|
if (!res.ok) {
|
|
80
81
|
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
81
82
|
}
|
|
@@ -92,7 +93,7 @@ class GenetecAgent {
|
|
|
92
93
|
for (const guid of guids) {
|
|
93
94
|
cameraEntitiesUrl.push(`${ACTION}(${guid},${timeStamp},${bookmarkText})`);
|
|
94
95
|
}
|
|
95
|
-
const res = await
|
|
96
|
+
const res = await this.fetchWithTimeout(`${this.baseUrl}/action?q=${cameraEntitiesUrl.join(',')}`, requestOptions);
|
|
96
97
|
if (!res.ok) {
|
|
97
98
|
throw new Error(await (0, utils_1.responseStringify)(res));
|
|
98
99
|
}
|
|
@@ -119,5 +120,15 @@ class GenetecAgent {
|
|
|
119
120
|
const miliSeconds = (0, utils_1.pad)(date.getUTCMilliseconds(), 2);
|
|
120
121
|
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${miliSeconds}Z`;
|
|
121
122
|
}
|
|
123
|
+
async fetchWithTimeout(url, options) {
|
|
124
|
+
const controller = new AbortController();
|
|
125
|
+
const timeoutId = setTimeout(() => controller.abort(), this.settings.timeout);
|
|
126
|
+
try {
|
|
127
|
+
return await fetch(url, { ...options, signal: controller.signal });
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
clearTimeout(timeoutId);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
122
133
|
}
|
|
123
134
|
exports.GenetecAgent = GenetecAgent;
|
package/cjs/index.d.ts
CHANGED
|
@@ -14,5 +14,11 @@ export * from './types/CamSwitcherEvents';
|
|
|
14
14
|
export * from './types/CamSwitcherAPI';
|
|
15
15
|
export * from './types/VapixAPI';
|
|
16
16
|
export * from './types/CamOverlayAPI';
|
|
17
|
-
export * from './
|
|
17
|
+
export * from './types/CamOverlayAPI/CamOverlayAPI';
|
|
18
18
|
export * from './types/PlaneTrackerAPI';
|
|
19
|
+
export { Frame } from './CamOverlayPainter/Frame';
|
|
20
|
+
export { Painter } from './CamOverlayPainter/Painter';
|
|
21
|
+
export { ResourceManager } from './CamOverlayPainter/ResourceManager';
|
|
22
|
+
export * from './types/CamOverlayPainter';
|
|
23
|
+
export { CamOverlayDrawingAPI } from './CamOverlayDrawingAPI';
|
|
24
|
+
export * from './types/CamOverlayDrawingAPI';
|
package/cjs/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.PlaneTrackerAPI = exports.CamStreamerAPI = exports.CamScripterAPI = exports.CamOverlayAPI = exports.VapixAPI = exports.CamSwitcherEvents = exports.CamSwitcherAPI = void 0;
|
|
17
|
+
exports.CamOverlayDrawingAPI = exports.ResourceManager = exports.Painter = exports.Frame = exports.PlaneTrackerAPI = exports.CamStreamerAPI = exports.CamScripterAPI = exports.CamOverlayAPI = exports.VapixAPI = exports.CamSwitcherEvents = exports.CamSwitcherAPI = void 0;
|
|
18
18
|
__exportStar(require("./internal/types"), exports);
|
|
19
19
|
__exportStar(require("./internal/constants"), exports);
|
|
20
20
|
__exportStar(require("./internal/utils"), exports);
|
|
@@ -38,5 +38,15 @@ __exportStar(require("./types/CamSwitcherEvents"), exports);
|
|
|
38
38
|
__exportStar(require("./types/CamSwitcherAPI"), exports);
|
|
39
39
|
__exportStar(require("./types/VapixAPI"), exports);
|
|
40
40
|
__exportStar(require("./types/CamOverlayAPI"), exports);
|
|
41
|
-
__exportStar(require("./
|
|
41
|
+
__exportStar(require("./types/CamOverlayAPI/CamOverlayAPI"), exports);
|
|
42
42
|
__exportStar(require("./types/PlaneTrackerAPI"), exports);
|
|
43
|
+
var Frame_1 = require("./CamOverlayPainter/Frame");
|
|
44
|
+
Object.defineProperty(exports, "Frame", { enumerable: true, get: function () { return Frame_1.Frame; } });
|
|
45
|
+
var Painter_1 = require("./CamOverlayPainter/Painter");
|
|
46
|
+
Object.defineProperty(exports, "Painter", { enumerable: true, get: function () { return Painter_1.Painter; } });
|
|
47
|
+
var ResourceManager_1 = require("./CamOverlayPainter/ResourceManager");
|
|
48
|
+
Object.defineProperty(exports, "ResourceManager", { enumerable: true, get: function () { return ResourceManager_1.ResourceManager; } });
|
|
49
|
+
__exportStar(require("./types/CamOverlayPainter"), exports);
|
|
50
|
+
var CamOverlayDrawingAPI_1 = require("./CamOverlayDrawingAPI");
|
|
51
|
+
Object.defineProperty(exports, "CamOverlayDrawingAPI", { enumerable: true, get: function () { return CamOverlayDrawingAPI_1.CamOverlayDrawingAPI; } });
|
|
52
|
+
__exportStar(require("./types/CamOverlayDrawingAPI"), exports);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { TProxyParam } from '../types/common';
|
|
1
|
+
import { IClient, TGetParams, TPostParams, TResponse } from './types';
|
|
2
|
+
import { TProxyParams } from '../types/common';
|
|
4
3
|
export declare class ProxyClient<Client extends IClient<TResponse> = IClient<TResponse>> {
|
|
5
|
-
client
|
|
6
|
-
|
|
7
|
-
constructor(client: Client,
|
|
8
|
-
get: (
|
|
9
|
-
post: (
|
|
4
|
+
private client;
|
|
5
|
+
private proxyParams;
|
|
6
|
+
constructor(client: Client, proxyParams: TProxyParams);
|
|
7
|
+
get: (params: TGetParams) => Promise<TResponse>;
|
|
8
|
+
post: (params: TPostParams) => Promise<TResponse>;
|
|
10
9
|
private getReal;
|
|
11
10
|
}
|
|
@@ -4,42 +4,36 @@ exports.ProxyClient = void 0;
|
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
5
|
class ProxyClient {
|
|
6
6
|
client;
|
|
7
|
-
|
|
8
|
-
constructor(client,
|
|
7
|
+
proxyParams;
|
|
8
|
+
constructor(client, proxyParams) {
|
|
9
9
|
this.client = client;
|
|
10
|
-
this.
|
|
10
|
+
this.proxyParams = proxyParams;
|
|
11
11
|
}
|
|
12
|
-
get = (
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const {
|
|
16
|
-
return this.client.get(
|
|
12
|
+
get = (params) => {
|
|
13
|
+
const { path, parameters, headers, timeout } = params;
|
|
14
|
+
const targetPath = (0, utils_1.addParametersToPath)(path, parameters);
|
|
15
|
+
const { realPath, realHeaders } = this.getReal(targetPath, headers);
|
|
16
|
+
return this.client.get({ path: realPath, headers: realHeaders, timeout });
|
|
17
17
|
};
|
|
18
|
-
post = (
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const {
|
|
22
|
-
return this.client.post(
|
|
18
|
+
post = (params) => {
|
|
19
|
+
const { path, data, parameters, headers, timeout } = params;
|
|
20
|
+
const targetPath = (0, utils_1.addParametersToPath)(path, parameters);
|
|
21
|
+
const { realPath, realHeaders } = this.getReal(targetPath, headers);
|
|
22
|
+
return this.client.post({ path: realPath, data, headers: realHeaders, timeout });
|
|
23
23
|
};
|
|
24
|
-
getReal = (
|
|
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
|
-
}
|
|
24
|
+
getReal = (targetPath, headers) => {
|
|
40
25
|
return {
|
|
41
|
-
|
|
42
|
-
realHeaders:
|
|
26
|
+
realPath: this.proxyParams.path,
|
|
27
|
+
realHeaders: {
|
|
28
|
+
...(headers ?? {}),
|
|
29
|
+
'x-target-camera-protocol': this.proxyParams.target.port === 443 ? 'https' : 'http',
|
|
30
|
+
'x-target-camera-path': targetPath,
|
|
31
|
+
'x-target-camera-ip': this.proxyParams.target.ip,
|
|
32
|
+
'x-target-camera-mdns': this.proxyParams.target.mdnsName,
|
|
33
|
+
'x-target-camera-port': String(this.proxyParams.target.port),
|
|
34
|
+
'x-target-camera-pass': this.proxyParams.target.pass,
|
|
35
|
+
'x-target-camera-user': this.proxyParams.target.user,
|
|
36
|
+
},
|
|
43
37
|
};
|
|
44
38
|
};
|
|
45
39
|
}
|
package/cjs/internal/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { Response as UndiciResponse } from 'undici';
|
|
3
4
|
export type Options = {
|
|
4
5
|
ip?: string;
|
|
@@ -14,16 +15,22 @@ export type HttpOptions = Options & {
|
|
|
14
15
|
export type WsOptions = Options;
|
|
15
16
|
export type TParameters = Record<string, string | number | boolean | null | undefined>;
|
|
16
17
|
export type TResponse = Response | UndiciResponse;
|
|
17
|
-
export type TGetParams =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
export type TGetParams = {
|
|
19
|
+
path: string;
|
|
20
|
+
parameters?: TParameters;
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
timeout?: number;
|
|
23
|
+
};
|
|
24
|
+
export type TPostParams = {
|
|
25
|
+
path: string;
|
|
26
|
+
data: string | Buffer | FormData;
|
|
27
|
+
parameters?: TParameters;
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
timeout?: number;
|
|
30
|
+
};
|
|
24
31
|
export interface IClient<TRes extends TResponse> {
|
|
25
|
-
get: (
|
|
26
|
-
post: (
|
|
32
|
+
get: (params: TGetParams) => Promise<TRes>;
|
|
33
|
+
post: (params: TPostParams) => Promise<TRes>;
|
|
27
34
|
}
|
|
28
35
|
export type TBlobResponse<Client extends IClient<TResponse>> = Awaited<ReturnType<Awaited<ReturnType<Client['get']>>['blob']>>;
|
|
29
36
|
export interface IWebsocket<Event extends {
|
package/cjs/internal/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TPlaylistPlayType } from '../types/CamSwitcherAPI';
|
|
2
|
-
import {
|
|
2
|
+
import { 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,7 +9,6 @@ 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
12
|
export declare function responseStringify(res: TResponse): Promise<string>;
|
|
14
13
|
export declare function pad(num: number, size: number): string;
|
|
15
14
|
export declare function isNullish<T>(value: T | undefined | null): value is undefined | null;
|
package/cjs/internal/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNullish = exports.pad = exports.responseStringify = exports.
|
|
3
|
+
exports.isNullish = exports.pad = exports.responseStringify = exports.isLoopPlayType = exports.isPlaylist = exports.isTracker = exports.isClip = exports.isStream = exports.isCamera = exports.arrayToUrl = exports.paramToUrl = exports.addParametersToPath = void 0;
|
|
4
4
|
const addParametersToPath = (path, params) => {
|
|
5
5
|
if (params === undefined || Object.keys(params).length === 0) {
|
|
6
6
|
return path;
|
|
@@ -43,10 +43,6 @@ const isPlaylist = (id) => id?.charAt(0) === 'p';
|
|
|
43
43
|
exports.isPlaylist = isPlaylist;
|
|
44
44
|
const isLoopPlayType = (playType) => playType.includes('LOOP');
|
|
45
45
|
exports.isLoopPlayType = isLoopPlayType;
|
|
46
|
-
function isClient(arg = {}) {
|
|
47
|
-
return 'get' in arg && 'post' in arg;
|
|
48
|
-
}
|
|
49
|
-
exports.isClient = isClient;
|
|
50
46
|
async function responseStringify(res) {
|
|
51
47
|
return JSON.stringify({
|
|
52
48
|
status: res.status,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { IClient, HttpOptions, TParameters } from '../internal/types';
|
|
1
|
+
import { IClient, HttpOptions, TGetParams, TPostParams } from '../internal/types';
|
|
3
2
|
import { Response as UndiciResponse } from 'undici';
|
|
4
3
|
export declare class DefaultClient implements IClient<UndiciResponse> {
|
|
5
4
|
private tls;
|
|
@@ -9,8 +8,7 @@ export declare class DefaultClient implements IClient<UndiciResponse> {
|
|
|
9
8
|
private pass;
|
|
10
9
|
private httpRequestSender;
|
|
11
10
|
constructor(opt?: HttpOptions);
|
|
12
|
-
get
|
|
13
|
-
|
|
14
|
-
post: (url: string, data: string | Buffer | FormData, parameters?: TParameters | undefined, headers?: Record<string, string> | undefined) => Promise<UndiciResponse>;
|
|
11
|
+
get: (params: TGetParams) => Promise<UndiciResponse>;
|
|
12
|
+
post: (params: TPostParams) => Promise<UndiciResponse>;
|
|
15
13
|
private getBaseConnectionParams;
|
|
16
14
|
}
|
|
@@ -25,31 +25,27 @@ class DefaultClient {
|
|
|
25
25
|
}
|
|
26
26
|
this.httpRequestSender = new HttpRequestSender_1.HttpRequestSender(agentOptions);
|
|
27
27
|
}
|
|
28
|
-
get
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
get = (...params) => {
|
|
32
|
-
const [path, parameters, headers] = params;
|
|
33
|
-
const options = this.getBaseConnectionParams('GET', path, parameters ?? {});
|
|
34
|
-
options.headers = headers;
|
|
28
|
+
get = (params) => {
|
|
29
|
+
const { path, parameters, headers, timeout } = params;
|
|
30
|
+
const options = this.getBaseConnectionParams('GET', path, parameters, headers, timeout);
|
|
35
31
|
return this.httpRequestSender.sendRequest(options);
|
|
36
32
|
};
|
|
37
|
-
post = (
|
|
38
|
-
const
|
|
39
|
-
const options = this.getBaseConnectionParams('POST', path, parameters
|
|
40
|
-
options.headers = headers;
|
|
33
|
+
post = (params) => {
|
|
34
|
+
const { path, data, parameters, headers, timeout } = params;
|
|
35
|
+
const options = this.getBaseConnectionParams('POST', path, parameters, headers, timeout);
|
|
41
36
|
return this.httpRequestSender.sendRequest(options, data);
|
|
42
37
|
};
|
|
43
|
-
getBaseConnectionParams(method, path, params) {
|
|
44
|
-
const pathName = (0, utils_1.addParametersToPath)(path, params);
|
|
38
|
+
getBaseConnectionParams(method, path, params, headers, timeout) {
|
|
45
39
|
return {
|
|
46
40
|
method: method,
|
|
47
41
|
protocol: this.tls ? 'https:' : 'http:',
|
|
48
42
|
host: this.ip,
|
|
49
43
|
port: this.port,
|
|
50
|
-
path:
|
|
44
|
+
path: (0, utils_1.addParametersToPath)(path, params),
|
|
51
45
|
user: this.user,
|
|
52
46
|
pass: this.pass,
|
|
47
|
+
headers,
|
|
48
|
+
timeout,
|
|
53
49
|
};
|
|
54
50
|
}
|
|
55
51
|
}
|
|
@@ -11,8 +11,18 @@ class HttpRequestSender {
|
|
|
11
11
|
connect: { rejectUnauthorized: agentOptions?.rejectUnaurhorized, keepAlive: agentOptions?.keepAlive },
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
-
sendRequest(options, postData) {
|
|
15
|
-
|
|
14
|
+
async sendRequest(options, postData) {
|
|
15
|
+
const stackHolder = { stack: '' };
|
|
16
|
+
Error.captureStackTrace(stackHolder, this.sendRequest);
|
|
17
|
+
try {
|
|
18
|
+
return await this.sendRequestWithAuth(options, postData);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
if (err instanceof Error) {
|
|
22
|
+
err.stack = `${err.stack}\nCaptured at:\n${stackHolder.stack}`;
|
|
23
|
+
}
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
16
26
|
}
|
|
17
27
|
async sendRequestWithAuth(options, postData, wwwAuthenticateHeader) {
|
|
18
28
|
options.timeout ??= 10000;
|
|
@@ -82,7 +92,7 @@ class HttpRequestSender {
|
|
|
82
92
|
return authData.digest.getAuthHeader(options.user, options.pass, options.method ?? 'GET', options.path, authData.wwwAuthenticateHeader);
|
|
83
93
|
}
|
|
84
94
|
else {
|
|
85
|
-
return `Basic ${
|
|
95
|
+
return `Basic ${Buffer.from(`${options.user}:${options.pass}`).toString('base64')}`;
|
|
86
96
|
}
|
|
87
97
|
}
|
|
88
98
|
}
|
package/cjs/node/WsClient.d.ts
CHANGED
package/cjs/node/index.d.ts
CHANGED
package/cjs/node/index.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WsClient = exports.DefaultClient = void 0;
|
|
17
|
+
exports.AxisCameraStationEvents = exports.WsClient = exports.DefaultClient = void 0;
|
|
4
18
|
var DefaultClient_1 = require("./DefaultClient");
|
|
5
19
|
Object.defineProperty(exports, "DefaultClient", { enumerable: true, get: function () { return DefaultClient_1.DefaultClient; } });
|
|
6
20
|
var WsClient_1 = require("./WsClient");
|
|
7
21
|
Object.defineProperty(exports, "WsClient", { enumerable: true, get: function () { return WsClient_1.WsClient; } });
|
|
22
|
+
var AxisCameraStationEvents_1 = require("../events/AxisCameraStationEvents");
|
|
23
|
+
Object.defineProperty(exports, "AxisCameraStationEvents", { enumerable: true, get: function () { return AxisCameraStationEvents_1.AxisCameraStationEvents; } });
|
|
24
|
+
__exportStar(require("../events/GenetecAgent"), exports);
|