camstreamerlib 1.6.1 → 1.6.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 +65 -0
- package/CamOverlayAPI.js +301 -0
- package/CamStreamerAPI.d.ts +19 -0
- package/CamStreamerAPI.js +62 -0
- package/CamSwitcherAPI.d.ts +26 -0
- package/CamSwitcherAPI.js +119 -0
- package/CameraVapix.d.ts +75 -0
- package/CameraVapix.js +328 -0
- package/Digest.d.ts +3 -0
- package/{src/Digest.ts → Digest.js} +11 -13
- package/HTTPRequest.d.ts +15 -0
- package/HTTPRequest.js +84 -0
- package/HttpServer.d.ts +18 -0
- package/{src/HttpServer.ts → HttpServer.js} +18 -42
- package/RtspClient.d.ts +48 -0
- package/{src/RtspClient.ts → RtspClient.js} +65 -120
- package/package.json +4 -4
- package/.github/workflows/github-ci.yml +0 -46
- package/jest.config.js +0 -11
- package/src/CamOverlayAPI.ts +0 -370
- package/src/CamStreamerAPI.ts +0 -58
- package/src/CamSwitcherAPI.ts +0 -130
- package/src/CameraVapix.ts +0 -398
- package/src/HTTPRequest.ts +0 -97
- package/test/Digest.test.ts +0 -13
- package/tsconfig.json +0 -11
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import * as EventEmitter from 'events';
|
|
4
|
+
export declare type CamOverlayOptions = {
|
|
5
|
+
protocol: string;
|
|
6
|
+
ip: string;
|
|
7
|
+
port: number;
|
|
8
|
+
auth: string;
|
|
9
|
+
serviceName: string;
|
|
10
|
+
serviceID: number;
|
|
11
|
+
camera: number;
|
|
12
|
+
};
|
|
13
|
+
export declare type Field = {
|
|
14
|
+
field_name: string;
|
|
15
|
+
text: string;
|
|
16
|
+
color?: string;
|
|
17
|
+
};
|
|
18
|
+
declare type Service = {
|
|
19
|
+
id: number;
|
|
20
|
+
enabled: number;
|
|
21
|
+
schedule: string;
|
|
22
|
+
name: string;
|
|
23
|
+
identifier: string;
|
|
24
|
+
camera: number;
|
|
25
|
+
};
|
|
26
|
+
declare type ServiceJson = {
|
|
27
|
+
services: Service[];
|
|
28
|
+
};
|
|
29
|
+
export declare class CamOverlayAPI extends EventEmitter {
|
|
30
|
+
private protocol;
|
|
31
|
+
private ip;
|
|
32
|
+
private port;
|
|
33
|
+
private auth;
|
|
34
|
+
private serviceName;
|
|
35
|
+
private serviceID;
|
|
36
|
+
private camera;
|
|
37
|
+
private callId;
|
|
38
|
+
private sendMessages;
|
|
39
|
+
private ws;
|
|
40
|
+
constructor(options?: CamOverlayOptions);
|
|
41
|
+
connect(): Promise<void>;
|
|
42
|
+
createService(): Promise<number>;
|
|
43
|
+
updateServices(servicesJson: ServiceJson): Promise<void>;
|
|
44
|
+
openWebsocket(digestHeader?: string): Promise<void>;
|
|
45
|
+
cairo(command: string, ...params: any[]): Promise<unknown>;
|
|
46
|
+
writeText(...params: any[]): Promise<unknown>;
|
|
47
|
+
uploadImageData(imgBuffer: Buffer): Promise<unknown>;
|
|
48
|
+
uploadFontData(fontBuffer: Buffer): Promise<unknown>;
|
|
49
|
+
showCairoImage(cairoImage: any, posX: number, posY: number): Promise<unknown>;
|
|
50
|
+
removeImage(): Promise<unknown>;
|
|
51
|
+
showCairoImageAbsolute(cairoImage: any, posX: number, posY: number, width: number, height: number): Promise<unknown>;
|
|
52
|
+
sendMessage(msgJson: any): Promise<unknown>;
|
|
53
|
+
reportMsg(msg: string): void;
|
|
54
|
+
reportErr(err: Error): void;
|
|
55
|
+
reportClose(): void;
|
|
56
|
+
updateCGText(fields: Field[]): Promise<void>;
|
|
57
|
+
private formCoordinates;
|
|
58
|
+
updateCGImage(path: string, coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
59
|
+
updateCGImagePos(coordinates?: string, x?: number, y?: number): Promise<void>;
|
|
60
|
+
promiseCGUpdate(action: string, params: string): Promise<void>;
|
|
61
|
+
updateInfoticker(text: string): Promise<void>;
|
|
62
|
+
setEnabled(enabled: boolean): Promise<void>;
|
|
63
|
+
isEnabled(): Promise<boolean>;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
package/CamOverlayAPI.js
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
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.CamOverlayAPI = void 0;
|
|
13
|
+
const WebSocket = require("ws");
|
|
14
|
+
const EventEmitter = require("events");
|
|
15
|
+
const Digest_1 = require("./Digest");
|
|
16
|
+
const HTTPRequest_1 = require("./HTTPRequest");
|
|
17
|
+
class CamOverlayAPI extends EventEmitter {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
20
|
+
super();
|
|
21
|
+
this.ws = null;
|
|
22
|
+
this.protocol = (_a = options === null || options === void 0 ? void 0 : options.protocol) !== null && _a !== void 0 ? _a : 'ws';
|
|
23
|
+
this.ip = (_b = options === null || options === void 0 ? void 0 : options.ip) !== null && _b !== void 0 ? _b : '127.0.0.1';
|
|
24
|
+
this.port = ((_c = options === null || options === void 0 ? void 0 : options.port) !== null && _c !== void 0 ? _c : this.protocol == 'ws') ? 80 : 443;
|
|
25
|
+
this.auth = (_d = options === null || options === void 0 ? void 0 : options.auth) !== null && _d !== void 0 ? _d : '';
|
|
26
|
+
this.serviceName = (_e = options === null || options === void 0 ? void 0 : options.serviceName) !== null && _e !== void 0 ? _e : '';
|
|
27
|
+
this.serviceID = (_f = options === null || options === void 0 ? void 0 : options.serviceID) !== null && _f !== void 0 ? _f : -1;
|
|
28
|
+
this.camera = (_g = options === null || options === void 0 ? void 0 : options.camera) !== null && _g !== void 0 ? _g : 0;
|
|
29
|
+
this.callId = 0;
|
|
30
|
+
this.sendMessages = {};
|
|
31
|
+
EventEmitter.call(this);
|
|
32
|
+
}
|
|
33
|
+
connect() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
if (this.serviceID != -1) {
|
|
36
|
+
yield this.openWebsocket();
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
try {
|
|
40
|
+
let id = yield this.createService();
|
|
41
|
+
this.serviceID = id;
|
|
42
|
+
yield this.openWebsocket();
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
this.reportErr(err);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
createService() {
|
|
51
|
+
var _a;
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const options = {
|
|
54
|
+
host: this.ip,
|
|
55
|
+
port: this.port,
|
|
56
|
+
path: '/local/camoverlay/api/services.cgi?action=get',
|
|
57
|
+
auth: this.auth,
|
|
58
|
+
};
|
|
59
|
+
const response = (yield (0, HTTPRequest_1.httpRequest)(options));
|
|
60
|
+
let servicesJson;
|
|
61
|
+
try {
|
|
62
|
+
servicesJson = JSON.parse(response);
|
|
63
|
+
(_a = servicesJson.services) !== null && _a !== void 0 ? _a : (servicesJson.services = []);
|
|
64
|
+
}
|
|
65
|
+
catch (_b) {
|
|
66
|
+
servicesJson = { services: [] };
|
|
67
|
+
}
|
|
68
|
+
let service = null;
|
|
69
|
+
let maxID = -1;
|
|
70
|
+
let servicesArr = servicesJson.services;
|
|
71
|
+
for (let s of servicesArr) {
|
|
72
|
+
if (s.id > maxID) {
|
|
73
|
+
maxID = s.id;
|
|
74
|
+
}
|
|
75
|
+
if (s.identifier == this.serviceName && s.name == 'scripter') {
|
|
76
|
+
service = s;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (service != null) {
|
|
81
|
+
if (service.enabled == 1) {
|
|
82
|
+
if (service.camera == undefined || service.camera != this.camera) {
|
|
83
|
+
service.camera = this.camera;
|
|
84
|
+
yield this.updateServices(servicesJson);
|
|
85
|
+
return service.id;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return service.id;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
throw new Error('CamOverlay service is not enabled');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
let newServiceID = maxID + 1;
|
|
97
|
+
service = {
|
|
98
|
+
id: newServiceID,
|
|
99
|
+
enabled: 1,
|
|
100
|
+
schedule: '',
|
|
101
|
+
name: 'scripter',
|
|
102
|
+
identifier: this.serviceName,
|
|
103
|
+
camera: this.camera,
|
|
104
|
+
};
|
|
105
|
+
servicesJson.services.push(service);
|
|
106
|
+
yield this.updateServices(servicesJson);
|
|
107
|
+
return newServiceID;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
updateServices(servicesJson) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const options = {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
host: this.ip,
|
|
116
|
+
port: this.port,
|
|
117
|
+
path: '/local/camoverlay/api/services.cgi?action=set',
|
|
118
|
+
auth: this.auth,
|
|
119
|
+
};
|
|
120
|
+
yield (0, HTTPRequest_1.httpRequest)(options, JSON.stringify(servicesJson));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
openWebsocket(digestHeader) {
|
|
124
|
+
let promise = new Promise((resolve, reject) => {
|
|
125
|
+
let userPass = this.auth.split(':');
|
|
126
|
+
let addr = `${this.protocol}://${this.ip}:${this.port}/local/camoverlay/ws`;
|
|
127
|
+
let options = {
|
|
128
|
+
auth: this.auth,
|
|
129
|
+
headers: {},
|
|
130
|
+
};
|
|
131
|
+
if (digestHeader != undefined) {
|
|
132
|
+
options.headers['Authorization'] = Digest_1.Digest.getAuthHeader(userPass[0], userPass[1], 'GET', '/local/camoverlay/ws', digestHeader);
|
|
133
|
+
}
|
|
134
|
+
this.ws = new WebSocket(addr, 'cairo-api', options);
|
|
135
|
+
this.ws.on('open', () => {
|
|
136
|
+
this.reportMsg('Websocket opened');
|
|
137
|
+
resolve();
|
|
138
|
+
});
|
|
139
|
+
this.ws.on('message', (data) => {
|
|
140
|
+
let dataJSON = JSON.parse(data);
|
|
141
|
+
if (dataJSON.hasOwnProperty('call_id') && dataJSON['call_id'] in this.sendMessages) {
|
|
142
|
+
this.sendMessages[dataJSON['call_id']].resolve(dataJSON);
|
|
143
|
+
delete this.sendMessages[dataJSON['call_id']];
|
|
144
|
+
}
|
|
145
|
+
if (dataJSON.hasOwnProperty('error')) {
|
|
146
|
+
let error = new Error(JSON.stringify(data));
|
|
147
|
+
this.reportErr(error);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
this.reportMsg(data);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
this.ws.on('unexpected-response', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
if (res.statusCode == 401 && res.headers['www-authenticate'] != undefined)
|
|
155
|
+
this.openWebsocket(res.headers['www-authenticate']).then(resolve, reject);
|
|
156
|
+
else {
|
|
157
|
+
reject('Error: status code: ' + res.statusCode + ', ' + res.data);
|
|
158
|
+
}
|
|
159
|
+
}));
|
|
160
|
+
this.ws.on('error', (error) => {
|
|
161
|
+
this.reportErr(error);
|
|
162
|
+
reject(error);
|
|
163
|
+
});
|
|
164
|
+
this.ws.on('close', () => {
|
|
165
|
+
this.reportClose();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
return promise;
|
|
169
|
+
}
|
|
170
|
+
cairo(command, ...params) {
|
|
171
|
+
return this.sendMessage({ command: command, params: params });
|
|
172
|
+
}
|
|
173
|
+
writeText(...params) {
|
|
174
|
+
return this.sendMessage({ command: 'write_text', params: params });
|
|
175
|
+
}
|
|
176
|
+
uploadImageData(imgBuffer) {
|
|
177
|
+
return this.sendMessage({ command: 'upload_image_data', params: [imgBuffer.toString('base64')] });
|
|
178
|
+
}
|
|
179
|
+
uploadFontData(fontBuffer) {
|
|
180
|
+
return this.sendMessage({ command: 'upload_font_data', params: [fontBuffer.toString('base64')] });
|
|
181
|
+
}
|
|
182
|
+
showCairoImage(cairoImage, posX, posY) {
|
|
183
|
+
return this.sendMessage({ command: 'show_cairo_image', params: [this.serviceID, cairoImage, posX, posY] });
|
|
184
|
+
}
|
|
185
|
+
removeImage() {
|
|
186
|
+
return this.sendMessage({ command: 'remove_image', params: [this.serviceID] });
|
|
187
|
+
}
|
|
188
|
+
showCairoImageAbsolute(cairoImage, posX, posY, width, height) {
|
|
189
|
+
return this.sendMessage({
|
|
190
|
+
command: 'show_cairo_image',
|
|
191
|
+
params: [this.serviceID, cairoImage, -1.0 + (2.0 / width) * posX, -1.0 + (2.0 / height) * posY],
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
sendMessage(msgJson) {
|
|
195
|
+
let promise = new Promise((resolve, reject) => {
|
|
196
|
+
try {
|
|
197
|
+
this.sendMessages[this.callId] = { resolve, reject };
|
|
198
|
+
msgJson['call_id'] = this.callId++;
|
|
199
|
+
this.ws.send(JSON.stringify(msgJson));
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
this.reportErr(new Error(`Send message error: ${err}`));
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
return promise;
|
|
206
|
+
}
|
|
207
|
+
reportMsg(msg) {
|
|
208
|
+
this.emit('msg', msg);
|
|
209
|
+
}
|
|
210
|
+
reportErr(err) {
|
|
211
|
+
var _a;
|
|
212
|
+
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.terminate();
|
|
213
|
+
this.emit('error', err);
|
|
214
|
+
}
|
|
215
|
+
reportClose() {
|
|
216
|
+
this.emit('close');
|
|
217
|
+
}
|
|
218
|
+
updateCGText(fields) {
|
|
219
|
+
let field_specs = '';
|
|
220
|
+
for (let field of fields) {
|
|
221
|
+
const name = field.field_name;
|
|
222
|
+
field_specs += `&${name}=${field.text}`;
|
|
223
|
+
if (field.color != undefined) {
|
|
224
|
+
field_specs += `&${name}_color=${field.color}`;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return this.promiseCGUpdate('update_text', field_specs);
|
|
228
|
+
}
|
|
229
|
+
formCoordinates(coordinates, x, y) {
|
|
230
|
+
return coordinates != '' ? `&coord_system=${coordinates}&pos_x=${x}&pos_y=${y}` : '';
|
|
231
|
+
}
|
|
232
|
+
updateCGImage(path, coordinates = '', x = 0, y = 0) {
|
|
233
|
+
const coord = this.formCoordinates(coordinates, x, y);
|
|
234
|
+
const update = `&image=${path}`;
|
|
235
|
+
return this.promiseCGUpdate('update_image', update + coord);
|
|
236
|
+
}
|
|
237
|
+
updateCGImagePos(coordinates = '', x = 0, y = 0) {
|
|
238
|
+
const coord = this.formCoordinates(coordinates, x, y);
|
|
239
|
+
return this.promiseCGUpdate('update_image', coord);
|
|
240
|
+
}
|
|
241
|
+
promiseCGUpdate(action, params) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
const path = encodeURI(`/local/camoverlay/api/customGraphics.cgi?action=${action}&service_id=${this.serviceID}${params}`);
|
|
244
|
+
const options = {
|
|
245
|
+
method: 'POST',
|
|
246
|
+
host: this.ip,
|
|
247
|
+
port: this.port,
|
|
248
|
+
path: path,
|
|
249
|
+
auth: this.auth,
|
|
250
|
+
};
|
|
251
|
+
yield (0, HTTPRequest_1.httpRequest)(options, '');
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
updateInfoticker(text) {
|
|
255
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
+
const path = `/local/camoverlay/api/infoticker.cgi?service_id=${this.serviceID}&text=${text}`;
|
|
257
|
+
const options = {
|
|
258
|
+
method: 'GET',
|
|
259
|
+
host: this.ip,
|
|
260
|
+
port: this.port,
|
|
261
|
+
path: path,
|
|
262
|
+
auth: this.auth,
|
|
263
|
+
};
|
|
264
|
+
yield (0, HTTPRequest_1.httpRequest)(options, '');
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
setEnabled(enabled) {
|
|
268
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
+
const value = enabled ? 1 : 0;
|
|
270
|
+
const path = encodeURI(`/local/camoverlay/api/enabled.cgi?id${this.serviceID}=${value}`);
|
|
271
|
+
const options = {
|
|
272
|
+
method: 'POST',
|
|
273
|
+
host: this.ip,
|
|
274
|
+
port: this.port,
|
|
275
|
+
path: path,
|
|
276
|
+
auth: this.auth,
|
|
277
|
+
};
|
|
278
|
+
yield (0, HTTPRequest_1.httpRequest)(options, '');
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
isEnabled() {
|
|
282
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
const options = {
|
|
284
|
+
method: 'GET',
|
|
285
|
+
host: this.ip,
|
|
286
|
+
port: this.port,
|
|
287
|
+
path: '/local/camoverlay/api/services.cgi?action=get',
|
|
288
|
+
auth: this.auth,
|
|
289
|
+
};
|
|
290
|
+
const response = (yield (0, HTTPRequest_1.httpRequest)(options, ''));
|
|
291
|
+
const data = JSON.parse(response);
|
|
292
|
+
for (let service of data.services) {
|
|
293
|
+
if (service.id == this.serviceID) {
|
|
294
|
+
return service.enabled == 1;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
throw new Error('Service not found.');
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
exports.CamOverlayAPI = CamOverlayAPI;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare type CamStreamerAPIOptions = {
|
|
2
|
+
protocol: string;
|
|
3
|
+
ip: string;
|
|
4
|
+
port: number;
|
|
5
|
+
auth: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class CamStreamerAPI {
|
|
8
|
+
private protocol;
|
|
9
|
+
private ip;
|
|
10
|
+
private port;
|
|
11
|
+
private auth;
|
|
12
|
+
constructor(options?: CamStreamerAPIOptions);
|
|
13
|
+
getStreamList(): Promise<any>;
|
|
14
|
+
getStreamParameter(streamID: string, paramName: string): Promise<any>;
|
|
15
|
+
setStreamParameter(streamID: string, paramName: string, value: string): Promise<any>;
|
|
16
|
+
isStreaming(streamID: string): Promise<any>;
|
|
17
|
+
get(path: string): Promise<any>;
|
|
18
|
+
private getBaseConnectionParams;
|
|
19
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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.CamStreamerAPI = void 0;
|
|
13
|
+
const HTTPRequest_1 = require("./HTTPRequest");
|
|
14
|
+
class CamStreamerAPI {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
var _a, _b, _c, _d;
|
|
17
|
+
this.protocol = (_a = options === null || options === void 0 ? void 0 : options.protocol) !== null && _a !== void 0 ? _a : 'http';
|
|
18
|
+
this.ip = (_b = options === null || options === void 0 ? void 0 : options.ip) !== null && _b !== void 0 ? _b : '127.0.0.1';
|
|
19
|
+
this.port = ((_c = options === null || options === void 0 ? void 0 : options.port) !== null && _c !== void 0 ? _c : this.protocol == 'http') ? 80 : 443;
|
|
20
|
+
this.auth = (_d = options === null || options === void 0 ? void 0 : options.auth) !== null && _d !== void 0 ? _d : '';
|
|
21
|
+
}
|
|
22
|
+
getStreamList() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const streamListRes = yield this.get('/local/camstreamer/stream/list.cgi');
|
|
25
|
+
return streamListRes.data;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
getStreamParameter(streamID, paramName) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const stream = yield this.get(`/local/camstreamer/stream/get.cgi?stream_id=${streamID}`);
|
|
31
|
+
return stream.data[paramName];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
setStreamParameter(streamID, paramName, value) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return yield this.get(`/local/camstreamer/stream/set.cgi?stream_id=${streamID}&${paramName}=${value}`);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
isStreaming(streamID) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const response = yield this.get(`/local/camstreamer/get_streamstat.cgi?stream_id=${streamID}`);
|
|
42
|
+
return response.data.is_streaming;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
get(path) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const options = this.getBaseConnectionParams();
|
|
48
|
+
options.path = encodeURI(path);
|
|
49
|
+
const data = (yield (0, HTTPRequest_1.httpRequest)(options));
|
|
50
|
+
return JSON.parse(data);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
getBaseConnectionParams() {
|
|
54
|
+
return {
|
|
55
|
+
protocol: this.protocol + ':',
|
|
56
|
+
host: this.ip,
|
|
57
|
+
port: this.port,
|
|
58
|
+
auth: this.auth,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.CamStreamerAPI = CamStreamerAPI;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as EventEmitter from 'events';
|
|
3
|
+
export declare type CamSwitcherAPIOptions = {
|
|
4
|
+
ip?: string;
|
|
5
|
+
port?: number;
|
|
6
|
+
auth?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class CamSwitcherAPI extends EventEmitter {
|
|
9
|
+
private ip;
|
|
10
|
+
private port;
|
|
11
|
+
private auth;
|
|
12
|
+
private ws;
|
|
13
|
+
private pingTimer;
|
|
14
|
+
constructor(options: CamSwitcherAPIOptions);
|
|
15
|
+
connect(): Promise<void>;
|
|
16
|
+
getPlaylistList(): Promise<object>;
|
|
17
|
+
getClipList(): Promise<object>;
|
|
18
|
+
playlistSwitch(playlistName: string): Promise<object>;
|
|
19
|
+
playlistQueueList(): Promise<object>;
|
|
20
|
+
playlistQueueClear(): Promise<object>;
|
|
21
|
+
playlistQueuePush(playlistName: string): Promise<object>;
|
|
22
|
+
playlistQueuePlayNext(): Promise<object>;
|
|
23
|
+
getOutputInfo(): Promise<object>;
|
|
24
|
+
get(path: string): Promise<object>;
|
|
25
|
+
private getBaseConnectionParams;
|
|
26
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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.CamSwitcherAPI = void 0;
|
|
13
|
+
const WebSocket = require("ws");
|
|
14
|
+
const EventEmitter = require("events");
|
|
15
|
+
const HTTPRequest_1 = require("./HTTPRequest");
|
|
16
|
+
class CamSwitcherAPI extends EventEmitter {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
var _a, _b, _c;
|
|
19
|
+
super();
|
|
20
|
+
this.ip = (_a = options === null || options === void 0 ? void 0 : options.ip) !== null && _a !== void 0 ? _a : '127.0.0.1';
|
|
21
|
+
this.port = (_b = options === null || options === void 0 ? void 0 : options.port) !== null && _b !== void 0 ? _b : 80;
|
|
22
|
+
this.auth = (_c = options === null || options === void 0 ? void 0 : options.auth) !== null && _c !== void 0 ? _c : '';
|
|
23
|
+
EventEmitter.call(this);
|
|
24
|
+
}
|
|
25
|
+
connect() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
try {
|
|
28
|
+
const token = yield this.get('/local/camswitcher/ws_authorization.cgi');
|
|
29
|
+
this.ws = new WebSocket(`ws://${this.ip}:${this.port}/local/camswitcher/events`, 'events');
|
|
30
|
+
this.pingTimer = null;
|
|
31
|
+
this.ws.on('open', () => {
|
|
32
|
+
this.ws.send(JSON.stringify({ authorization: token }));
|
|
33
|
+
this.ws.isAlive = true;
|
|
34
|
+
this.pingTimer = setInterval(() => {
|
|
35
|
+
if (this.ws.isAlive === false) {
|
|
36
|
+
return this.ws.terminate();
|
|
37
|
+
}
|
|
38
|
+
this.ws.isAlive = false;
|
|
39
|
+
this.ws.ping();
|
|
40
|
+
}, 30000);
|
|
41
|
+
});
|
|
42
|
+
this.ws.on('pong', () => {
|
|
43
|
+
this.ws.isAlive = true;
|
|
44
|
+
});
|
|
45
|
+
this.ws.on('message', (data) => {
|
|
46
|
+
try {
|
|
47
|
+
const parsedData = JSON.parse(data);
|
|
48
|
+
this.emit('event', parsedData);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
console.log(err);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
this.ws.on('close', () => {
|
|
55
|
+
clearInterval(this.pingTimer);
|
|
56
|
+
this.emit('event_connection_close');
|
|
57
|
+
});
|
|
58
|
+
this.ws.on('error', (err) => {
|
|
59
|
+
this.emit('event_connection_error', err);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
this.emit('event_connection_error', err);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
getPlaylistList() {
|
|
68
|
+
return this.get('/local/camswitcher/playlists.cgi?action=get');
|
|
69
|
+
}
|
|
70
|
+
getClipList() {
|
|
71
|
+
return this.get('/local/camswitcher/clips.cgi?action=get');
|
|
72
|
+
}
|
|
73
|
+
playlistSwitch(playlistName) {
|
|
74
|
+
return this.get(`/local/camswitcher/playlist_switch.cgi?playlist_name=${playlistName}`);
|
|
75
|
+
}
|
|
76
|
+
playlistQueueList() {
|
|
77
|
+
return this.get('/local/camswitcher/playlist_queue_list.cgi');
|
|
78
|
+
}
|
|
79
|
+
playlistQueueClear() {
|
|
80
|
+
return this.get('/local/camswitcher/playlist_queue_clear.cgi');
|
|
81
|
+
}
|
|
82
|
+
playlistQueuePush(playlistName) {
|
|
83
|
+
return this.get(`/local/camswitcher/playlist_queue_push.cgi?playlist_name=${playlistName}`);
|
|
84
|
+
}
|
|
85
|
+
playlistQueuePlayNext() {
|
|
86
|
+
return this.get('/local/camswitcher/playlist_queue_play_next.cgi');
|
|
87
|
+
}
|
|
88
|
+
getOutputInfo() {
|
|
89
|
+
return this.get('/local/camswitcher/output_info.cgi');
|
|
90
|
+
}
|
|
91
|
+
get(path) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const options = this.getBaseConnectionParams();
|
|
94
|
+
options.path = encodeURI(path);
|
|
95
|
+
const data = (yield (0, HTTPRequest_1.httpRequest)(options));
|
|
96
|
+
try {
|
|
97
|
+
const response = JSON.parse(data);
|
|
98
|
+
if (response.status == 200) {
|
|
99
|
+
return response.data;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw new Error(`Request (${path}) error, response: ${JSON.stringify(response)}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
throw new Error(`Request (${path}) error: ${err}, msg: ${data}`);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
getBaseConnectionParams() {
|
|
111
|
+
return {
|
|
112
|
+
protocol: 'http:',
|
|
113
|
+
host: this.ip,
|
|
114
|
+
port: this.port,
|
|
115
|
+
auth: this.auth,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.CamSwitcherAPI = CamSwitcherAPI;
|
package/CameraVapix.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import * as http from 'http';
|
|
4
|
+
import { EventEmitter2 as EventEmitter } from 'eventemitter2';
|
|
5
|
+
export declare type CameraVapixOptions = {
|
|
6
|
+
protocol?: string;
|
|
7
|
+
ip?: string;
|
|
8
|
+
port?: number;
|
|
9
|
+
auth?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare type ApplicationList = {
|
|
12
|
+
reply: {
|
|
13
|
+
$: {
|
|
14
|
+
result: string;
|
|
15
|
+
};
|
|
16
|
+
application: {
|
|
17
|
+
$: Application;
|
|
18
|
+
}[];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare type Application = {
|
|
22
|
+
Name: string;
|
|
23
|
+
NiceName: string;
|
|
24
|
+
Vendor: string;
|
|
25
|
+
Version: string;
|
|
26
|
+
ApplicationID?: string;
|
|
27
|
+
License: string;
|
|
28
|
+
Status: string;
|
|
29
|
+
ConfigurationPage?: string;
|
|
30
|
+
VendorHomePage?: string;
|
|
31
|
+
LicenseName?: string;
|
|
32
|
+
};
|
|
33
|
+
export declare type GuardTour = {
|
|
34
|
+
id: string;
|
|
35
|
+
camNbr: any;
|
|
36
|
+
name: string;
|
|
37
|
+
randomEnabled: any;
|
|
38
|
+
running: string;
|
|
39
|
+
timeBetweenSequences: any;
|
|
40
|
+
tour: {
|
|
41
|
+
moveSpeed: any;
|
|
42
|
+
position: any;
|
|
43
|
+
presetNbr: any;
|
|
44
|
+
waitTime: any;
|
|
45
|
+
waitTimeViewType: any;
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
export declare class CameraVapix extends EventEmitter {
|
|
49
|
+
private protocol;
|
|
50
|
+
private ip;
|
|
51
|
+
private port;
|
|
52
|
+
private auth;
|
|
53
|
+
private rtsp;
|
|
54
|
+
private ws;
|
|
55
|
+
constructor(options?: CameraVapixOptions);
|
|
56
|
+
getParameterGroup(groupNames: string): Promise<{}>;
|
|
57
|
+
setParameter(params: object): Promise<string>;
|
|
58
|
+
getPTZPresetList(channel: string): Promise<string[]>;
|
|
59
|
+
goToPreset(channel: number, presetName: string): Promise<string>;
|
|
60
|
+
getGuardTourList(): Promise<GuardTour[]>;
|
|
61
|
+
setGuardTourEnabled(gourTourID: string, enable: boolean): Promise<string>;
|
|
62
|
+
getInputState(port: number): Promise<boolean>;
|
|
63
|
+
setOutputState(port: number, active: boolean): Promise<string>;
|
|
64
|
+
getApplicationList(): Promise<Application[]>;
|
|
65
|
+
getEventDeclarations(): Promise<string>;
|
|
66
|
+
private isReservedEventName;
|
|
67
|
+
eventsConnect(channel?: string): void;
|
|
68
|
+
eventsDisconnect(): void;
|
|
69
|
+
private rtspConnect;
|
|
70
|
+
private websocketConnect;
|
|
71
|
+
vapixGet(path: string, noWaitForData?: boolean): Promise<string | http.IncomingMessage>;
|
|
72
|
+
getCameraImage(camera: string, compression: string, resolution: string, outputStream: NodeJS.WritableStream): Promise<NodeJS.WritableStream>;
|
|
73
|
+
vapixPost(path: string, data: string, contentType?: string): Promise<string>;
|
|
74
|
+
private getBaseVapixConnectionParams;
|
|
75
|
+
}
|