camstreamerlib 1.9.0 → 2.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 +14 -68
- package/CamOverlayAPI.js +46 -281
- package/CamOverlayDrawingAPI.d.ts +68 -0
- package/CamOverlayDrawingAPI.js +176 -0
- package/CamScripterAPICameraEventsGenerator.d.ts +9 -14
- 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 +10 -19
- package/CameraVapix.js +73 -154
- package/{HTTPRequest.d.ts → HttpRequest.d.ts} +1 -1
- package/HttpServer.d.ts +2 -2
- 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.js → HttpRequest.js} +0 -0
|
@@ -0,0 +1,176 @@
|
|
|
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.CamOverlayDrawingAPI = void 0;
|
|
13
|
+
const EventEmitter = require("events");
|
|
14
|
+
const WsClient_1 = require("./WsClient");
|
|
15
|
+
class CamOverlayDrawingAPI extends EventEmitter {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
var _a, _b, _c, _d, _e, _f;
|
|
18
|
+
super();
|
|
19
|
+
this.ws = null;
|
|
20
|
+
this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
|
|
21
|
+
this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
|
|
22
|
+
this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
|
|
23
|
+
this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
|
|
24
|
+
this.auth = (_e = options === null || options === void 0 ? void 0 : options.auth) !== null && _e !== void 0 ? _e : '';
|
|
25
|
+
this.zIndex = (_f = options === null || options === void 0 ? void 0 : options.zIndex) !== null && _f !== void 0 ? _f : 0;
|
|
26
|
+
this.cameraList = [0];
|
|
27
|
+
if (Array.isArray(options === null || options === void 0 ? void 0 : options.camera)) {
|
|
28
|
+
this.cameraList = options.camera;
|
|
29
|
+
}
|
|
30
|
+
else if (typeof (options === null || options === void 0 ? void 0 : options.camera) === 'number') {
|
|
31
|
+
this.cameraList = [options.camera];
|
|
32
|
+
}
|
|
33
|
+
this.callId = 0;
|
|
34
|
+
this.sendMessages = {};
|
|
35
|
+
EventEmitter.call(this);
|
|
36
|
+
}
|
|
37
|
+
connect() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
try {
|
|
40
|
+
yield this.openWebsocket();
|
|
41
|
+
this.emit('open');
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
this.reportError(err);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
cairo(command, ...params) {
|
|
49
|
+
return this.sendMessage({ command: command, params: params });
|
|
50
|
+
}
|
|
51
|
+
writeText(...params) {
|
|
52
|
+
return this.sendMessage({ command: 'write_text', params: params });
|
|
53
|
+
}
|
|
54
|
+
uploadImageData(imgBuffer) {
|
|
55
|
+
return this.sendBinaryMessage({
|
|
56
|
+
command: 'upload_image_data',
|
|
57
|
+
params: [],
|
|
58
|
+
}, imgBuffer);
|
|
59
|
+
}
|
|
60
|
+
uploadFontData(fontBuffer) {
|
|
61
|
+
return this.sendBinaryMessage({
|
|
62
|
+
command: 'upload_font_data',
|
|
63
|
+
params: [fontBuffer.toString('base64')],
|
|
64
|
+
}, fontBuffer);
|
|
65
|
+
}
|
|
66
|
+
showCairoImage(cairoImage, posX, posY) {
|
|
67
|
+
return this.sendMessage({
|
|
68
|
+
command: 'show_cairo_image_v2',
|
|
69
|
+
params: [cairoImage, posX, posY, this.cameraList, this.zIndex],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
showCairoImageAbsolute(cairoImage, posX, posY, width, height) {
|
|
73
|
+
return this.sendMessage({
|
|
74
|
+
command: 'show_cairo_image_v2',
|
|
75
|
+
params: [
|
|
76
|
+
cairoImage,
|
|
77
|
+
-1.0 + (2.0 / width) * posX,
|
|
78
|
+
-1.0 + (2.0 / height) * posY,
|
|
79
|
+
this.cameraList,
|
|
80
|
+
this.zIndex,
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
removeImage() {
|
|
85
|
+
return this.sendMessage({ command: 'remove_image_v2' });
|
|
86
|
+
}
|
|
87
|
+
openWebsocket() {
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
const options = {
|
|
90
|
+
ip: this.ip,
|
|
91
|
+
port: this.port,
|
|
92
|
+
address: '/local/camoverlay/ws',
|
|
93
|
+
protocol: 'cairo-api',
|
|
94
|
+
auth: this.auth,
|
|
95
|
+
tls: this.tls,
|
|
96
|
+
tlsInsecure: this.tlsInsecure,
|
|
97
|
+
};
|
|
98
|
+
this.ws = new WsClient_1.WsClient(options);
|
|
99
|
+
this.ws.on('open', () => {
|
|
100
|
+
this.reportMessage('Websocket opened');
|
|
101
|
+
resolve();
|
|
102
|
+
});
|
|
103
|
+
this.ws.on('message', (data) => {
|
|
104
|
+
let dataJSON = JSON.parse(data.toString());
|
|
105
|
+
if (dataJSON.hasOwnProperty('call_id') && dataJSON['call_id'] in this.sendMessages) {
|
|
106
|
+
if (dataJSON.hasOwnProperty('error')) {
|
|
107
|
+
this.sendMessages[dataJSON['call_id']].reject(new Error(dataJSON.error));
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
this.sendMessages[dataJSON['call_id']].resolve(dataJSON);
|
|
111
|
+
}
|
|
112
|
+
delete this.sendMessages[dataJSON['call_id']];
|
|
113
|
+
}
|
|
114
|
+
if (dataJSON.hasOwnProperty('error')) {
|
|
115
|
+
this.reportError(new Error(dataJSON.error));
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
this.reportMessage(data.toString());
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
this.ws.on('error', (error) => {
|
|
122
|
+
this.reportError(error);
|
|
123
|
+
reject(error);
|
|
124
|
+
});
|
|
125
|
+
this.ws.on('close', () => {
|
|
126
|
+
this.reportClose();
|
|
127
|
+
});
|
|
128
|
+
this.ws.open();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
sendMessage(msgJson) {
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
try {
|
|
134
|
+
this.sendMessages[this.callId] = { resolve, reject };
|
|
135
|
+
msgJson['call_id'] = this.callId++;
|
|
136
|
+
this.ws.send(JSON.stringify(msgJson));
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
this.reportError(new Error(`Send message error: ${err}`));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
sendBinaryMessage(msgJson, data) {
|
|
144
|
+
return new Promise((resolve, reject) => {
|
|
145
|
+
try {
|
|
146
|
+
this.sendMessages[this.callId] = { resolve, reject };
|
|
147
|
+
msgJson['call_id'] = this.callId++;
|
|
148
|
+
const jsonBuffer = Buffer.from(JSON.stringify(msgJson));
|
|
149
|
+
const header = new ArrayBuffer(5);
|
|
150
|
+
const headerView = new DataView(header);
|
|
151
|
+
headerView.setInt8(0, 1);
|
|
152
|
+
headerView.setInt32(1, jsonBuffer.byteLength);
|
|
153
|
+
const msgBuffer = Buffer.concat([Buffer.from(header), jsonBuffer, data]);
|
|
154
|
+
this.ws.send(msgBuffer);
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
this.reportError(new Error(`Send binary message error: ${err}`));
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
reportMessage(msg) {
|
|
162
|
+
this.emit('message', msg);
|
|
163
|
+
}
|
|
164
|
+
reportError(err) {
|
|
165
|
+
this.ws.close();
|
|
166
|
+
this.emit('error', err);
|
|
167
|
+
}
|
|
168
|
+
reportClose() {
|
|
169
|
+
for (const callId in this.sendMessages) {
|
|
170
|
+
this.sendMessages[callId].reject(new Error('Connection lost'));
|
|
171
|
+
}
|
|
172
|
+
this.sendMessages = {};
|
|
173
|
+
this.emit('close');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.CamOverlayDrawingAPI = CamOverlayDrawingAPI;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as EventEmitter from 'events';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
ip?: string;
|
|
7
|
-
port?: number;
|
|
8
|
-
auth?: string;
|
|
9
|
-
};
|
|
10
|
-
export declare type Declaration = {
|
|
3
|
+
import { Options } from './common';
|
|
4
|
+
export type CamScripterOptions = Options;
|
|
5
|
+
export type Declaration = {
|
|
11
6
|
type?: '' | 'SOURCE' | 'DATA';
|
|
12
7
|
namespace: string;
|
|
13
8
|
key: string;
|
|
@@ -16,25 +11,25 @@ export declare type Declaration = {
|
|
|
16
11
|
key_nice_name?: string;
|
|
17
12
|
value_nice_name?: string;
|
|
18
13
|
};
|
|
19
|
-
export
|
|
14
|
+
export type EventDeclaration = {
|
|
20
15
|
declaration_id: string;
|
|
21
16
|
stateless: boolean;
|
|
22
17
|
declaration: Declaration[];
|
|
23
18
|
};
|
|
24
|
-
export
|
|
19
|
+
export type EventUndeclaration = {
|
|
25
20
|
declaration_id: string;
|
|
26
21
|
};
|
|
27
|
-
export
|
|
22
|
+
export type EventData = {
|
|
28
23
|
namespace: string;
|
|
29
24
|
key: string;
|
|
30
25
|
value: string | boolean | number;
|
|
31
26
|
value_type: 'STRING' | 'INT' | 'BOOL' | 'DOUBLE';
|
|
32
27
|
};
|
|
33
|
-
export
|
|
28
|
+
export type Event = {
|
|
34
29
|
declaration_id: string;
|
|
35
30
|
event_data: EventData[];
|
|
36
31
|
};
|
|
37
|
-
export
|
|
32
|
+
export type Response = {
|
|
38
33
|
call_id: number;
|
|
39
34
|
message: string;
|
|
40
35
|
};
|
|
@@ -49,11 +44,11 @@ export declare class CamScripterAPICameraEventsGenerator extends EventEmitter {
|
|
|
49
44
|
private ws;
|
|
50
45
|
constructor(options?: CamScripterOptions);
|
|
51
46
|
connect(): Promise<void>;
|
|
52
|
-
private openWebsocket;
|
|
53
47
|
declareEvent(eventDeclaration: EventDeclaration): Promise<Response>;
|
|
54
48
|
undeclareEvent(eventUndeclaration: EventUndeclaration): Promise<Response>;
|
|
55
49
|
sendEvent(event: Event): Promise<Response>;
|
|
56
50
|
private sendMessage;
|
|
51
|
+
private openWebsocket;
|
|
57
52
|
private reportErr;
|
|
58
53
|
private reportClose;
|
|
59
54
|
}
|
|
@@ -10,9 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CamScripterAPICameraEventsGenerator = void 0;
|
|
13
|
-
const WebSocket = require("ws");
|
|
14
13
|
const EventEmitter = require("events");
|
|
15
|
-
const
|
|
14
|
+
const WsClient_1 = require("./WsClient");
|
|
16
15
|
class CamScripterAPICameraEventsGenerator extends EventEmitter {
|
|
17
16
|
constructor(options) {
|
|
18
17
|
var _a, _b, _c, _d, _e;
|
|
@@ -38,67 +37,6 @@ class CamScripterAPICameraEventsGenerator extends EventEmitter {
|
|
|
38
37
|
}
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
|
-
openWebsocket(digestHeader) {
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
const userPass = this.auth.split(':');
|
|
44
|
-
const protocol = this.tls ? 'wss' : 'ws';
|
|
45
|
-
const addr = `${protocol}://${this.ip}:${this.port}/local/camscripter/ws`;
|
|
46
|
-
const options = {
|
|
47
|
-
auth: this.auth,
|
|
48
|
-
rejectUnauthorized: !this.tlsInsecure,
|
|
49
|
-
headers: {},
|
|
50
|
-
};
|
|
51
|
-
if (digestHeader !== undefined) {
|
|
52
|
-
options.headers['Authorization'] = Digest_1.Digest.getAuthHeader(userPass[0], userPass[1], 'GET', '/local/camscripter/ws', digestHeader);
|
|
53
|
-
}
|
|
54
|
-
this.ws = new WebSocket(addr, 'camera-events', options);
|
|
55
|
-
this.ws.binaryType = 'arraybuffer';
|
|
56
|
-
this.ws.isAlive = true;
|
|
57
|
-
const pingTimer = setInterval(() => {
|
|
58
|
-
if (this.ws.readyState !== this.ws.OPEN || this.ws.isAlive === false) {
|
|
59
|
-
return this.ws.terminate();
|
|
60
|
-
}
|
|
61
|
-
this.ws.isAlive = false;
|
|
62
|
-
this.ws.ping();
|
|
63
|
-
}, 30000);
|
|
64
|
-
this.ws.on('open', () => {
|
|
65
|
-
resolve();
|
|
66
|
-
});
|
|
67
|
-
this.ws.on('pong', () => {
|
|
68
|
-
this.ws.isAlive = true;
|
|
69
|
-
});
|
|
70
|
-
this.ws.on('message', (data) => {
|
|
71
|
-
const dataJSON = JSON.parse(data);
|
|
72
|
-
if (dataJSON.hasOwnProperty('call_id') && dataJSON['call_id'] in this.sendMessages) {
|
|
73
|
-
if (dataJSON.hasOwnProperty('error')) {
|
|
74
|
-
this.sendMessages[dataJSON['call_id']].reject(new Error(dataJSON.error));
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
this.sendMessages[dataJSON['call_id']].resolve(dataJSON);
|
|
78
|
-
}
|
|
79
|
-
delete this.sendMessages[dataJSON['call_id']];
|
|
80
|
-
}
|
|
81
|
-
if (dataJSON.hasOwnProperty('error')) {
|
|
82
|
-
this.reportErr(new Error(dataJSON.error));
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
this.ws.on('unexpected-response', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
if (res.statusCode === 401 && res.headers['www-authenticate'] !== undefined)
|
|
87
|
-
this.openWebsocket(res.headers['www-authenticate']).then(resolve, reject);
|
|
88
|
-
else {
|
|
89
|
-
reject('Error: status code: ' + res.statusCode + ', ' + res.data);
|
|
90
|
-
}
|
|
91
|
-
}));
|
|
92
|
-
this.ws.on('error', (error) => {
|
|
93
|
-
this.reportErr(error);
|
|
94
|
-
reject(error);
|
|
95
|
-
});
|
|
96
|
-
this.ws.on('close', () => {
|
|
97
|
-
clearInterval(pingTimer);
|
|
98
|
-
this.reportClose();
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
40
|
declareEvent(eventDeclaration) {
|
|
103
41
|
return this.sendMessage({
|
|
104
42
|
call_id: 0,
|
|
@@ -132,9 +70,48 @@ class CamScripterAPICameraEventsGenerator extends EventEmitter {
|
|
|
132
70
|
}
|
|
133
71
|
});
|
|
134
72
|
}
|
|
73
|
+
openWebsocket() {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
const options = {
|
|
76
|
+
auth: this.auth,
|
|
77
|
+
tlsInsecure: this.tlsInsecure,
|
|
78
|
+
tls: this.tls,
|
|
79
|
+
ip: this.ip,
|
|
80
|
+
port: this.port,
|
|
81
|
+
address: '/local/camscripter/ws',
|
|
82
|
+
protocol: 'camera-events',
|
|
83
|
+
};
|
|
84
|
+
this.ws = new WsClient_1.WsClient(options);
|
|
85
|
+
this.ws.on('open', () => {
|
|
86
|
+
resolve();
|
|
87
|
+
});
|
|
88
|
+
this.ws.on('message', (data) => {
|
|
89
|
+
const dataJSON = JSON.parse(data.toString());
|
|
90
|
+
if (dataJSON.hasOwnProperty('call_id') && dataJSON['call_id'] in this.sendMessages) {
|
|
91
|
+
if (dataJSON.hasOwnProperty('error')) {
|
|
92
|
+
this.sendMessages[dataJSON['call_id']].reject(new Error(dataJSON.error));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this.sendMessages[dataJSON['call_id']].resolve(dataJSON);
|
|
96
|
+
}
|
|
97
|
+
delete this.sendMessages[dataJSON['call_id']];
|
|
98
|
+
}
|
|
99
|
+
if (dataJSON.hasOwnProperty('error')) {
|
|
100
|
+
this.reportErr(new Error(dataJSON.error));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
this.ws.on('error', (error) => {
|
|
104
|
+
this.reportErr(error);
|
|
105
|
+
reject(error);
|
|
106
|
+
});
|
|
107
|
+
this.ws.on('close', () => {
|
|
108
|
+
this.reportClose();
|
|
109
|
+
});
|
|
110
|
+
this.ws.open();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
135
113
|
reportErr(err) {
|
|
136
|
-
|
|
137
|
-
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.terminate();
|
|
114
|
+
this.ws.close();
|
|
138
115
|
this.emit('error', err);
|
|
139
116
|
}
|
|
140
117
|
reportClose() {
|
package/CamStreamerAPI.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
tls?: boolean;
|
|
4
|
-
tlsInsecure?: boolean;
|
|
5
|
-
ip?: string;
|
|
6
|
-
port?: number;
|
|
7
|
-
auth?: string;
|
|
8
|
-
};
|
|
1
|
+
import { Options } from './common';
|
|
2
|
+
export type CamStreamerAPIOptions = Options;
|
|
9
3
|
export declare class CamStreamerAPI {
|
|
10
4
|
private tls;
|
|
11
5
|
private tlsInsecure;
|
package/CamStreamerAPI.js
CHANGED
|
@@ -10,14 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CamStreamerAPI = void 0;
|
|
13
|
-
const
|
|
13
|
+
const HttpRequest_1 = require("./HttpRequest");
|
|
14
14
|
class CamStreamerAPI {
|
|
15
15
|
constructor(options) {
|
|
16
16
|
var _a, _b, _c, _d, _e;
|
|
17
17
|
this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
|
|
18
|
-
if ((options === null || options === void 0 ? void 0 : options.tls) === undefined && (options === null || options === void 0 ? void 0 : options.protocol) !== undefined) {
|
|
19
|
-
this.tls = options.protocol === 'https';
|
|
20
|
-
}
|
|
21
18
|
this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
|
|
22
19
|
this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
|
|
23
20
|
this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
|
|
@@ -50,7 +47,7 @@ class CamStreamerAPI {
|
|
|
50
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
48
|
const options = this.getBaseConnectionParams();
|
|
52
49
|
options.path = encodeURI(path);
|
|
53
|
-
const data = (yield (0,
|
|
50
|
+
const data = (yield (0, HttpRequest_1.httpRequest)(options));
|
|
54
51
|
return JSON.parse(data);
|
|
55
52
|
});
|
|
56
53
|
}
|
package/CamSwitcherAPI.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as EventEmitter from 'events';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
tlsInsecure?: boolean;
|
|
6
|
-
ip?: string;
|
|
7
|
-
port?: number;
|
|
8
|
-
auth?: string;
|
|
9
|
-
};
|
|
3
|
+
import { Options } from './common';
|
|
4
|
+
export type CamSwitcherAPIOptions = Options;
|
|
10
5
|
export declare class CamSwitcherAPI extends EventEmitter {
|
|
11
6
|
private tls;
|
|
12
7
|
private tlsInsecure;
|
|
@@ -14,8 +9,7 @@ export declare class CamSwitcherAPI extends EventEmitter {
|
|
|
14
9
|
private port;
|
|
15
10
|
private auth;
|
|
16
11
|
private ws;
|
|
17
|
-
|
|
18
|
-
constructor(options: CamSwitcherAPIOptions);
|
|
12
|
+
constructor(options?: CamSwitcherAPIOptions);
|
|
19
13
|
connect(): Promise<void>;
|
|
20
14
|
getPlaylistList(): Promise<object>;
|
|
21
15
|
getClipList(): Promise<object>;
|
package/CamSwitcherAPI.js
CHANGED
|
@@ -10,9 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CamSwitcherAPI = void 0;
|
|
13
|
-
const WebSocket = require("ws");
|
|
14
13
|
const EventEmitter = require("events");
|
|
15
|
-
const
|
|
14
|
+
const WsClient_1 = require("./WsClient");
|
|
15
|
+
const HttpRequest_1 = require("./HttpRequest");
|
|
16
16
|
class CamSwitcherAPI extends EventEmitter {
|
|
17
17
|
constructor(options) {
|
|
18
18
|
var _a, _b, _c, _d, _e;
|
|
@@ -20,7 +20,7 @@ class CamSwitcherAPI extends EventEmitter {
|
|
|
20
20
|
this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
|
|
21
21
|
this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
|
|
22
22
|
this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
|
|
23
|
-
this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : 80;
|
|
23
|
+
this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
|
|
24
24
|
this.auth = (_e = options === null || options === void 0 ? void 0 : options.auth) !== null && _e !== void 0 ? _e : '';
|
|
25
25
|
EventEmitter.call(this);
|
|
26
26
|
}
|
|
@@ -28,28 +28,22 @@ class CamSwitcherAPI extends EventEmitter {
|
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
29
|
try {
|
|
30
30
|
const token = yield this.get('/local/camswitcher/ws_authorization.cgi');
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const options = {
|
|
32
|
+
ip: this.ip,
|
|
33
|
+
port: this.port,
|
|
34
|
+
auth: this.auth,
|
|
35
|
+
tls: this.tls,
|
|
36
|
+
tlsInsecure: this.tlsInsecure,
|
|
37
|
+
address: '/local/camswitcher/events',
|
|
38
|
+
protocol: 'events',
|
|
39
|
+
};
|
|
40
|
+
this.ws = new WsClient_1.WsClient(options);
|
|
36
41
|
this.ws.on('open', () => {
|
|
37
42
|
this.ws.send(JSON.stringify({ authorization: token }));
|
|
38
|
-
this.ws.isAlive = true;
|
|
39
|
-
this.pingTimer = setInterval(() => {
|
|
40
|
-
if (this.ws.isAlive === false) {
|
|
41
|
-
return this.ws.terminate();
|
|
42
|
-
}
|
|
43
|
-
this.ws.isAlive = false;
|
|
44
|
-
this.ws.ping();
|
|
45
|
-
}, 30000);
|
|
46
|
-
});
|
|
47
|
-
this.ws.on('pong', () => {
|
|
48
|
-
this.ws.isAlive = true;
|
|
49
43
|
});
|
|
50
44
|
this.ws.on('message', (data) => {
|
|
51
45
|
try {
|
|
52
|
-
const parsedData = JSON.parse(data);
|
|
46
|
+
const parsedData = JSON.parse(data.toString());
|
|
53
47
|
this.emit('event', parsedData);
|
|
54
48
|
}
|
|
55
49
|
catch (err) {
|
|
@@ -57,12 +51,12 @@ class CamSwitcherAPI extends EventEmitter {
|
|
|
57
51
|
}
|
|
58
52
|
});
|
|
59
53
|
this.ws.on('close', () => {
|
|
60
|
-
clearInterval(this.pingTimer);
|
|
61
54
|
this.emit('event_connection_close');
|
|
62
55
|
});
|
|
63
56
|
this.ws.on('error', (err) => {
|
|
64
57
|
this.emit('event_connection_error', err);
|
|
65
58
|
});
|
|
59
|
+
this.ws.open();
|
|
66
60
|
}
|
|
67
61
|
catch (err) {
|
|
68
62
|
this.emit('event_connection_error', err);
|
|
@@ -97,7 +91,7 @@ class CamSwitcherAPI extends EventEmitter {
|
|
|
97
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
92
|
const options = this.getBaseConnectionParams();
|
|
99
93
|
options.path = encodeURI(path);
|
|
100
|
-
const data = (yield (0,
|
|
94
|
+
const data = (yield (0, HttpRequest_1.httpRequest)(options));
|
|
101
95
|
try {
|
|
102
96
|
const response = JSON.parse(data);
|
|
103
97
|
if (response.status == 200) {
|
package/CameraVapix.d.ts
CHANGED
|
@@ -2,15 +2,9 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import * as http from 'http';
|
|
4
4
|
import { EventEmitter2 as EventEmitter } from 'eventemitter2';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
tlsInsecure?: boolean;
|
|
9
|
-
ip?: string;
|
|
10
|
-
port?: number;
|
|
11
|
-
auth?: string;
|
|
12
|
-
};
|
|
13
|
-
export declare type ApplicationList = {
|
|
5
|
+
import { Options } from './common';
|
|
6
|
+
export type CameraVapixOptions = Options;
|
|
7
|
+
export type ApplicationList = {
|
|
14
8
|
reply: {
|
|
15
9
|
$: {
|
|
16
10
|
result: string;
|
|
@@ -20,7 +14,7 @@ export declare type ApplicationList = {
|
|
|
20
14
|
}[];
|
|
21
15
|
};
|
|
22
16
|
};
|
|
23
|
-
export
|
|
17
|
+
export type Application = {
|
|
24
18
|
Name: string;
|
|
25
19
|
NiceName: string;
|
|
26
20
|
Vendor: string;
|
|
@@ -32,7 +26,7 @@ export declare type Application = {
|
|
|
32
26
|
VendorHomePage?: string;
|
|
33
27
|
LicenseName?: string;
|
|
34
28
|
};
|
|
35
|
-
export
|
|
29
|
+
export type GuardTour = {
|
|
36
30
|
id: string;
|
|
37
31
|
camNbr: any;
|
|
38
32
|
name: string;
|
|
@@ -53,9 +47,10 @@ export declare class CameraVapix extends EventEmitter {
|
|
|
53
47
|
private ip;
|
|
54
48
|
private port;
|
|
55
49
|
private auth;
|
|
56
|
-
private rtsp;
|
|
57
50
|
private ws;
|
|
58
51
|
constructor(options?: CameraVapixOptions);
|
|
52
|
+
vapixGet(path: string, noWaitForData?: boolean): Promise<string | http.IncomingMessage>;
|
|
53
|
+
vapixPost(path: string, data: string, contentType?: string): Promise<string>;
|
|
59
54
|
getParameterGroup(groupNames: string): Promise<{}>;
|
|
60
55
|
setParameter(params: object): Promise<string>;
|
|
61
56
|
getPTZPresetList(channel: string): Promise<string[]>;
|
|
@@ -65,14 +60,10 @@ export declare class CameraVapix extends EventEmitter {
|
|
|
65
60
|
getInputState(port: number): Promise<boolean>;
|
|
66
61
|
setOutputState(port: number, active: boolean): Promise<string>;
|
|
67
62
|
getApplicationList(): Promise<Application[]>;
|
|
63
|
+
getCameraImage(camera: string, compression: string, resolution: string, outputStream: NodeJS.WritableStream): Promise<NodeJS.WritableStream>;
|
|
68
64
|
getEventDeclarations(): Promise<string>;
|
|
69
|
-
|
|
70
|
-
eventsConnect(channel?: string): void;
|
|
65
|
+
eventsConnect(): void;
|
|
71
66
|
eventsDisconnect(): void;
|
|
72
|
-
private
|
|
73
|
-
private websocketConnect;
|
|
74
|
-
vapixGet(path: string, noWaitForData?: boolean): Promise<string | http.IncomingMessage>;
|
|
75
|
-
getCameraImage(camera: string, compression: string, resolution: string, outputStream: NodeJS.WritableStream): Promise<NodeJS.WritableStream>;
|
|
76
|
-
vapixPost(path: string, data: string, contentType?: string): Promise<string>;
|
|
67
|
+
private isReservedEventName;
|
|
77
68
|
private getBaseVapixConnectionParams;
|
|
78
69
|
}
|