camstreamerlib 1.9.1 → 2.0.1
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 +11 -65
- package/CamOverlayAPI.js +46 -281
- package/CamOverlayDrawingAPI.d.ts +68 -0
- package/CamOverlayDrawingAPI.js +176 -0
- package/CamScripterAPICameraEventsGenerator.d.ts +3 -8
- package/CamScripterAPICameraEventsGenerator.js +42 -65
- package/CamStreamerAPI.d.ts +2 -8
- package/CamStreamerAPI.js +2 -5
- package/CamSwitcherAPI.d.ts +3 -9
- package/CamSwitcherAPI.js +16 -22
- package/CameraVapix.d.ts +7 -16
- package/CameraVapix.js +73 -157
- package/CreatePackage.js +19 -1
- package/README.md +14 -1
- package/WsClient.d.ts +26 -0
- package/WsClient.js +104 -0
- package/common.d.ts +7 -0
- package/common.js +2 -0
- package/package.json +3 -3
- package/RtspClient.d.ts +0 -48
- package/RtspClient.js +0 -288
- /package/{HTTPRequest.d.ts → HttpRequest.d.ts} +0 -0
- /package/{HTTPRequest.js → HttpRequest.js} +0 -0
package/CamOverlayAPI.d.ts
CHANGED
|
@@ -1,43 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type CamOverlayOptions = {
|
|
5
|
-
protocol?: string;
|
|
6
|
-
tls?: boolean;
|
|
7
|
-
tlsInsecure?: boolean;
|
|
8
|
-
ip?: string;
|
|
9
|
-
port?: number;
|
|
10
|
-
auth?: string;
|
|
11
|
-
serviceName?: string;
|
|
12
|
-
serviceID?: number;
|
|
13
|
-
camera?: number | number[];
|
|
14
|
-
};
|
|
2
|
+
import { Options } from './common';
|
|
3
|
+
export type CamOverlayOptions = Options;
|
|
15
4
|
export type Field = {
|
|
16
5
|
field_name: string;
|
|
17
6
|
text: string;
|
|
18
7
|
color?: string;
|
|
19
8
|
};
|
|
20
|
-
export type Message = {
|
|
21
|
-
command: string;
|
|
22
|
-
params: any[];
|
|
23
|
-
};
|
|
24
|
-
export type CairoResponse = {
|
|
25
|
-
message: string;
|
|
26
|
-
call_id: number;
|
|
27
|
-
};
|
|
28
|
-
export type CairoCreateResponse = {
|
|
29
|
-
var: string;
|
|
30
|
-
call_id: number;
|
|
31
|
-
};
|
|
32
|
-
export type UploadImageResponse = {
|
|
33
|
-
var: string;
|
|
34
|
-
width: number;
|
|
35
|
-
height: number;
|
|
36
|
-
call_id: number;
|
|
37
|
-
};
|
|
38
|
-
export type Align = 'A_RIGHT' | 'A_LEFT' | 'A_CENTER';
|
|
39
|
-
export type TextFit = 'TFM_SCALE' | 'TFM_TRUNCATE' | 'TFM_OVERFLOW';
|
|
40
|
-
export type WriteTextParams = [string, string, number, number, number, number, Align, TextFit?];
|
|
41
9
|
export type Service = {
|
|
42
10
|
id: number;
|
|
43
11
|
enabled: number;
|
|
@@ -53,44 +21,22 @@ export declare enum ImageType {
|
|
|
53
21
|
PNG = 0,
|
|
54
22
|
JPEG = 1
|
|
55
23
|
}
|
|
56
|
-
export declare class CamOverlayAPI
|
|
24
|
+
export declare class CamOverlayAPI {
|
|
57
25
|
private tls;
|
|
58
26
|
private tlsInsecure;
|
|
59
27
|
private ip;
|
|
60
28
|
private port;
|
|
61
29
|
private auth;
|
|
62
|
-
private serviceName;
|
|
63
|
-
private serviceID;
|
|
64
|
-
private cameraList;
|
|
65
|
-
private callId;
|
|
66
|
-
private sendMessages;
|
|
67
|
-
private ws;
|
|
68
30
|
constructor(options?: CamOverlayOptions);
|
|
69
|
-
|
|
70
|
-
|
|
31
|
+
updateCGText(serviceID: number, fields: Field[]): Promise<void>;
|
|
32
|
+
updateCGImagePos(serviceID: number, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
33
|
+
updateCGImage(serviceID: number, path: string, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
34
|
+
updateInfoticker(serviceID: number, text: string): Promise<void>;
|
|
35
|
+
setEnabled(serviceID: number, enabled: boolean): Promise<void>;
|
|
36
|
+
isEnabled(serviceID: number): Promise<boolean>;
|
|
71
37
|
updateServices(servicesJson: ServiceList): Promise<void>;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
writeText(...params: WriteTextParams): Promise<CairoResponse>;
|
|
75
|
-
uploadImageData(imgBuffer: Buffer): Promise<UploadImageResponse>;
|
|
76
|
-
uploadFontData(fontBuffer: Buffer): Promise<CairoCreateResponse>;
|
|
77
|
-
showCairoImage(cairoImage: string, posX: number, posY: number): Promise<CairoResponse>;
|
|
78
|
-
showCairoImageAbsolute(cairoImage: string, posX: number, posY: number, width: number, height: number): Promise<CairoResponse>;
|
|
79
|
-
removeImage(): Promise<CairoResponse>;
|
|
80
|
-
private sendMessage;
|
|
81
|
-
private sendBinaryMessage;
|
|
82
|
-
private reportMsg;
|
|
83
|
-
private reportErr;
|
|
84
|
-
private reportClose;
|
|
85
|
-
updateCGText(fields: Field[]): Promise<void>;
|
|
38
|
+
updateCGImageFromData(serviceID: number, imageType: ImageType, imageData: Buffer, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
39
|
+
promiseCGUpdate(serviceID: number, action: string, params: string, contentType?: string, data?: Buffer): Promise<void>;
|
|
86
40
|
private formCoordinates;
|
|
87
|
-
updateCGImage(path: string, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
88
|
-
updateCGImageFromData(imageType: ImageType, imageData: Buffer, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
89
|
-
updateCGImagePos(coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
90
|
-
promiseCGUpdate(action: string, params: string, contentType?: string, data?: Buffer): Promise<void>;
|
|
91
|
-
updateInfoticker(text: string): Promise<void>;
|
|
92
|
-
setEnabled(enabled: boolean): Promise<void>;
|
|
93
|
-
isEnabled(): Promise<boolean>;
|
|
94
41
|
private getBaseVapixConnectionParams;
|
|
95
|
-
private compareCameraList;
|
|
96
42
|
}
|
package/CamOverlayAPI.js
CHANGED
|
@@ -10,261 +10,22 @@ 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
|
|
14
|
-
const EventEmitter = require("events");
|
|
15
|
-
const Digest_1 = require("./Digest");
|
|
16
|
-
const HTTPRequest_1 = require("./HTTPRequest");
|
|
13
|
+
const HttpRequest_1 = require("./HttpRequest");
|
|
17
14
|
var ImageType;
|
|
18
15
|
(function (ImageType) {
|
|
19
16
|
ImageType[ImageType["PNG"] = 0] = "PNG";
|
|
20
17
|
ImageType[ImageType["JPEG"] = 1] = "JPEG";
|
|
21
18
|
})(ImageType = exports.ImageType || (exports.ImageType = {}));
|
|
22
|
-
class CamOverlayAPI
|
|
19
|
+
class CamOverlayAPI {
|
|
23
20
|
constructor(options) {
|
|
24
|
-
var _a, _b, _c, _d, _e
|
|
25
|
-
super();
|
|
26
|
-
this.ws = null;
|
|
21
|
+
var _a, _b, _c, _d, _e;
|
|
27
22
|
this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
|
|
28
|
-
if ((options === null || options === void 0 ? void 0 : options.tls) === undefined && (options === null || options === void 0 ? void 0 : options.protocol) !== undefined) {
|
|
29
|
-
this.tls = options.protocol === 'wss';
|
|
30
|
-
}
|
|
31
23
|
this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
|
|
32
24
|
this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
|
|
33
25
|
this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
|
|
34
26
|
this.auth = (_e = options === null || options === void 0 ? void 0 : options.auth) !== null && _e !== void 0 ? _e : '';
|
|
35
|
-
this.serviceName = (_f = options === null || options === void 0 ? void 0 : options.serviceName) !== null && _f !== void 0 ? _f : '';
|
|
36
|
-
this.serviceID = (_g = options === null || options === void 0 ? void 0 : options.serviceID) !== null && _g !== void 0 ? _g : -1;
|
|
37
|
-
this.cameraList = [0];
|
|
38
|
-
if (Array.isArray(options === null || options === void 0 ? void 0 : options.camera)) {
|
|
39
|
-
this.cameraList = options.camera;
|
|
40
|
-
}
|
|
41
|
-
else if (typeof (options === null || options === void 0 ? void 0 : options.camera) === 'number') {
|
|
42
|
-
this.cameraList = [options.camera];
|
|
43
|
-
}
|
|
44
|
-
this.callId = 0;
|
|
45
|
-
this.sendMessages = {};
|
|
46
|
-
EventEmitter.call(this);
|
|
47
|
-
}
|
|
48
|
-
connect() {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
try {
|
|
51
|
-
if (this.serviceID === -1) {
|
|
52
|
-
this.serviceID = yield this.createService();
|
|
53
|
-
}
|
|
54
|
-
yield this.openWebsocket();
|
|
55
|
-
this.emit('open');
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
this.reportErr(err);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
createService() {
|
|
63
|
-
var _a;
|
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const options = this.getBaseVapixConnectionParams();
|
|
66
|
-
options.method = 'GET';
|
|
67
|
-
options.path = '/local/camoverlay/api/services.cgi?action=get';
|
|
68
|
-
const response = (yield (0, HTTPRequest_1.httpRequest)(options));
|
|
69
|
-
let servicesJson;
|
|
70
|
-
try {
|
|
71
|
-
servicesJson = JSON.parse(response);
|
|
72
|
-
(_a = servicesJson.services) !== null && _a !== void 0 ? _a : (servicesJson.services = []);
|
|
73
|
-
}
|
|
74
|
-
catch (_b) {
|
|
75
|
-
servicesJson = { services: [] };
|
|
76
|
-
}
|
|
77
|
-
let service = null;
|
|
78
|
-
let maxID = -1;
|
|
79
|
-
let servicesArr = servicesJson.services;
|
|
80
|
-
for (let s of servicesArr) {
|
|
81
|
-
if (s.id > maxID) {
|
|
82
|
-
maxID = s.id;
|
|
83
|
-
}
|
|
84
|
-
if (s.identifier === this.serviceName && s.name === 'scripter') {
|
|
85
|
-
service = s;
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (service !== null) {
|
|
90
|
-
if (service.cameraList === undefined || !this.compareCameraList(service.cameraList)) {
|
|
91
|
-
service.cameraList = this.cameraList;
|
|
92
|
-
yield this.updateServices(servicesJson);
|
|
93
|
-
return service.id;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
return service.id;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
let newServiceID = maxID + 1;
|
|
101
|
-
service = {
|
|
102
|
-
id: newServiceID,
|
|
103
|
-
enabled: 1,
|
|
104
|
-
schedule: '',
|
|
105
|
-
name: 'scripter',
|
|
106
|
-
identifier: this.serviceName,
|
|
107
|
-
cameraList: this.cameraList,
|
|
108
|
-
};
|
|
109
|
-
servicesJson.services.push(service);
|
|
110
|
-
yield this.updateServices(servicesJson);
|
|
111
|
-
return newServiceID;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
updateServices(servicesJson) {
|
|
116
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
const options = this.getBaseVapixConnectionParams();
|
|
118
|
-
options.method = 'POST';
|
|
119
|
-
options.path = '/local/camoverlay/api/services.cgi?action=set';
|
|
120
|
-
yield (0, HTTPRequest_1.httpRequest)(options, JSON.stringify(servicesJson));
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
openWebsocket(digestHeader) {
|
|
124
|
-
let promise = new Promise((resolve, reject) => {
|
|
125
|
-
const userPass = this.auth.split(':');
|
|
126
|
-
const protocol = this.tls ? 'wss' : 'ws';
|
|
127
|
-
const addr = `${protocol}://${this.ip}:${this.port}/local/camoverlay/ws`;
|
|
128
|
-
const options = {
|
|
129
|
-
auth: this.auth,
|
|
130
|
-
rejectUnauthorized: !this.tlsInsecure,
|
|
131
|
-
headers: {},
|
|
132
|
-
};
|
|
133
|
-
if (digestHeader !== undefined) {
|
|
134
|
-
options.headers['Authorization'] = Digest_1.Digest.getAuthHeader(userPass[0], userPass[1], 'GET', '/local/camoverlay/ws', digestHeader);
|
|
135
|
-
}
|
|
136
|
-
this.ws = new WebSocket(addr, 'cairo-api', options);
|
|
137
|
-
this.ws.binaryType = 'arraybuffer';
|
|
138
|
-
this.ws.isAlive = true;
|
|
139
|
-
const pingTimer = setInterval(() => {
|
|
140
|
-
if (this.ws.readyState !== this.ws.OPEN || this.ws.isAlive === false) {
|
|
141
|
-
return this.ws.terminate();
|
|
142
|
-
}
|
|
143
|
-
this.ws.isAlive = false;
|
|
144
|
-
this.ws.ping();
|
|
145
|
-
}, 30000);
|
|
146
|
-
this.ws.on('open', () => {
|
|
147
|
-
this.reportMsg('Websocket opened');
|
|
148
|
-
resolve();
|
|
149
|
-
});
|
|
150
|
-
this.ws.on('pong', () => {
|
|
151
|
-
this.ws.isAlive = true;
|
|
152
|
-
});
|
|
153
|
-
this.ws.on('message', (data) => {
|
|
154
|
-
let dataJSON = JSON.parse(data);
|
|
155
|
-
if (dataJSON.hasOwnProperty('call_id') && dataJSON['call_id'] in this.sendMessages) {
|
|
156
|
-
if (dataJSON.hasOwnProperty('error')) {
|
|
157
|
-
this.sendMessages[dataJSON['call_id']].reject(new Error(dataJSON.error));
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
this.sendMessages[dataJSON['call_id']].resolve(dataJSON);
|
|
161
|
-
}
|
|
162
|
-
delete this.sendMessages[dataJSON['call_id']];
|
|
163
|
-
}
|
|
164
|
-
if (dataJSON.hasOwnProperty('error')) {
|
|
165
|
-
this.reportErr(new Error(dataJSON.error));
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
this.reportMsg(data);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
this.ws.on('unexpected-response', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
172
|
-
if (res.statusCode === 401 && res.headers['www-authenticate'] !== undefined)
|
|
173
|
-
this.openWebsocket(res.headers['www-authenticate']).then(resolve, reject);
|
|
174
|
-
else {
|
|
175
|
-
reject('Error: status code: ' + res.statusCode + ', ' + res.data);
|
|
176
|
-
}
|
|
177
|
-
}));
|
|
178
|
-
this.ws.on('error', (error) => {
|
|
179
|
-
this.reportErr(error);
|
|
180
|
-
reject(error);
|
|
181
|
-
});
|
|
182
|
-
this.ws.on('close', () => {
|
|
183
|
-
clearInterval(pingTimer);
|
|
184
|
-
this.reportClose();
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
return promise;
|
|
188
|
-
}
|
|
189
|
-
cairo(command, ...params) {
|
|
190
|
-
return this.sendMessage({ command: command, params: params });
|
|
191
|
-
}
|
|
192
|
-
writeText(...params) {
|
|
193
|
-
return this.sendMessage({ command: 'write_text', params: params });
|
|
194
|
-
}
|
|
195
|
-
uploadImageData(imgBuffer) {
|
|
196
|
-
return this.sendBinaryMessage({
|
|
197
|
-
command: 'upload_image_data',
|
|
198
|
-
params: [],
|
|
199
|
-
}, imgBuffer);
|
|
200
|
-
}
|
|
201
|
-
uploadFontData(fontBuffer) {
|
|
202
|
-
return this.sendBinaryMessage({
|
|
203
|
-
command: 'upload_font_data',
|
|
204
|
-
params: [fontBuffer.toString('base64')],
|
|
205
|
-
}, fontBuffer);
|
|
206
|
-
}
|
|
207
|
-
showCairoImage(cairoImage, posX, posY) {
|
|
208
|
-
return this.sendMessage({
|
|
209
|
-
command: 'show_cairo_image',
|
|
210
|
-
params: [this.serviceID, cairoImage, posX, posY],
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
showCairoImageAbsolute(cairoImage, posX, posY, width, height) {
|
|
214
|
-
return this.sendMessage({
|
|
215
|
-
command: 'show_cairo_image',
|
|
216
|
-
params: [this.serviceID, cairoImage, -1.0 + (2.0 / width) * posX, -1.0 + (2.0 / height) * posY],
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
removeImage() {
|
|
220
|
-
return this.sendMessage({ command: 'remove_image', params: [this.serviceID] });
|
|
221
|
-
}
|
|
222
|
-
sendMessage(msgJson) {
|
|
223
|
-
return new Promise((resolve, reject) => {
|
|
224
|
-
try {
|
|
225
|
-
this.sendMessages[this.callId] = { resolve, reject };
|
|
226
|
-
msgJson['call_id'] = this.callId++;
|
|
227
|
-
this.ws.send(JSON.stringify(msgJson));
|
|
228
|
-
}
|
|
229
|
-
catch (err) {
|
|
230
|
-
this.reportErr(new Error(`Send message error: ${err}`));
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
sendBinaryMessage(msgJson, data) {
|
|
235
|
-
return new Promise((resolve, reject) => {
|
|
236
|
-
try {
|
|
237
|
-
this.sendMessages[this.callId] = { resolve, reject };
|
|
238
|
-
msgJson['call_id'] = this.callId++;
|
|
239
|
-
const jsonBuffer = Buffer.from(JSON.stringify(msgJson));
|
|
240
|
-
const header = new ArrayBuffer(5);
|
|
241
|
-
const headerView = new DataView(header);
|
|
242
|
-
headerView.setInt8(0, 1);
|
|
243
|
-
headerView.setInt32(1, jsonBuffer.byteLength);
|
|
244
|
-
const msgBuffer = Buffer.concat([Buffer.from(header), jsonBuffer, data]);
|
|
245
|
-
this.ws.send(msgBuffer);
|
|
246
|
-
}
|
|
247
|
-
catch (err) {
|
|
248
|
-
this.reportErr(new Error(`Send binary message error: ${err}`));
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
27
|
}
|
|
252
|
-
|
|
253
|
-
this.emit('msg', msg);
|
|
254
|
-
}
|
|
255
|
-
reportErr(err) {
|
|
256
|
-
var _a;
|
|
257
|
-
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.terminate();
|
|
258
|
-
this.emit('error', err);
|
|
259
|
-
}
|
|
260
|
-
reportClose() {
|
|
261
|
-
for (const callId in this.sendMessages) {
|
|
262
|
-
this.sendMessages[callId].reject(new Error('Connection lost'));
|
|
263
|
-
}
|
|
264
|
-
this.sendMessages = {};
|
|
265
|
-
this.emit('close');
|
|
266
|
-
}
|
|
267
|
-
updateCGText(fields) {
|
|
28
|
+
updateCGText(serviceID, fields) {
|
|
268
29
|
let field_specs = '';
|
|
269
30
|
for (let field of fields) {
|
|
270
31
|
const name = field.field_name;
|
|
@@ -273,67 +34,75 @@ class CamOverlayAPI extends EventEmitter {
|
|
|
273
34
|
field_specs += `&${name}_color=${field.color}`;
|
|
274
35
|
}
|
|
275
36
|
}
|
|
276
|
-
return this.promiseCGUpdate('update_text', field_specs);
|
|
37
|
+
return this.promiseCGUpdate(serviceID, 'update_text', field_specs);
|
|
277
38
|
}
|
|
278
|
-
|
|
279
|
-
return coordinates !== '' ? `&coord_system=${coordinates}&pos_x=${x}&pos_y=${y}` : '';
|
|
280
|
-
}
|
|
281
|
-
updateCGImage(path, coordinates = '', x = 0, y = 0) {
|
|
282
|
-
const coord = this.formCoordinates(coordinates, x, y);
|
|
283
|
-
const update = `&image=${path}`;
|
|
284
|
-
return this.promiseCGUpdate('update_image', update + coord);
|
|
285
|
-
}
|
|
286
|
-
updateCGImageFromData(imageType, imageData, coordinates = '', x = 0, y = 0) {
|
|
39
|
+
updateCGImagePos(serviceID, coordinates = '', x = 0, y = 0) {
|
|
287
40
|
const coord = this.formCoordinates(coordinates, x, y);
|
|
288
|
-
|
|
289
|
-
return this.promiseCGUpdate('update_image', coord, contentType, imageData);
|
|
41
|
+
return this.promiseCGUpdate(serviceID, 'update_image', coord);
|
|
290
42
|
}
|
|
291
|
-
|
|
43
|
+
updateCGImage(serviceID, path, coordinates = '', x = 0, y = 0) {
|
|
292
44
|
const coord = this.formCoordinates(coordinates, x, y);
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
promiseCGUpdate(action, params, contentType, data) {
|
|
296
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
297
|
-
const options = this.getBaseVapixConnectionParams();
|
|
298
|
-
options.method = 'POST';
|
|
299
|
-
options.path = encodeURI(`/local/camoverlay/api/customGraphics.cgi?action=${action}&service_id=${this.serviceID}${params}`);
|
|
300
|
-
if (contentType && data) {
|
|
301
|
-
options.headers = { 'Content-Type': contentType };
|
|
302
|
-
}
|
|
303
|
-
yield (0, HTTPRequest_1.httpRequest)(options, data);
|
|
304
|
-
});
|
|
45
|
+
const update = `&image=${path}`;
|
|
46
|
+
return this.promiseCGUpdate(serviceID, 'update_image', update + coord);
|
|
305
47
|
}
|
|
306
|
-
updateInfoticker(text) {
|
|
48
|
+
updateInfoticker(serviceID, text) {
|
|
307
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
308
50
|
const options = this.getBaseVapixConnectionParams();
|
|
309
51
|
options.method = 'GET';
|
|
310
|
-
options.path = `/local/camoverlay/api/infoticker.cgi?service_id=${
|
|
311
|
-
yield (0,
|
|
52
|
+
options.path = `/local/camoverlay/api/infoticker.cgi?service_id=${serviceID}&text=${text}`;
|
|
53
|
+
yield (0, HttpRequest_1.httpRequest)(options);
|
|
312
54
|
});
|
|
313
55
|
}
|
|
314
|
-
setEnabled(enabled) {
|
|
56
|
+
setEnabled(serviceID, enabled) {
|
|
315
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
316
58
|
const options = this.getBaseVapixConnectionParams();
|
|
317
59
|
options.method = 'POST';
|
|
318
|
-
options.path = encodeURI(`/local/camoverlay/api/enabled.cgi?id_${
|
|
319
|
-
yield (0,
|
|
60
|
+
options.path = encodeURI(`/local/camoverlay/api/enabled.cgi?id_${serviceID}=${enabled ? 1 : 0}`);
|
|
61
|
+
yield (0, HttpRequest_1.httpRequest)(options);
|
|
320
62
|
});
|
|
321
63
|
}
|
|
322
|
-
isEnabled() {
|
|
64
|
+
isEnabled(serviceID) {
|
|
323
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
324
66
|
const options = this.getBaseVapixConnectionParams();
|
|
325
67
|
options.method = 'GET';
|
|
326
68
|
options.path = '/local/camoverlay/api/services.cgi?action=get';
|
|
327
|
-
const response = (yield (0,
|
|
69
|
+
const response = (yield (0, HttpRequest_1.httpRequest)(options));
|
|
328
70
|
const data = JSON.parse(response);
|
|
329
71
|
for (let service of data.services) {
|
|
330
|
-
if (service.id ===
|
|
72
|
+
if (service.id === serviceID) {
|
|
331
73
|
return service.enabled === 1;
|
|
332
74
|
}
|
|
333
75
|
}
|
|
334
76
|
throw new Error('Service not found.');
|
|
335
77
|
});
|
|
336
78
|
}
|
|
79
|
+
updateServices(servicesJson) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const options = this.getBaseVapixConnectionParams();
|
|
82
|
+
options.method = 'POST';
|
|
83
|
+
options.path = '/local/camoverlay/api/services.cgi?action=set';
|
|
84
|
+
yield (0, HttpRequest_1.httpRequest)(options, JSON.stringify(servicesJson));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
updateCGImageFromData(serviceID, imageType, imageData, coordinates = '', x = 0, y = 0) {
|
|
88
|
+
const coord = this.formCoordinates(coordinates, x, y);
|
|
89
|
+
const contentType = imageType === ImageType.PNG ? 'image/png' : 'image/jpeg';
|
|
90
|
+
return this.promiseCGUpdate(serviceID, 'update_image', coord, contentType, imageData);
|
|
91
|
+
}
|
|
92
|
+
promiseCGUpdate(serviceID, action, params, contentType, data) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const options = this.getBaseVapixConnectionParams();
|
|
95
|
+
options.method = 'POST';
|
|
96
|
+
options.path = encodeURI(`/local/camoverlay/api/customGraphics.cgi?action=${action}&service_id=${serviceID}${params}`);
|
|
97
|
+
if (contentType && data) {
|
|
98
|
+
options.headers = { 'Content-Type': contentType };
|
|
99
|
+
}
|
|
100
|
+
yield (0, HttpRequest_1.httpRequest)(options, data);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
formCoordinates(coordinates, x, y) {
|
|
104
|
+
return coordinates !== '' ? `&coord_system=${coordinates}&pos_x=${x}&pos_y=${y}` : '';
|
|
105
|
+
}
|
|
337
106
|
getBaseVapixConnectionParams() {
|
|
338
107
|
return {
|
|
339
108
|
protocol: this.tls ? 'https:' : 'http:',
|
|
@@ -343,9 +112,5 @@ class CamOverlayAPI extends EventEmitter {
|
|
|
343
112
|
rejectUnauthorized: !this.tlsInsecure,
|
|
344
113
|
};
|
|
345
114
|
}
|
|
346
|
-
compareCameraList(cameraList) {
|
|
347
|
-
return (this.cameraList.length === cameraList.length &&
|
|
348
|
-
this.cameraList.every((element, index) => element === cameraList[index]));
|
|
349
|
-
}
|
|
350
115
|
}
|
|
351
116
|
exports.CamOverlayAPI = CamOverlayAPI;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import * as EventEmitter from 'events';
|
|
4
|
+
import { Options } from './common';
|
|
5
|
+
type CamOverlayDrawingOptions = Options & {
|
|
6
|
+
camera?: number | number[];
|
|
7
|
+
zIndex?: number;
|
|
8
|
+
};
|
|
9
|
+
export type Message = {
|
|
10
|
+
command: string;
|
|
11
|
+
params?: any[];
|
|
12
|
+
};
|
|
13
|
+
export type CairoResponse = {
|
|
14
|
+
message: string;
|
|
15
|
+
call_id: number;
|
|
16
|
+
};
|
|
17
|
+
export type CairoCreateResponse = {
|
|
18
|
+
var: string;
|
|
19
|
+
call_id: number;
|
|
20
|
+
};
|
|
21
|
+
export type UploadImageResponse = {
|
|
22
|
+
var: string;
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
call_id: number;
|
|
26
|
+
};
|
|
27
|
+
export type Service = {
|
|
28
|
+
id: number;
|
|
29
|
+
enabled: number;
|
|
30
|
+
schedule: string;
|
|
31
|
+
name: string;
|
|
32
|
+
identifier: string;
|
|
33
|
+
cameraList: number[];
|
|
34
|
+
};
|
|
35
|
+
export type ServiceList = {
|
|
36
|
+
services: Service[];
|
|
37
|
+
};
|
|
38
|
+
export type Align = 'A_RIGHT' | 'A_LEFT' | 'A_CENTER';
|
|
39
|
+
export type TextFit = 'TFM_SCALE' | 'TFM_TRUNCATE' | 'TFM_OVERFLOW';
|
|
40
|
+
export type WriteTextParams = [string, string, number, number, number, number, Align, TextFit?];
|
|
41
|
+
export declare class CamOverlayDrawingAPI extends EventEmitter {
|
|
42
|
+
private tls;
|
|
43
|
+
private tlsInsecure;
|
|
44
|
+
private ip;
|
|
45
|
+
private port;
|
|
46
|
+
private auth;
|
|
47
|
+
private cameraList;
|
|
48
|
+
private zIndex;
|
|
49
|
+
private callId;
|
|
50
|
+
private sendMessages;
|
|
51
|
+
private ws;
|
|
52
|
+
constructor(options?: CamOverlayDrawingOptions);
|
|
53
|
+
connect(): Promise<void>;
|
|
54
|
+
cairo(command: string, ...params: any[]): Promise<CairoResponse | CairoCreateResponse>;
|
|
55
|
+
writeText(...params: WriteTextParams): Promise<CairoResponse>;
|
|
56
|
+
uploadImageData(imgBuffer: Buffer): Promise<UploadImageResponse>;
|
|
57
|
+
uploadFontData(fontBuffer: Buffer): Promise<CairoCreateResponse>;
|
|
58
|
+
showCairoImage(cairoImage: string, posX: number, posY: number): Promise<CairoResponse>;
|
|
59
|
+
showCairoImageAbsolute(cairoImage: string, posX: number, posY: number, width: number, height: number): Promise<CairoResponse>;
|
|
60
|
+
removeImage(): Promise<CairoResponse>;
|
|
61
|
+
private openWebsocket;
|
|
62
|
+
private sendMessage;
|
|
63
|
+
private sendBinaryMessage;
|
|
64
|
+
private reportMessage;
|
|
65
|
+
private reportError;
|
|
66
|
+
private reportClose;
|
|
67
|
+
}
|
|
68
|
+
export {};
|