camstreamerlib 1.8.1 → 1.8.2
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 -5
- package/CamOverlayAPI.js +47 -11
- package/HTTPRequest.d.ts +2 -1
- package/package.json +1 -1
package/CamOverlayAPI.d.ts
CHANGED
|
@@ -49,6 +49,10 @@ export declare type Service = {
|
|
|
49
49
|
export declare type ServiceList = {
|
|
50
50
|
services: Service[];
|
|
51
51
|
};
|
|
52
|
+
export declare enum ImageType {
|
|
53
|
+
PNG = 0,
|
|
54
|
+
JPEG = 1
|
|
55
|
+
}
|
|
52
56
|
export declare class CamOverlayAPI extends EventEmitter {
|
|
53
57
|
private tls;
|
|
54
58
|
private tlsInsecure;
|
|
@@ -73,15 +77,17 @@ export declare class CamOverlayAPI extends EventEmitter {
|
|
|
73
77
|
showCairoImage(cairoImage: string, posX: number, posY: number): Promise<CairoResponse>;
|
|
74
78
|
showCairoImageAbsolute(cairoImage: string, posX: number, posY: number, width: number, height: number): Promise<CairoResponse>;
|
|
75
79
|
removeImage(): Promise<CairoResponse>;
|
|
76
|
-
sendMessage
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
private sendMessage;
|
|
81
|
+
private sendBinaryMessage;
|
|
82
|
+
private reportMsg;
|
|
83
|
+
private reportErr;
|
|
84
|
+
private reportClose;
|
|
80
85
|
updateCGText(fields: Field[]): Promise<void>;
|
|
81
86
|
private formCoordinates;
|
|
82
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>;
|
|
83
89
|
updateCGImagePos(coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
84
|
-
promiseCGUpdate(action: string, params: string): Promise<void>;
|
|
90
|
+
promiseCGUpdate(action: string, params: string, contentType?: string, data?: Buffer): Promise<void>;
|
|
85
91
|
updateInfoticker(text: string): Promise<void>;
|
|
86
92
|
setEnabled(enabled: boolean): Promise<void>;
|
|
87
93
|
isEnabled(): Promise<boolean>;
|
package/CamOverlayAPI.js
CHANGED
|
@@ -9,11 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.CamOverlayAPI = void 0;
|
|
12
|
+
exports.CamOverlayAPI = exports.ImageType = void 0;
|
|
13
13
|
const WebSocket = require("ws");
|
|
14
14
|
const EventEmitter = require("events");
|
|
15
15
|
const Digest_1 = require("./Digest");
|
|
16
16
|
const HTTPRequest_1 = require("./HTTPRequest");
|
|
17
|
+
var ImageType;
|
|
18
|
+
(function (ImageType) {
|
|
19
|
+
ImageType[ImageType["PNG"] = 0] = "PNG";
|
|
20
|
+
ImageType[ImageType["JPEG"] = 1] = "JPEG";
|
|
21
|
+
})(ImageType = exports.ImageType || (exports.ImageType = {}));
|
|
17
22
|
class CamOverlayAPI extends EventEmitter {
|
|
18
23
|
constructor(options) {
|
|
19
24
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -129,6 +134,7 @@ class CamOverlayAPI extends EventEmitter {
|
|
|
129
134
|
options.headers['Authorization'] = Digest_1.Digest.getAuthHeader(userPass[0], userPass[1], 'GET', '/local/camoverlay/ws', digestHeader);
|
|
130
135
|
}
|
|
131
136
|
this.ws = new WebSocket(addr, 'cairo-api', options);
|
|
137
|
+
this.ws.binaryType = 'arraybuffer';
|
|
132
138
|
this.ws.on('open', () => {
|
|
133
139
|
this.reportMsg('Websocket opened');
|
|
134
140
|
resolve();
|
|
@@ -171,16 +177,16 @@ class CamOverlayAPI extends EventEmitter {
|
|
|
171
177
|
return this.sendMessage({ command: 'write_text', params: params });
|
|
172
178
|
}
|
|
173
179
|
uploadImageData(imgBuffer) {
|
|
174
|
-
return this.
|
|
180
|
+
return this.sendBinaryMessage({
|
|
175
181
|
command: 'upload_image_data',
|
|
176
|
-
params: [
|
|
177
|
-
});
|
|
182
|
+
params: [],
|
|
183
|
+
}, imgBuffer);
|
|
178
184
|
}
|
|
179
185
|
uploadFontData(fontBuffer) {
|
|
180
|
-
return this.
|
|
186
|
+
return this.sendBinaryMessage({
|
|
181
187
|
command: 'upload_font_data',
|
|
182
188
|
params: [fontBuffer.toString('base64')],
|
|
183
|
-
});
|
|
189
|
+
}, fontBuffer);
|
|
184
190
|
}
|
|
185
191
|
showCairoImage(cairoImage, posX, posY) {
|
|
186
192
|
return this.sendMessage({
|
|
@@ -209,6 +215,24 @@ class CamOverlayAPI extends EventEmitter {
|
|
|
209
215
|
}
|
|
210
216
|
});
|
|
211
217
|
}
|
|
218
|
+
sendBinaryMessage(msgJson, data) {
|
|
219
|
+
return new Promise((resolve, reject) => {
|
|
220
|
+
try {
|
|
221
|
+
this.sendMessages[this.callId] = { resolve, reject };
|
|
222
|
+
msgJson['call_id'] = this.callId++;
|
|
223
|
+
const jsonBuffer = Buffer.from(JSON.stringify(msgJson));
|
|
224
|
+
const header = new ArrayBuffer(5);
|
|
225
|
+
const headerView = new DataView(header);
|
|
226
|
+
headerView.setInt8(0, 1);
|
|
227
|
+
headerView.setInt32(1, jsonBuffer.byteLength);
|
|
228
|
+
const msgBuffer = Buffer.concat([Buffer.from(header), jsonBuffer, data]);
|
|
229
|
+
this.ws.send(msgBuffer);
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
this.reportErr(new Error(`Send binary message error: ${err}`));
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
212
236
|
reportMsg(msg) {
|
|
213
237
|
this.emit('msg', msg);
|
|
214
238
|
}
|
|
@@ -219,6 +243,10 @@ class CamOverlayAPI extends EventEmitter {
|
|
|
219
243
|
this.emit('close');
|
|
220
244
|
}
|
|
221
245
|
reportClose() {
|
|
246
|
+
for (const callId in this.sendMessages) {
|
|
247
|
+
this.sendMessages[callId].reject(new Error('Connection lost'));
|
|
248
|
+
}
|
|
249
|
+
this.sendMessages = {};
|
|
222
250
|
this.emit('close');
|
|
223
251
|
}
|
|
224
252
|
updateCGText(fields) {
|
|
@@ -240,16 +268,24 @@ class CamOverlayAPI extends EventEmitter {
|
|
|
240
268
|
const update = `&image=${path}`;
|
|
241
269
|
return this.promiseCGUpdate('update_image', update + coord);
|
|
242
270
|
}
|
|
271
|
+
updateCGImageFromData(imageType, imageData, coordinates = '', x = 0, y = 0) {
|
|
272
|
+
const coord = this.formCoordinates(coordinates, x, y);
|
|
273
|
+
const contentType = imageType === ImageType.PNG ? 'image/png' : 'image/jpeg';
|
|
274
|
+
return this.promiseCGUpdate('update_image', coord, contentType, imageData);
|
|
275
|
+
}
|
|
243
276
|
updateCGImagePos(coordinates = '', x = 0, y = 0) {
|
|
244
277
|
const coord = this.formCoordinates(coordinates, x, y);
|
|
245
278
|
return this.promiseCGUpdate('update_image', coord);
|
|
246
279
|
}
|
|
247
|
-
promiseCGUpdate(action, params) {
|
|
280
|
+
promiseCGUpdate(action, params, contentType, data) {
|
|
248
281
|
return __awaiter(this, void 0, void 0, function* () {
|
|
249
282
|
const options = this.getBaseVapixConnectionParams();
|
|
250
283
|
options.method = 'POST';
|
|
251
284
|
options.path = encodeURI(`/local/camoverlay/api/customGraphics.cgi?action=${action}&service_id=${this.serviceID}${params}`);
|
|
252
|
-
|
|
285
|
+
if (contentType && data) {
|
|
286
|
+
options.headers = { 'Content-Type': contentType };
|
|
287
|
+
}
|
|
288
|
+
yield (0, HTTPRequest_1.httpRequest)(options, data);
|
|
253
289
|
});
|
|
254
290
|
}
|
|
255
291
|
updateInfoticker(text) {
|
|
@@ -257,7 +293,7 @@ class CamOverlayAPI extends EventEmitter {
|
|
|
257
293
|
const options = this.getBaseVapixConnectionParams();
|
|
258
294
|
options.method = 'GET';
|
|
259
295
|
options.path = `/local/camoverlay/api/infoticker.cgi?service_id=${this.serviceID}&text=${text}`;
|
|
260
|
-
yield (0, HTTPRequest_1.httpRequest)(options
|
|
296
|
+
yield (0, HTTPRequest_1.httpRequest)(options);
|
|
261
297
|
});
|
|
262
298
|
}
|
|
263
299
|
setEnabled(enabled) {
|
|
@@ -265,7 +301,7 @@ class CamOverlayAPI extends EventEmitter {
|
|
|
265
301
|
const options = this.getBaseVapixConnectionParams();
|
|
266
302
|
options.method = 'POST';
|
|
267
303
|
options.path = encodeURI(`/local/camoverlay/api/enabled.cgi?id_${this.serviceID}=${enabled ? 1 : 0}`);
|
|
268
|
-
yield (0, HTTPRequest_1.httpRequest)(options
|
|
304
|
+
yield (0, HTTPRequest_1.httpRequest)(options);
|
|
269
305
|
});
|
|
270
306
|
}
|
|
271
307
|
isEnabled() {
|
|
@@ -273,7 +309,7 @@ class CamOverlayAPI extends EventEmitter {
|
|
|
273
309
|
const options = this.getBaseVapixConnectionParams();
|
|
274
310
|
options.method = 'GET';
|
|
275
311
|
options.path = '/local/camoverlay/api/services.cgi?action=get';
|
|
276
|
-
const response = (yield (0, HTTPRequest_1.httpRequest)(options
|
|
312
|
+
const response = (yield (0, HTTPRequest_1.httpRequest)(options));
|
|
277
313
|
const data = JSON.parse(response);
|
|
278
314
|
for (let service of data.services) {
|
|
279
315
|
if (service.id === this.serviceID) {
|
package/HTTPRequest.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import * as http from 'http';
|
|
3
4
|
export declare type HttpRequestOptions = {
|
|
4
5
|
method?: string;
|
|
@@ -13,4 +14,4 @@ export declare type HttpRequestOptions = {
|
|
|
13
14
|
};
|
|
14
15
|
rejectUnauthorized?: boolean;
|
|
15
16
|
};
|
|
16
|
-
export declare function httpRequest(options: HttpRequestOptions, postData?: string, noWaitForData?: boolean): Promise<string | http.IncomingMessage>;
|
|
17
|
+
export declare function httpRequest(options: HttpRequestOptions, postData?: Buffer | string, noWaitForData?: boolean): Promise<string | http.IncomingMessage>;
|