camstreamerlib 2.0.6 → 3.0.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 -9
- package/CamOverlayAPI.js +49 -33
- package/CamOverlayDrawingAPI.d.ts +20 -25
- package/CamOverlayDrawingAPI.js +29 -16
- 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 -15
- package/CamScripterAPICameraEventsGenerator.js +14 -9
- package/CamStreamerAPI.d.ts +3 -2
- package/CamStreamerAPI.js +17 -9
- package/CamSwitcherAPI.d.ts +4 -4
- package/CamSwitcherAPI.js +23 -18
- package/CameraVapix.d.ts +27 -28
- package/CameraVapix.js +46 -47
- package/CreatePackage.js +8 -4
- package/HttpServer.d.ts +2 -4
- package/HttpServer.js +10 -7
- package/README.md +26 -12
- package/{Digest.js → internal/Digest.js} +9 -9
- package/internal/HttpRequest.d.ts +13 -0
- package/internal/HttpRequest.js +65 -0
- package/{WsClient.d.ts → internal/WsClient.d.ts} +7 -8
- package/{WsClient.js → internal/WsClient.js} +29 -29
- package/{common.d.ts → internal/common.d.ts} +2 -1
- package/package.json +21 -9
- package/HttpRequest.d.ts +0 -15
- package/HttpRequest.js +0 -88
- /package/{Digest.d.ts → internal/Digest.d.ts} +0 -0
- /package/{common.js → internal/common.js} +0 -0
package/CamOverlayAPI.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import { Options } from './common';
|
|
1
|
+
import { Options } from './internal/common';
|
|
3
2
|
export type CamOverlayOptions = Options;
|
|
4
|
-
export type
|
|
3
|
+
export type TField = {
|
|
5
4
|
field_name: string;
|
|
6
5
|
text: string;
|
|
7
6
|
color?: string;
|
|
8
7
|
};
|
|
9
|
-
export type
|
|
8
|
+
export type TService = {
|
|
10
9
|
id: number;
|
|
11
10
|
enabled: number;
|
|
12
11
|
schedule: string;
|
|
@@ -14,8 +13,8 @@ export type Service = {
|
|
|
14
13
|
identifier: string;
|
|
15
14
|
cameraList: number[];
|
|
16
15
|
};
|
|
17
|
-
export type
|
|
18
|
-
services:
|
|
16
|
+
export type TServiceList = {
|
|
17
|
+
services: TService[];
|
|
19
18
|
};
|
|
20
19
|
export declare enum ImageType {
|
|
21
20
|
PNG = 0,
|
|
@@ -26,15 +25,16 @@ export declare class CamOverlayAPI {
|
|
|
26
25
|
private tlsInsecure;
|
|
27
26
|
private ip;
|
|
28
27
|
private port;
|
|
29
|
-
private
|
|
28
|
+
private user;
|
|
29
|
+
private pass;
|
|
30
30
|
constructor(options?: CamOverlayOptions);
|
|
31
|
-
updateCGText(serviceID: number, fields:
|
|
31
|
+
updateCGText(serviceID: number, fields: TField[]): Promise<void>;
|
|
32
32
|
updateCGImagePos(serviceID: number, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
33
33
|
updateCGImage(serviceID: number, path: string, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
34
34
|
updateInfoticker(serviceID: number, text: string): Promise<void>;
|
|
35
35
|
setEnabled(serviceID: number, enabled: boolean): Promise<void>;
|
|
36
36
|
isEnabled(serviceID: number): Promise<boolean>;
|
|
37
|
-
updateServices(servicesJson:
|
|
37
|
+
updateServices(servicesJson: TServiceList): Promise<void>;
|
|
38
38
|
updateCGImageFromData(serviceID: number, imageType: ImageType, imageData: Buffer, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
39
39
|
promiseCGUpdate(serviceID: number, action: string, params: string, contentType?: string, data?: Buffer): Promise<void>;
|
|
40
40
|
private formCoordinates;
|
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 HttpRequest_1 = require("./HttpRequest");
|
|
13
|
+
const HttpRequest_1 = require("./internal/HttpRequest");
|
|
14
14
|
var ImageType;
|
|
15
15
|
(function (ImageType) {
|
|
16
16
|
ImageType[ImageType["PNG"] = 0] = "PNG";
|
|
17
17
|
ImageType[ImageType["JPEG"] = 1] = "JPEG";
|
|
18
|
-
})(ImageType
|
|
18
|
+
})(ImageType || (exports.ImageType = ImageType = {}));
|
|
19
19
|
class CamOverlayAPI {
|
|
20
20
|
constructor(options) {
|
|
21
|
-
var _a, _b, _c, _d, _e;
|
|
21
|
+
var _a, _b, _c, _d, _e, _f;
|
|
22
22
|
this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
|
|
23
23
|
this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
|
|
24
24
|
this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
|
|
25
25
|
this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
|
|
26
|
-
this.
|
|
26
|
+
this.user = (_e = options === null || options === void 0 ? void 0 : options.user) !== null && _e !== void 0 ? _e : '';
|
|
27
|
+
this.pass = (_f = options === null || options === void 0 ? void 0 : options.pass) !== null && _f !== void 0 ? _f : '';
|
|
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,51 @@ class CamOverlayAPI {
|
|
|
47
48
|
}
|
|
48
49
|
updateInfoticker(serviceID, text) {
|
|
49
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const
|
|
51
|
-
options
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const path = `/local/camoverlay/api/infoticker.cgi?service_id=${serviceID}&text=${text}`;
|
|
52
|
+
const options = this.getBaseVapixConnectionParams(path);
|
|
53
|
+
const res = yield (0, HttpRequest_1.sendRequest)(options);
|
|
54
|
+
if (!res.ok) {
|
|
55
|
+
throw new Error(JSON.stringify(res));
|
|
56
|
+
}
|
|
54
57
|
});
|
|
55
58
|
}
|
|
56
59
|
setEnabled(serviceID, enabled) {
|
|
57
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const
|
|
59
|
-
options
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
const path = `/local/camoverlay/api/enabled.cgi?id_${serviceID}=${enabled ? 1 : 0}`;
|
|
62
|
+
const options = this.getBaseVapixConnectionParams(path, 'POST');
|
|
63
|
+
const res = yield (0, HttpRequest_1.sendRequest)(options);
|
|
64
|
+
if (!res.ok) {
|
|
65
|
+
throw new Error(JSON.stringify(res));
|
|
66
|
+
}
|
|
62
67
|
});
|
|
63
68
|
}
|
|
64
69
|
isEnabled(serviceID) {
|
|
65
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const
|
|
67
|
-
options
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
const path = '/local/camoverlay/api/services.cgi?action=get';
|
|
72
|
+
const options = this.getBaseVapixConnectionParams(path);
|
|
73
|
+
const res = yield (0, HttpRequest_1.sendRequest)(options);
|
|
74
|
+
if (res.ok) {
|
|
75
|
+
const data = JSON.parse(yield res.text());
|
|
76
|
+
for (const service of data.services) {
|
|
77
|
+
if (service.id === serviceID) {
|
|
78
|
+
return service.enabled === 1;
|
|
79
|
+
}
|
|
74
80
|
}
|
|
81
|
+
throw new Error('Service not found.');
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new Error(JSON.stringify(res));
|
|
75
85
|
}
|
|
76
|
-
throw new Error('Service not found.');
|
|
77
86
|
});
|
|
78
87
|
}
|
|
79
88
|
updateServices(servicesJson) {
|
|
80
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const
|
|
82
|
-
options
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
const path = '/local/camoverlay/api/services.cgi?action=set';
|
|
91
|
+
const options = this.getBaseVapixConnectionParams(path, 'POST');
|
|
92
|
+
const res = yield (0, HttpRequest_1.sendRequest)(options, JSON.stringify(servicesJson));
|
|
93
|
+
if (!res.ok) {
|
|
94
|
+
throw new Error(JSON.stringify(res));
|
|
95
|
+
}
|
|
85
96
|
});
|
|
86
97
|
}
|
|
87
98
|
updateCGImageFromData(serviceID, imageType, imageData, coordinates = '', x = 0, y = 0) {
|
|
@@ -91,24 +102,29 @@ class CamOverlayAPI {
|
|
|
91
102
|
}
|
|
92
103
|
promiseCGUpdate(serviceID, action, params, contentType, data) {
|
|
93
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const
|
|
95
|
-
options
|
|
96
|
-
|
|
97
|
-
if (contentType && data) {
|
|
105
|
+
const path = `/local/camoverlay/api/customGraphics.cgi?action=${action}&service_id=${serviceID}${params}`;
|
|
106
|
+
const options = this.getBaseVapixConnectionParams(path, 'POST');
|
|
107
|
+
if (contentType !== undefined && data) {
|
|
98
108
|
options.headers = { 'Content-Type': contentType };
|
|
99
109
|
}
|
|
100
|
-
yield (0, HttpRequest_1.
|
|
110
|
+
const res = yield (0, HttpRequest_1.sendRequest)(options, data);
|
|
111
|
+
if (!res.ok) {
|
|
112
|
+
throw new Error(JSON.stringify(res));
|
|
113
|
+
}
|
|
101
114
|
});
|
|
102
115
|
}
|
|
103
116
|
formCoordinates(coordinates, x, y) {
|
|
104
117
|
return coordinates !== '' ? `&coord_system=${coordinates}&pos_x=${x}&pos_y=${y}` : '';
|
|
105
118
|
}
|
|
106
|
-
getBaseVapixConnectionParams() {
|
|
119
|
+
getBaseVapixConnectionParams(path, method = 'GET') {
|
|
107
120
|
return {
|
|
121
|
+
method: method,
|
|
108
122
|
protocol: this.tls ? 'https:' : 'http:',
|
|
109
123
|
host: this.ip,
|
|
110
124
|
port: this.port,
|
|
111
|
-
|
|
125
|
+
path: path,
|
|
126
|
+
user: this.user,
|
|
127
|
+
pass: this.pass,
|
|
112
128
|
rejectUnauthorized: !this.tlsInsecure,
|
|
113
129
|
};
|
|
114
130
|
}
|
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
import * as EventEmitter from 'events';
|
|
4
|
-
import { Options } from './common';
|
|
5
|
-
type CamOverlayDrawingOptions = Options & {
|
|
2
|
+
import { Options } from './internal/common';
|
|
3
|
+
export type CamOverlayDrawingOptions = Options & {
|
|
6
4
|
camera?: number | number[];
|
|
7
5
|
zIndex?: number;
|
|
8
6
|
};
|
|
9
|
-
export type
|
|
10
|
-
command: string;
|
|
11
|
-
params?: any[];
|
|
12
|
-
};
|
|
13
|
-
export type CairoResponse = {
|
|
7
|
+
export type TCairoResponse = {
|
|
14
8
|
message: string;
|
|
15
9
|
call_id: number;
|
|
16
10
|
};
|
|
17
|
-
export type
|
|
11
|
+
export type TCairoCreateResponse = {
|
|
18
12
|
var: string;
|
|
19
13
|
call_id: number;
|
|
20
14
|
};
|
|
21
|
-
export type
|
|
15
|
+
export type TUploadImageResponse = {
|
|
22
16
|
var: string;
|
|
23
17
|
width: number;
|
|
24
18
|
height: number;
|
|
25
19
|
call_id: number;
|
|
26
20
|
};
|
|
27
|
-
export type
|
|
21
|
+
export type TService = {
|
|
28
22
|
id: number;
|
|
29
23
|
enabled: number;
|
|
30
24
|
schedule: string;
|
|
@@ -32,33 +26,35 @@ export type Service = {
|
|
|
32
26
|
identifier: string;
|
|
33
27
|
cameraList: number[];
|
|
34
28
|
};
|
|
35
|
-
export type
|
|
36
|
-
services:
|
|
29
|
+
export type TServiceList = {
|
|
30
|
+
services: TService[];
|
|
37
31
|
};
|
|
38
|
-
export type
|
|
32
|
+
export type TAlign = 'A_RIGHT' | 'A_LEFT' | 'A_CENTER';
|
|
39
33
|
export type TextFit = 'TFM_SCALE' | 'TFM_TRUNCATE' | 'TFM_OVERFLOW';
|
|
40
|
-
export type
|
|
34
|
+
export type TWriteTextParams = [string, string, number, number, number, number, TAlign, TextFit?];
|
|
41
35
|
export declare class CamOverlayDrawingAPI extends EventEmitter {
|
|
42
36
|
private tls;
|
|
43
37
|
private tlsInsecure;
|
|
44
38
|
private ip;
|
|
45
39
|
private port;
|
|
46
|
-
private
|
|
40
|
+
private user;
|
|
41
|
+
private pass;
|
|
47
42
|
private cameraList;
|
|
48
43
|
private zIndex;
|
|
49
44
|
private callId;
|
|
50
45
|
private sendMessages;
|
|
46
|
+
private connected;
|
|
51
47
|
private ws?;
|
|
52
48
|
constructor(options?: CamOverlayDrawingOptions);
|
|
53
49
|
connect(): Promise<void>;
|
|
54
50
|
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<
|
|
51
|
+
cairo(command: string, ...params: unknown[]): Promise<TCairoResponse | TCairoCreateResponse>;
|
|
52
|
+
writeText(...params: TWriteTextParams): Promise<TCairoResponse>;
|
|
53
|
+
uploadImageData(imgBuffer: Buffer): Promise<TUploadImageResponse>;
|
|
54
|
+
uploadFontData(fontBuffer: Buffer): Promise<TCairoCreateResponse>;
|
|
55
|
+
showCairoImage(cairoImage: string, posX: number, posY: number): Promise<TCairoResponse>;
|
|
56
|
+
showCairoImageAbsolute(cairoImage: string, posX: number, posY: number, width: number, height: number): Promise<TCairoResponse>;
|
|
57
|
+
removeImage(): Promise<TCairoResponse>;
|
|
62
58
|
private openWebsocket;
|
|
63
59
|
private sendMessage;
|
|
64
60
|
private sendBinaryMessage;
|
|
@@ -66,4 +62,3 @@ export declare class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
66
62
|
private reportError;
|
|
67
63
|
private reportClose;
|
|
68
64
|
}
|
|
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,18 @@ 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
|
+
void this.openWebsocket();
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}));
|
|
132
145
|
this.ws.open();
|
|
133
146
|
});
|
|
134
147
|
}
|
|
@@ -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_1, rm_1, cairo_1, ppX_1, ppY_1) {
|
|
82
|
+
return __awaiter(this, arguments, void 0, function* (cod, rm, cairo, ppX, ppY, scale = 1) {
|
|
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;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CamOverlayDrawingAPI, CamOverlayDrawingOptions } from '../CamOverlayDrawingAPI';
|
|
2
|
+
import ResourceManager from './ResourceManager';
|
|
3
|
+
import { Frame, FrameOptions } from './Frame';
|
|
4
|
+
export declare const COORD: Record<string, [number, number]>;
|
|
5
|
+
export type PainterOptions = FrameOptions & {
|
|
6
|
+
screenWidth: number;
|
|
7
|
+
screenHeight: number;
|
|
8
|
+
coAlignment: string;
|
|
9
|
+
};
|
|
10
|
+
export default class Painter extends Frame {
|
|
11
|
+
private screenWidth;
|
|
12
|
+
private screenHeight;
|
|
13
|
+
private coAlignment;
|
|
14
|
+
private surface?;
|
|
15
|
+
private cairo?;
|
|
16
|
+
private cod;
|
|
17
|
+
private rm;
|
|
18
|
+
get camOverlayDrawingAPI(): CamOverlayDrawingAPI;
|
|
19
|
+
get resourceManager(): ResourceManager;
|
|
20
|
+
constructor(opt: PainterOptions, coopt: CamOverlayDrawingOptions);
|
|
21
|
+
connect(): Promise<void>;
|
|
22
|
+
disconnect(): void;
|
|
23
|
+
registerImage(moniker: string, fileName: string): void;
|
|
24
|
+
registerFont(moniker: string, fileName: string): void;
|
|
25
|
+
setScreenSize(sw: number, sh: number): void;
|
|
26
|
+
setCoAlignment(coa: string): void;
|
|
27
|
+
display(scale?: number): Promise<void>;
|
|
28
|
+
hide(): Promise<void>;
|
|
29
|
+
private positionConvertor;
|
|
30
|
+
private prepareDrawing;
|
|
31
|
+
private destroy;
|
|
32
|
+
}
|
|
33
|
+
export { Painter, Frame, FrameOptions, ResourceManager, CamOverlayDrawingOptions };
|