camstreamerlib 2.0.6 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CamOverlayAPI.d.ts +9 -14
- package/CamOverlayAPI.js +46 -46
- package/CamOverlayDrawingAPI.d.ts +20 -23
- package/CamOverlayDrawingAPI.js +35 -18
- package/CamOverlayPainter/Frame.d.ts +59 -0
- package/CamOverlayPainter/Frame.js +182 -0
- package/CamOverlayPainter/Painter.d.ts +33 -0
- package/CamOverlayPainter/Painter.js +113 -0
- package/CamOverlayPainter/ResourceManager.d.ts +14 -0
- package/CamOverlayPainter/ResourceManager.js +62 -0
- package/CamScripterAPICameraEventsGenerator.d.ts +15 -14
- package/CamScripterAPICameraEventsGenerator.js +14 -9
- package/CamStreamerAPI.d.ts +31 -12
- package/CamStreamerAPI.js +18 -23
- package/CamSwitcherAPI.d.ts +47 -19
- package/CamSwitcherAPI.js +26 -74
- package/CamSwitcherEvents.d.ts +17 -0
- package/CamSwitcherEvents.js +88 -0
- package/CameraVapix.d.ts +26 -35
- package/CameraVapix.js +35 -120
- package/CreatePackage.js +8 -4
- package/DefaultAgent.d.ts +15 -0
- package/DefaultAgent.js +67 -0
- package/HttpServer.d.ts +2 -2
- package/HttpServer.js +10 -7
- package/README.md +26 -12
- package/VapixEvents.d.ts +16 -0
- package/VapixEvents.js +89 -0
- package/events/AxisCameraStationEvents.d.ts +8 -0
- package/events/AxisCameraStationEvents.js +65 -0
- package/{Digest.js → internal/Digest.js} +9 -9
- package/internal/HttpRequest.d.ts +15 -0
- package/internal/HttpRequest.js +82 -0
- package/{WsClient.d.ts → internal/WsClient.d.ts} +7 -6
- package/{WsClient.js → internal/WsClient.js} +29 -29
- package/internal/common.d.ts +17 -0
- package/internal/common.js +7 -0
- package/internal/fetchInsecure.d.ts +4 -0
- package/internal/fetchInsecure.js +14 -0
- package/package.json +22 -9
- package/HttpRequest.d.ts +0 -15
- package/HttpRequest.js +0 -88
- package/common.d.ts +0 -7
- package/common.js +0 -2
- /package/{Digest.d.ts → internal/Digest.d.ts} +0 -0
package/CamOverlayAPI.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Options } from './common';
|
|
2
|
+
import { IClient, Options } from './internal/common';
|
|
3
3
|
export type CamOverlayOptions = Options;
|
|
4
|
-
export type
|
|
4
|
+
export type TField = {
|
|
5
5
|
field_name: string;
|
|
6
6
|
text: string;
|
|
7
7
|
color?: string;
|
|
8
8
|
};
|
|
9
|
-
export type
|
|
9
|
+
export type TService = {
|
|
10
10
|
id: number;
|
|
11
11
|
enabled: number;
|
|
12
12
|
schedule: string;
|
|
@@ -14,29 +14,24 @@ export type Service = {
|
|
|
14
14
|
identifier: string;
|
|
15
15
|
cameraList: number[];
|
|
16
16
|
};
|
|
17
|
-
export type
|
|
18
|
-
services:
|
|
17
|
+
export type TServiceList = {
|
|
18
|
+
services: TService[];
|
|
19
19
|
};
|
|
20
20
|
export declare enum ImageType {
|
|
21
21
|
PNG = 0,
|
|
22
22
|
JPEG = 1
|
|
23
23
|
}
|
|
24
24
|
export declare class CamOverlayAPI {
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
private port;
|
|
29
|
-
private auth;
|
|
30
|
-
constructor(options?: CamOverlayOptions);
|
|
31
|
-
updateCGText(serviceID: number, fields: Field[]): Promise<void>;
|
|
25
|
+
private client;
|
|
26
|
+
constructor(options?: CamOverlayOptions | IClient);
|
|
27
|
+
updateCGText(serviceID: number, fields: TField[]): Promise<void>;
|
|
32
28
|
updateCGImagePos(serviceID: number, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
33
29
|
updateCGImage(serviceID: number, path: string, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
34
30
|
updateInfoticker(serviceID: number, text: string): Promise<void>;
|
|
35
31
|
setEnabled(serviceID: number, enabled: boolean): Promise<void>;
|
|
36
32
|
isEnabled(serviceID: number): Promise<boolean>;
|
|
37
|
-
updateServices(servicesJson:
|
|
33
|
+
updateServices(servicesJson: TServiceList): Promise<void>;
|
|
38
34
|
updateCGImageFromData(serviceID: number, imageType: ImageType, imageData: Buffer, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
39
35
|
promiseCGUpdate(serviceID: number, action: string, params: string, contentType?: string, data?: Buffer): Promise<void>;
|
|
40
36
|
private formCoordinates;
|
|
41
|
-
private getBaseVapixConnectionParams;
|
|
42
37
|
}
|
package/CamOverlayAPI.js
CHANGED
|
@@ -10,24 +10,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CamOverlayAPI = exports.ImageType = void 0;
|
|
13
|
-
const
|
|
13
|
+
const common_1 = require("./internal/common");
|
|
14
|
+
const DefaultAgent_1 = require("./DefaultAgent");
|
|
14
15
|
var ImageType;
|
|
15
16
|
(function (ImageType) {
|
|
16
17
|
ImageType[ImageType["PNG"] = 0] = "PNG";
|
|
17
18
|
ImageType[ImageType["JPEG"] = 1] = "JPEG";
|
|
18
|
-
})(ImageType
|
|
19
|
+
})(ImageType || (exports.ImageType = ImageType = {}));
|
|
19
20
|
class CamOverlayAPI {
|
|
20
|
-
constructor(options) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
if ((0, common_1.isClient)(options)) {
|
|
23
|
+
this.client = options;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
this.client = new DefaultAgent_1.DefaultAgent(options);
|
|
27
|
+
}
|
|
27
28
|
}
|
|
28
29
|
updateCGText(serviceID, fields) {
|
|
29
30
|
let field_specs = '';
|
|
30
|
-
for (
|
|
31
|
+
for (const field of fields) {
|
|
31
32
|
const name = field.field_name;
|
|
32
33
|
field_specs += `&${name}=${field.text}`;
|
|
33
34
|
if (field.color !== undefined) {
|
|
@@ -47,41 +48,47 @@ class CamOverlayAPI {
|
|
|
47
48
|
}
|
|
48
49
|
updateInfoticker(serviceID, text) {
|
|
49
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const path = `/local/camoverlay/api/infoticker.cgi?service_id=${serviceID}&text=${text}`;
|
|
52
|
+
const res = yield this.client.get(path);
|
|
53
|
+
if (!res.ok) {
|
|
54
|
+
throw new Error(JSON.stringify(res));
|
|
55
|
+
}
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
setEnabled(serviceID, enabled) {
|
|
57
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const path = `/local/camoverlay/api/enabled.cgi?id_${serviceID}=${enabled ? 1 : 0}`;
|
|
61
|
+
const res = yield this.client.post(path, '');
|
|
62
|
+
if (!res.ok) {
|
|
63
|
+
throw new Error(JSON.stringify(res));
|
|
64
|
+
}
|
|
62
65
|
});
|
|
63
66
|
}
|
|
64
67
|
isEnabled(serviceID) {
|
|
65
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
const path = '/local/camoverlay/api/services.cgi?action=get';
|
|
70
|
+
const res = yield this.client.get(path);
|
|
71
|
+
if (res.ok) {
|
|
72
|
+
const data = JSON.parse(yield res.text());
|
|
73
|
+
for (const service of data.services) {
|
|
74
|
+
if (service.id === serviceID) {
|
|
75
|
+
return service.enabled === 1;
|
|
76
|
+
}
|
|
74
77
|
}
|
|
78
|
+
throw new Error('Service not found.');
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
throw new Error(JSON.stringify(res));
|
|
75
82
|
}
|
|
76
|
-
throw new Error('Service not found.');
|
|
77
83
|
});
|
|
78
84
|
}
|
|
79
85
|
updateServices(servicesJson) {
|
|
80
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
const path = '/local/camoverlay/api/services.cgi?action=set';
|
|
88
|
+
const res = yield this.client.post(path, JSON.stringify(servicesJson));
|
|
89
|
+
if (!res.ok) {
|
|
90
|
+
throw new Error(JSON.stringify(res));
|
|
91
|
+
}
|
|
85
92
|
});
|
|
86
93
|
}
|
|
87
94
|
updateCGImageFromData(serviceID, imageType, imageData, coordinates = '', x = 0, y = 0) {
|
|
@@ -91,26 +98,19 @@ class CamOverlayAPI {
|
|
|
91
98
|
}
|
|
92
99
|
promiseCGUpdate(serviceID, action, params, contentType, data) {
|
|
93
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
const path = `/local/camoverlay/api/customGraphics.cgi?action=${action}&service_id=${serviceID}${params}`;
|
|
102
|
+
let headers = {};
|
|
103
|
+
if (contentType !== undefined && data) {
|
|
104
|
+
headers = { 'Content-Type': contentType };
|
|
105
|
+
}
|
|
106
|
+
const res = yield this.client.post(path, data !== null && data !== void 0 ? data : '', {}, headers);
|
|
107
|
+
if (!res.ok) {
|
|
108
|
+
throw new Error(JSON.stringify(res));
|
|
99
109
|
}
|
|
100
|
-
yield (0, HttpRequest_1.httpRequest)(options, data);
|
|
101
110
|
});
|
|
102
111
|
}
|
|
103
112
|
formCoordinates(coordinates, x, y) {
|
|
104
113
|
return coordinates !== '' ? `&coord_system=${coordinates}&pos_x=${x}&pos_y=${y}` : '';
|
|
105
114
|
}
|
|
106
|
-
getBaseVapixConnectionParams() {
|
|
107
|
-
return {
|
|
108
|
-
protocol: this.tls ? 'https:' : 'http:',
|
|
109
|
-
host: this.ip,
|
|
110
|
-
port: this.port,
|
|
111
|
-
auth: this.auth,
|
|
112
|
-
rejectUnauthorized: !this.tlsInsecure,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
115
|
}
|
|
116
116
|
exports.CamOverlayAPI = CamOverlayAPI;
|
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import * as EventEmitter from 'events';
|
|
4
|
-
import { Options } from './common';
|
|
5
|
-
type CamOverlayDrawingOptions = Options & {
|
|
4
|
+
import { Options } from './internal/common';
|
|
5
|
+
export type CamOverlayDrawingOptions = Options & {
|
|
6
6
|
camera?: number | number[];
|
|
7
7
|
zIndex?: number;
|
|
8
8
|
};
|
|
9
|
-
export type
|
|
10
|
-
command: string;
|
|
11
|
-
params?: any[];
|
|
12
|
-
};
|
|
13
|
-
export type CairoResponse = {
|
|
9
|
+
export type TCairoResponse = {
|
|
14
10
|
message: string;
|
|
15
11
|
call_id: number;
|
|
16
12
|
};
|
|
17
|
-
export type
|
|
13
|
+
export type TCairoCreateResponse = {
|
|
18
14
|
var: string;
|
|
19
15
|
call_id: number;
|
|
20
16
|
};
|
|
21
|
-
export type
|
|
17
|
+
export type TUploadImageResponse = {
|
|
22
18
|
var: string;
|
|
23
19
|
width: number;
|
|
24
20
|
height: number;
|
|
25
21
|
call_id: number;
|
|
26
22
|
};
|
|
27
|
-
export type
|
|
23
|
+
export type TService = {
|
|
28
24
|
id: number;
|
|
29
25
|
enabled: number;
|
|
30
26
|
schedule: string;
|
|
@@ -32,33 +28,35 @@ export type Service = {
|
|
|
32
28
|
identifier: string;
|
|
33
29
|
cameraList: number[];
|
|
34
30
|
};
|
|
35
|
-
export type
|
|
36
|
-
services:
|
|
31
|
+
export type TServiceList = {
|
|
32
|
+
services: TService[];
|
|
37
33
|
};
|
|
38
|
-
export type
|
|
34
|
+
export type TAlign = 'A_RIGHT' | 'A_LEFT' | 'A_CENTER';
|
|
39
35
|
export type TextFit = 'TFM_SCALE' | 'TFM_TRUNCATE' | 'TFM_OVERFLOW';
|
|
40
|
-
export type
|
|
36
|
+
export type TWriteTextParams = [string, string, number, number, number, number, TAlign, TextFit?];
|
|
41
37
|
export declare class CamOverlayDrawingAPI extends EventEmitter {
|
|
42
38
|
private tls;
|
|
43
39
|
private tlsInsecure;
|
|
44
40
|
private ip;
|
|
45
41
|
private port;
|
|
46
|
-
private
|
|
42
|
+
private user;
|
|
43
|
+
private pass;
|
|
47
44
|
private cameraList;
|
|
48
45
|
private zIndex;
|
|
49
46
|
private callId;
|
|
50
47
|
private sendMessages;
|
|
48
|
+
private connected;
|
|
51
49
|
private ws?;
|
|
52
50
|
constructor(options?: CamOverlayDrawingOptions);
|
|
53
51
|
connect(): Promise<void>;
|
|
54
52
|
disconnect(): void;
|
|
55
|
-
cairo(command: string, ...params:
|
|
56
|
-
writeText(...params:
|
|
57
|
-
uploadImageData(imgBuffer: Buffer): Promise<
|
|
58
|
-
uploadFontData(fontBuffer: Buffer): Promise<
|
|
59
|
-
showCairoImage(cairoImage: string, posX: number, posY: number): Promise<
|
|
60
|
-
showCairoImageAbsolute(cairoImage: string, posX: number, posY: number, width: number, height: number): Promise<
|
|
61
|
-
removeImage(): Promise<
|
|
53
|
+
cairo(command: string, ...params: unknown[]): Promise<TCairoResponse | TCairoCreateResponse>;
|
|
54
|
+
writeText(...params: TWriteTextParams): Promise<TCairoResponse>;
|
|
55
|
+
uploadImageData(imgBuffer: Buffer): Promise<TUploadImageResponse>;
|
|
56
|
+
uploadFontData(fontBuffer: Buffer): Promise<TCairoCreateResponse>;
|
|
57
|
+
showCairoImage(cairoImage: string, posX: number, posY: number): Promise<TCairoResponse>;
|
|
58
|
+
showCairoImageAbsolute(cairoImage: string, posX: number, posY: number, width: number, height: number): Promise<TCairoResponse>;
|
|
59
|
+
removeImage(): Promise<TCairoResponse>;
|
|
62
60
|
private openWebsocket;
|
|
63
61
|
private sendMessage;
|
|
64
62
|
private sendBinaryMessage;
|
|
@@ -66,4 +64,3 @@ export declare class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
66
64
|
private reportError;
|
|
67
65
|
private reportClose;
|
|
68
66
|
}
|
|
69
|
-
export {};
|
package/CamOverlayDrawingAPI.js
CHANGED
|
@@ -11,19 +11,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CamOverlayDrawingAPI = void 0;
|
|
13
13
|
const EventEmitter = require("events");
|
|
14
|
-
const
|
|
14
|
+
const promises_1 = require("timers/promises");
|
|
15
|
+
const WsClient_1 = require("./internal/WsClient");
|
|
15
16
|
class CamOverlayDrawingAPI extends EventEmitter {
|
|
16
17
|
constructor(options) {
|
|
17
|
-
var _a, _b, _c, _d, _e, _f;
|
|
18
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
18
19
|
super();
|
|
20
|
+
this.connected = false;
|
|
19
21
|
this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
|
|
20
22
|
this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
|
|
21
23
|
this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
|
|
22
24
|
this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
+
this.user = (_e = options === null || options === void 0 ? void 0 : options.user) !== null && _e !== void 0 ? _e : '';
|
|
26
|
+
this.pass = (_f = options === null || options === void 0 ? void 0 : options.pass) !== null && _f !== void 0 ? _f : '';
|
|
27
|
+
this.zIndex = (_g = options === null || options === void 0 ? void 0 : options.zIndex) !== null && _g !== void 0 ? _g : 0;
|
|
25
28
|
this.cameraList = [0];
|
|
26
|
-
if (Array.isArray(options
|
|
29
|
+
if (options && Array.isArray(options.camera)) {
|
|
27
30
|
this.cameraList = options.camera;
|
|
28
31
|
}
|
|
29
32
|
else if (typeof (options === null || options === void 0 ? void 0 : options.camera) === 'number') {
|
|
@@ -37,13 +40,14 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
37
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
41
|
try {
|
|
39
42
|
yield this.openWebsocket();
|
|
40
|
-
this.
|
|
43
|
+
this.connected = true;
|
|
41
44
|
}
|
|
42
45
|
catch (err) {
|
|
43
46
|
}
|
|
44
47
|
});
|
|
45
48
|
}
|
|
46
49
|
disconnect() {
|
|
50
|
+
this.connected = false;
|
|
47
51
|
if (this.ws !== undefined) {
|
|
48
52
|
this.ws.close();
|
|
49
53
|
}
|
|
@@ -94,27 +98,28 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
94
98
|
port: this.port,
|
|
95
99
|
address: '/local/camoverlay/ws',
|
|
96
100
|
protocol: 'cairo-api',
|
|
97
|
-
|
|
101
|
+
user: this.user,
|
|
102
|
+
pass: this.pass,
|
|
98
103
|
tls: this.tls,
|
|
99
104
|
tlsInsecure: this.tlsInsecure,
|
|
100
105
|
};
|
|
101
106
|
this.ws = new WsClient_1.WsClient(options);
|
|
102
107
|
this.ws.on('open', () => {
|
|
103
|
-
this.
|
|
108
|
+
this.emit('open');
|
|
104
109
|
resolve();
|
|
105
110
|
});
|
|
106
111
|
this.ws.on('message', (data) => {
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
if (
|
|
110
|
-
this.sendMessages[dataJSON
|
|
112
|
+
const dataJSON = JSON.parse(data.toString());
|
|
113
|
+
if (Object.hasOwn(dataJSON, 'call_id') && dataJSON['call_id'] in this.sendMessages) {
|
|
114
|
+
if (Object.hasOwn(dataJSON, 'error')) {
|
|
115
|
+
this.sendMessages[dataJSON.call_id].reject(new Error(dataJSON.error));
|
|
111
116
|
}
|
|
112
117
|
else {
|
|
113
|
-
this.sendMessages[dataJSON
|
|
118
|
+
this.sendMessages[dataJSON.call_id].resolve(dataJSON);
|
|
114
119
|
}
|
|
115
120
|
delete this.sendMessages[dataJSON['call_id']];
|
|
116
121
|
}
|
|
117
|
-
if (
|
|
122
|
+
if (Object.hasOwn(dataJSON, 'error')) {
|
|
118
123
|
this.reportError(new Error(dataJSON.error));
|
|
119
124
|
}
|
|
120
125
|
else {
|
|
@@ -125,10 +130,20 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
125
130
|
this.reportError(error);
|
|
126
131
|
reject(error);
|
|
127
132
|
});
|
|
128
|
-
this.ws.on('close', () => {
|
|
133
|
+
this.ws.on('close', () => __awaiter(this, void 0, void 0, function* () {
|
|
129
134
|
this.ws = undefined;
|
|
130
135
|
this.reportClose();
|
|
131
|
-
|
|
136
|
+
if (this.connected) {
|
|
137
|
+
try {
|
|
138
|
+
yield (0, promises_1.setTimeout)(10000);
|
|
139
|
+
yield this.openWebsocket();
|
|
140
|
+
resolve();
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
reject(err);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}));
|
|
132
147
|
this.ws.open();
|
|
133
148
|
});
|
|
134
149
|
}
|
|
@@ -143,7 +158,8 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
143
158
|
this.ws.send(JSON.stringify(msgJson));
|
|
144
159
|
}
|
|
145
160
|
catch (err) {
|
|
146
|
-
|
|
161
|
+
const errorMessage = (err instanceof Error) ? err.message : err;
|
|
162
|
+
this.reportError(new Error(`Send message error: ${errorMessage}`));
|
|
147
163
|
}
|
|
148
164
|
});
|
|
149
165
|
}
|
|
@@ -164,7 +180,8 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
164
180
|
this.ws.send(msgBuffer);
|
|
165
181
|
}
|
|
166
182
|
catch (err) {
|
|
167
|
-
|
|
183
|
+
const errorMessage = (err instanceof Error) ? err.message : err;
|
|
184
|
+
this.reportError(new Error(`Send binary message error: ${errorMessage}`));
|
|
168
185
|
}
|
|
169
186
|
});
|
|
170
187
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { CamOverlayDrawingAPI, TAlign, TUploadImageResponse } from '../CamOverlayDrawingAPI';
|
|
2
|
+
import ResourceManager from './ResourceManager';
|
|
3
|
+
export type TRgb = [number, number, number];
|
|
4
|
+
export type TRgba = [number, number, number, number];
|
|
5
|
+
export type TTmf = 'TFM_OVERFLOW' | 'TFM_SCALE' | 'TFM_TRUNCATE';
|
|
6
|
+
export type TObjectFitType = 'fill' | 'fit' | 'none';
|
|
7
|
+
export type FrameOptions = {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
bgImage?: string;
|
|
14
|
+
text?: string;
|
|
15
|
+
fontColor?: TRgb;
|
|
16
|
+
bgColor?: TRgba;
|
|
17
|
+
bgType?: TObjectFitType;
|
|
18
|
+
};
|
|
19
|
+
export type TFrameInfo = {
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
23
|
+
export type TDrawingCallback = (cod: CamOverlayDrawingAPI, cairo: string, info: TFrameInfo) => Promise<void>;
|
|
24
|
+
export default class Frame {
|
|
25
|
+
private customDraw?;
|
|
26
|
+
protected posX: number;
|
|
27
|
+
protected posY: number;
|
|
28
|
+
protected width: number;
|
|
29
|
+
protected height: number;
|
|
30
|
+
protected enabled: boolean;
|
|
31
|
+
private text;
|
|
32
|
+
private align;
|
|
33
|
+
private textType;
|
|
34
|
+
private fontColor;
|
|
35
|
+
private fontName?;
|
|
36
|
+
private bgColor?;
|
|
37
|
+
private bgImage?;
|
|
38
|
+
private bgType?;
|
|
39
|
+
protected children: Frame[];
|
|
40
|
+
constructor(opt: FrameOptions, customDraw?: TDrawingCallback | undefined);
|
|
41
|
+
setFramePosition(x: number, y: number): void;
|
|
42
|
+
setFrameSize(width: number, height: number): void;
|
|
43
|
+
setText(text: string, align: TAlign, textType?: TTmf, color?: TRgb): void;
|
|
44
|
+
setFont(fontName: string): void;
|
|
45
|
+
setBgColor(color: TRgba): void;
|
|
46
|
+
setBgImage(imageName: string, type?: TObjectFitType): void;
|
|
47
|
+
setBgImageData(imageData: TUploadImageResponse, type?: TObjectFitType): void;
|
|
48
|
+
setCustomDraw(customDraw: TDrawingCallback): void;
|
|
49
|
+
clear(): void;
|
|
50
|
+
insert(...frames: Frame[]): void;
|
|
51
|
+
enable(): void;
|
|
52
|
+
disable(): void;
|
|
53
|
+
displayImage(cod: CamOverlayDrawingAPI, rm: ResourceManager, cairo: string, ppX: number, ppY: number, scale?: number): Promise<void>;
|
|
54
|
+
protected displayOwnImage(cod: CamOverlayDrawingAPI, rm: ResourceManager, cairo: string, ppX: number, ppY: number, scale: number): Promise<void>;
|
|
55
|
+
private drawFrame;
|
|
56
|
+
private drawImage;
|
|
57
|
+
private drawText;
|
|
58
|
+
}
|
|
59
|
+
export { Frame };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Frame = void 0;
|
|
13
|
+
class Frame {
|
|
14
|
+
constructor(opt, customDraw) {
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
this.customDraw = customDraw;
|
|
17
|
+
this.text = '';
|
|
18
|
+
this.align = 'A_LEFT';
|
|
19
|
+
this.textType = 'TFM_OVERFLOW';
|
|
20
|
+
this.children = new Array();
|
|
21
|
+
this.posX = opt.x;
|
|
22
|
+
this.posY = opt.y;
|
|
23
|
+
this.width = opt.width;
|
|
24
|
+
this.height = opt.height;
|
|
25
|
+
this.enabled = (_a = opt.enabled) !== null && _a !== void 0 ? _a : true;
|
|
26
|
+
this.setText((_b = opt.text) !== null && _b !== void 0 ? _b : '', 'A_LEFT');
|
|
27
|
+
this.fontColor = (_c = opt.fontColor) !== null && _c !== void 0 ? _c : [1.0, 1.0, 1.0];
|
|
28
|
+
this.bgColor = opt.bgColor;
|
|
29
|
+
this.bgImage = opt.bgImage;
|
|
30
|
+
this.bgType = opt.bgType;
|
|
31
|
+
}
|
|
32
|
+
setFramePosition(x, y) {
|
|
33
|
+
this.posX = x;
|
|
34
|
+
this.posY = y;
|
|
35
|
+
}
|
|
36
|
+
setFrameSize(width, height) {
|
|
37
|
+
this.width = width;
|
|
38
|
+
this.height = height;
|
|
39
|
+
}
|
|
40
|
+
setText(text, align, textType = 'TFM_OVERFLOW', color) {
|
|
41
|
+
this.text = text;
|
|
42
|
+
this.align = align;
|
|
43
|
+
this.textType = textType;
|
|
44
|
+
if (color) {
|
|
45
|
+
this.fontColor = color;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
setFont(fontName) {
|
|
49
|
+
this.fontName = fontName;
|
|
50
|
+
}
|
|
51
|
+
setBgColor(color) {
|
|
52
|
+
this.bgColor = color;
|
|
53
|
+
}
|
|
54
|
+
setBgImage(imageName, type = 'fit') {
|
|
55
|
+
this.bgImage = imageName;
|
|
56
|
+
this.bgType = type;
|
|
57
|
+
}
|
|
58
|
+
setBgImageData(imageData, type = 'fit') {
|
|
59
|
+
this.bgImage = imageData;
|
|
60
|
+
this.bgType = type;
|
|
61
|
+
}
|
|
62
|
+
setCustomDraw(customDraw) {
|
|
63
|
+
this.customDraw = customDraw;
|
|
64
|
+
}
|
|
65
|
+
clear() {
|
|
66
|
+
this.text = '';
|
|
67
|
+
this.align = 'A_LEFT';
|
|
68
|
+
this.fontColor = [1.0, 1.0, 1.0];
|
|
69
|
+
this.bgColor = undefined;
|
|
70
|
+
this.bgImage = undefined;
|
|
71
|
+
}
|
|
72
|
+
insert(...frames) {
|
|
73
|
+
this.children.push(...frames);
|
|
74
|
+
}
|
|
75
|
+
enable() {
|
|
76
|
+
this.enabled = true;
|
|
77
|
+
}
|
|
78
|
+
disable() {
|
|
79
|
+
this.enabled = false;
|
|
80
|
+
}
|
|
81
|
+
displayImage(cod, rm, cairo, ppX, ppY, scale = 1) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (this.enabled) {
|
|
84
|
+
ppX += this.posX;
|
|
85
|
+
ppY += this.posY;
|
|
86
|
+
yield this.displayOwnImage(cod, rm, cairo, ppX, ppY, scale);
|
|
87
|
+
for (const child of this.children) {
|
|
88
|
+
yield child.displayImage(cod, rm, cairo, ppX, ppY, scale);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
displayOwnImage(cod, rm, cairo, ppX, ppY, scale) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
if (this.enabled) {
|
|
96
|
+
const promises = new Array();
|
|
97
|
+
if (this.fontName !== undefined) {
|
|
98
|
+
const fontData = yield rm.font(this.fontName);
|
|
99
|
+
promises.push(cod.cairo('cairo_set_font_face', cairo, fontData.var));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
promises.push(cod.cairo('cairo_set_font_face', cairo, 'NULL'));
|
|
103
|
+
}
|
|
104
|
+
if (this.bgColor !== undefined) {
|
|
105
|
+
promises.push(this.drawFrame(cod, cairo, scale, ppX, ppY));
|
|
106
|
+
}
|
|
107
|
+
if (this.bgImage !== undefined) {
|
|
108
|
+
promises.push(this.drawImage(cod, rm, cairo, scale, ppX, ppY));
|
|
109
|
+
}
|
|
110
|
+
if (this.text) {
|
|
111
|
+
promises.push(this.drawText(cod, cairo, scale, ppX, ppY));
|
|
112
|
+
}
|
|
113
|
+
if (this.customDraw) {
|
|
114
|
+
promises.push(cod.cairo('cairo_identity_matrix', cairo));
|
|
115
|
+
promises.push(cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY));
|
|
116
|
+
promises.push(cod.cairo('cairo_scale', cairo, scale, scale));
|
|
117
|
+
promises.push(this.customDraw(cod, cairo, { width: this.width, height: this.height }));
|
|
118
|
+
}
|
|
119
|
+
yield Promise.all(promises);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
drawFrame(cod, cairo, scale, ppX, ppY) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
if (this.bgColor) {
|
|
126
|
+
const promises = [
|
|
127
|
+
cod.cairo('cairo_identity_matrix', cairo),
|
|
128
|
+
cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
|
|
129
|
+
cod.cairo('cairo_scale', cairo, scale, scale),
|
|
130
|
+
cod.cairo('cairo_set_source_rgba', cairo, this.bgColor[0], this.bgColor[1], this.bgColor[2], this.bgColor[3]),
|
|
131
|
+
cod.cairo('cairo_rectangle', cairo, 0, 0, this.width, this.height),
|
|
132
|
+
cod.cairo('cairo_fill', cairo),
|
|
133
|
+
cod.cairo('cairo_stroke', cairo),
|
|
134
|
+
];
|
|
135
|
+
yield Promise.all(promises);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
throw new Error('Colour of this frame is undefined.');
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
drawImage(cod, rm, cairo, scale, ppX, ppY) {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
const imageData = typeof this.bgImage === 'string' ? yield rm.image(this.bgImage) : this.bgImage;
|
|
145
|
+
const bgImage = imageData.var;
|
|
146
|
+
const bgWidth = imageData.width;
|
|
147
|
+
const bgHeight = imageData.height;
|
|
148
|
+
const promises = new Array();
|
|
149
|
+
promises.push(cod.cairo('cairo_identity_matrix', cairo));
|
|
150
|
+
promises.push(cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY));
|
|
151
|
+
if (this.bgType === 'fill') {
|
|
152
|
+
const sx = (scale * this.width) / bgWidth;
|
|
153
|
+
const sy = (scale * this.height) / bgHeight;
|
|
154
|
+
promises.push(cod.cairo('cairo_scale', cairo, sx, sy));
|
|
155
|
+
}
|
|
156
|
+
else if (this.bgType === 'fit') {
|
|
157
|
+
const sx = this.width / bgWidth;
|
|
158
|
+
const sy = this.height / bgHeight;
|
|
159
|
+
const scaleRatio = scale * Math.min(sx, sy);
|
|
160
|
+
promises.push(cod.cairo('cairo_scale', cairo, scaleRatio, scaleRatio));
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
promises.push(cod.cairo('cairo_scale', cairo, scale, scale));
|
|
164
|
+
}
|
|
165
|
+
promises.push(cod.cairo('cairo_set_source_surface', cairo, bgImage, 0, 0));
|
|
166
|
+
promises.push(cod.cairo('cairo_paint', cairo));
|
|
167
|
+
yield Promise.all(promises);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
drawText(cod, cairo, scale, ppX, ppY) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
const promises = [
|
|
173
|
+
cod.cairo('cairo_identity_matrix', cairo),
|
|
174
|
+
cod.cairo('cairo_set_source_rgb', cairo, this.fontColor[0], this.fontColor[1], this.fontColor[2]),
|
|
175
|
+
cod.writeText(cairo, '' + this.text, Math.floor(scale * ppX), Math.floor(scale * ppY), Math.floor(scale * this.width), Math.floor(scale * this.height), this.align, this.textType),
|
|
176
|
+
];
|
|
177
|
+
yield Promise.all(promises);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.default = Frame;
|
|
182
|
+
exports.Frame = Frame;
|