camstreamerlib 3.1.0 → 3.2.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 +2 -2
- package/CamOverlayDrawingAPI.d.ts +7 -6
- package/CamOverlayDrawingAPI.js +47 -80
- package/CamOverlayPainter/Painter.d.ts +2 -1
- package/CamOverlayPainter/Painter.js +9 -5
- package/CamScripterAPICameraEventsGenerator.d.ts +10 -5
- package/CamScripterAPICameraEventsGenerator.js +48 -63
- package/CamStreamerAPI.d.ts +2 -2
- package/CamSwitcherAPI.d.ts +2 -2
- package/CamSwitcherEvents.d.ts +7 -5
- package/CamSwitcherEvents.js +38 -32
- package/CameraVapix.d.ts +2 -2
- package/CameraVapix.js +11 -10
- package/CreatePackage.js +12 -5
- package/DefaultAgent.d.ts +4 -4
- package/DefaultAgent.js +27 -27
- package/README.md +11 -1
- package/VapixEvents.d.ts +4 -3
- package/VapixEvents.js +13 -20
- package/events/AxisCameraStationEvents.d.ts +2 -2
- package/internal/Digest.d.ts +2 -1
- package/internal/Digest.js +8 -3
- package/internal/HttpRequestSender.d.ts +28 -0
- package/internal/HttpRequestSender.js +118 -0
- package/internal/WsClient.d.ts +5 -4
- package/internal/WsClient.js +63 -30
- package/internal/common.d.ts +7 -1
- package/internal/common.js +5 -1
- package/package.json +2 -2
- package/internal/HttpRequest.d.ts +0 -15
- package/internal/HttpRequest.js +0 -82
- package/internal/fetchInsecure.d.ts +0 -4
- package/internal/fetchInsecure.js +0 -14
package/CamOverlayAPI.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
3
|
-
export type CamOverlayOptions =
|
|
2
|
+
import { HttpOptions, IClient } from './internal/common';
|
|
3
|
+
export type CamOverlayOptions = HttpOptions;
|
|
4
4
|
export type TField = {
|
|
5
5
|
field_name: string;
|
|
6
6
|
text: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import * as EventEmitter from 'events';
|
|
4
|
-
import {
|
|
5
|
-
export type CamOverlayDrawingOptions =
|
|
4
|
+
import { WsOptions } from './internal/common';
|
|
5
|
+
export type CamOverlayDrawingOptions = WsOptions & {
|
|
6
6
|
camera?: number | number[];
|
|
7
7
|
zIndex?: number;
|
|
8
8
|
};
|
|
@@ -45,11 +45,12 @@ export declare class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
45
45
|
private zIndex;
|
|
46
46
|
private callId;
|
|
47
47
|
private sendMessages;
|
|
48
|
-
private
|
|
49
|
-
private ws
|
|
48
|
+
private wsConnected;
|
|
49
|
+
private ws;
|
|
50
50
|
constructor(options?: CamOverlayDrawingOptions);
|
|
51
|
-
connect():
|
|
51
|
+
connect(): void;
|
|
52
52
|
disconnect(): void;
|
|
53
|
+
isConnected(): boolean;
|
|
53
54
|
cairo(command: string, ...params: unknown[]): Promise<TCairoResponse | TCairoCreateResponse>;
|
|
54
55
|
writeText(...params: TWriteTextParams): Promise<TCairoResponse>;
|
|
55
56
|
uploadImageData(imgBuffer: Buffer): Promise<TUploadImageResponse>;
|
|
@@ -57,7 +58,7 @@ export declare class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
57
58
|
showCairoImage(cairoImage: string, posX: number, posY: number): Promise<TCairoResponse>;
|
|
58
59
|
showCairoImageAbsolute(cairoImage: string, posX: number, posY: number, width: number, height: number): Promise<TCairoResponse>;
|
|
59
60
|
removeImage(): Promise<TCairoResponse>;
|
|
60
|
-
private
|
|
61
|
+
private createWsClient;
|
|
61
62
|
private sendMessage;
|
|
62
63
|
private sendBinaryMessage;
|
|
63
64
|
private reportMessage;
|
package/CamOverlayDrawingAPI.js
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.CamOverlayDrawingAPI = void 0;
|
|
13
4
|
const EventEmitter = require("events");
|
|
14
|
-
const promises_1 = require("timers/promises");
|
|
15
5
|
const WsClient_1 = require("./internal/WsClient");
|
|
16
6
|
class CamOverlayDrawingAPI extends EventEmitter {
|
|
17
7
|
constructor(options) {
|
|
18
8
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
19
9
|
super();
|
|
20
|
-
this.connected = false;
|
|
21
10
|
this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
|
|
22
11
|
this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
|
|
23
12
|
this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
|
|
@@ -34,23 +23,18 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
34
23
|
}
|
|
35
24
|
this.callId = 0;
|
|
36
25
|
this.sendMessages = {};
|
|
26
|
+
this.wsConnected = false;
|
|
27
|
+
this.createWsClient();
|
|
37
28
|
EventEmitter.call(this);
|
|
38
29
|
}
|
|
39
30
|
connect() {
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
yield this.openWebsocket();
|
|
43
|
-
this.connected = true;
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
}
|
|
47
|
-
});
|
|
31
|
+
this.ws.open();
|
|
48
32
|
}
|
|
49
33
|
disconnect() {
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
this.ws.close();
|
|
35
|
+
}
|
|
36
|
+
isConnected() {
|
|
37
|
+
return this.wsConnected;
|
|
54
38
|
}
|
|
55
39
|
cairo(command, ...params) {
|
|
56
40
|
return this.sendMessage({ command: command, params: params });
|
|
@@ -91,60 +75,46 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
91
75
|
removeImage() {
|
|
92
76
|
return this.sendMessage({ command: 'remove_image_v2' });
|
|
93
77
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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));
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
this.sendMessages[dataJSON.call_id].resolve(dataJSON);
|
|
119
|
-
}
|
|
120
|
-
delete this.sendMessages[dataJSON['call_id']];
|
|
121
|
-
}
|
|
78
|
+
createWsClient() {
|
|
79
|
+
const options = {
|
|
80
|
+
ip: this.ip,
|
|
81
|
+
port: this.port,
|
|
82
|
+
address: '/local/camoverlay/ws',
|
|
83
|
+
protocol: 'cairo-api',
|
|
84
|
+
user: this.user,
|
|
85
|
+
pass: this.pass,
|
|
86
|
+
tls: this.tls,
|
|
87
|
+
tlsInsecure: this.tlsInsecure,
|
|
88
|
+
};
|
|
89
|
+
this.ws = new WsClient_1.WsClient(options);
|
|
90
|
+
this.ws.on('open', () => {
|
|
91
|
+
this.wsConnected = true;
|
|
92
|
+
this.emit('open');
|
|
93
|
+
});
|
|
94
|
+
this.ws.on('message', (data) => {
|
|
95
|
+
const dataJSON = JSON.parse(data.toString());
|
|
96
|
+
if (Object.hasOwn(dataJSON, 'call_id') && dataJSON['call_id'] in this.sendMessages) {
|
|
122
97
|
if (Object.hasOwn(dataJSON, 'error')) {
|
|
123
|
-
this.
|
|
98
|
+
this.sendMessages[dataJSON.call_id].reject(new Error(dataJSON.error));
|
|
124
99
|
}
|
|
125
100
|
else {
|
|
126
|
-
this.
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
this.ws.on('error', (error) => {
|
|
130
|
-
this.reportError(error);
|
|
131
|
-
reject(error);
|
|
132
|
-
});
|
|
133
|
-
this.ws.on('close', () => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
this.ws = undefined;
|
|
135
|
-
this.reportClose();
|
|
136
|
-
if (this.connected) {
|
|
137
|
-
try {
|
|
138
|
-
yield (0, promises_1.setTimeout)(10000);
|
|
139
|
-
yield this.openWebsocket();
|
|
140
|
-
resolve();
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
reject(err);
|
|
144
|
-
}
|
|
101
|
+
this.sendMessages[dataJSON.call_id].resolve(dataJSON);
|
|
145
102
|
}
|
|
146
|
-
|
|
147
|
-
|
|
103
|
+
delete this.sendMessages[dataJSON['call_id']];
|
|
104
|
+
}
|
|
105
|
+
if (Object.hasOwn(dataJSON, 'error')) {
|
|
106
|
+
this.reportError(new Error(dataJSON.error));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
this.reportMessage(data.toString());
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
this.ws.on('error', (error) => {
|
|
113
|
+
this.reportError(error);
|
|
114
|
+
});
|
|
115
|
+
this.ws.on('close', () => {
|
|
116
|
+
this.wsConnected = false;
|
|
117
|
+
this.reportClose();
|
|
148
118
|
});
|
|
149
119
|
}
|
|
150
120
|
sendMessage(msgJson) {
|
|
@@ -152,13 +122,13 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
152
122
|
try {
|
|
153
123
|
this.sendMessages[this.callId] = { resolve, reject };
|
|
154
124
|
msgJson['call_id'] = this.callId++;
|
|
155
|
-
if (this.
|
|
125
|
+
if (!this.wsConnected) {
|
|
156
126
|
throw new Error('No CamOverlay connection');
|
|
157
127
|
}
|
|
158
128
|
this.ws.send(JSON.stringify(msgJson));
|
|
159
129
|
}
|
|
160
130
|
catch (err) {
|
|
161
|
-
const errorMessage =
|
|
131
|
+
const errorMessage = err instanceof Error ? err.message : err;
|
|
162
132
|
this.reportError(new Error(`Send message error: ${errorMessage}`));
|
|
163
133
|
}
|
|
164
134
|
});
|
|
@@ -174,13 +144,13 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
174
144
|
headerView.setInt8(0, 1);
|
|
175
145
|
headerView.setInt32(1, jsonBuffer.byteLength);
|
|
176
146
|
const msgBuffer = Buffer.concat([Buffer.from(header), jsonBuffer, data]);
|
|
177
|
-
if (this.
|
|
147
|
+
if (!this.wsConnected) {
|
|
178
148
|
throw new Error('No CamOverlay connection');
|
|
179
149
|
}
|
|
180
150
|
this.ws.send(msgBuffer);
|
|
181
151
|
}
|
|
182
152
|
catch (err) {
|
|
183
|
-
const errorMessage =
|
|
153
|
+
const errorMessage = err instanceof Error ? err.message : err;
|
|
184
154
|
this.reportError(new Error(`Send binary message error: ${errorMessage}`));
|
|
185
155
|
}
|
|
186
156
|
});
|
|
@@ -189,9 +159,6 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
189
159
|
this.emit('message', msg);
|
|
190
160
|
}
|
|
191
161
|
reportError(err) {
|
|
192
|
-
if (this.ws !== undefined) {
|
|
193
|
-
this.ws.close();
|
|
194
|
-
}
|
|
195
162
|
this.emit('error', err);
|
|
196
163
|
}
|
|
197
164
|
reportClose() {
|
|
@@ -18,8 +18,9 @@ export default class Painter extends Frame {
|
|
|
18
18
|
get camOverlayDrawingAPI(): CamOverlayDrawingAPI;
|
|
19
19
|
get resourceManager(): ResourceManager;
|
|
20
20
|
constructor(opt: PainterOptions, coopt: CamOverlayDrawingOptions);
|
|
21
|
-
connect():
|
|
21
|
+
connect(): void;
|
|
22
22
|
disconnect(): void;
|
|
23
|
+
isConnected(): boolean;
|
|
23
24
|
registerImage(moniker: string, fileName: string): void;
|
|
24
25
|
registerFont(moniker: string, fileName: string): void;
|
|
25
26
|
setScreenSize(sw: number, sh: number): void;
|
|
@@ -42,16 +42,20 @@ class Painter extends Frame_1.Frame {
|
|
|
42
42
|
this.rm = new ResourceManager_1.default(this.cod);
|
|
43
43
|
}
|
|
44
44
|
connect() {
|
|
45
|
-
|
|
46
|
-
this.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
this.cod.on('open', () => {
|
|
46
|
+
this.rm.clear();
|
|
47
|
+
});
|
|
48
|
+
this.cod.on('error', (err) => {
|
|
49
|
+
console.error('Painter:', err);
|
|
50
50
|
});
|
|
51
|
+
this.cod.connect();
|
|
51
52
|
}
|
|
52
53
|
disconnect() {
|
|
53
54
|
this.cod.disconnect();
|
|
54
55
|
}
|
|
56
|
+
isConnected() {
|
|
57
|
+
return this.cod.isConnected();
|
|
58
|
+
}
|
|
55
59
|
registerImage(moniker, fileName) {
|
|
56
60
|
this.rm.registerImage(moniker, fileName);
|
|
57
61
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as EventEmitter from 'events';
|
|
3
|
-
import {
|
|
4
|
-
export type CamScripterOptions =
|
|
3
|
+
import { WsOptions } from './internal/common';
|
|
4
|
+
export type CamScripterOptions = WsOptions & {
|
|
5
|
+
camScripterAcapName?: string;
|
|
6
|
+
};
|
|
5
7
|
export type TDeclaration = {
|
|
6
8
|
type?: '' | 'SOURCE' | 'DATA';
|
|
7
9
|
namespace: string;
|
|
@@ -40,16 +42,19 @@ export declare class CamScripterAPICameraEventsGenerator extends EventEmitter {
|
|
|
40
42
|
private port;
|
|
41
43
|
private user;
|
|
42
44
|
private pass;
|
|
45
|
+
private camScripterAcapName;
|
|
43
46
|
private callId;
|
|
44
47
|
private sendMessages;
|
|
45
|
-
private
|
|
48
|
+
private wsConnected;
|
|
49
|
+
private ws;
|
|
46
50
|
constructor(options?: CamScripterOptions);
|
|
47
|
-
connect():
|
|
51
|
+
connect(): void;
|
|
52
|
+
disconnect(): void;
|
|
48
53
|
declareEvent(eventDeclaration: TEventDeclaration): Promise<TResponse>;
|
|
49
54
|
undeclareEvent(eventUndeclaration: TEventUndeclaration): Promise<TResponse>;
|
|
50
55
|
sendEvent(event: TEvent): Promise<TResponse>;
|
|
56
|
+
private createWsClient;
|
|
51
57
|
private sendMessage;
|
|
52
|
-
private openWebsocket;
|
|
53
58
|
private reportErr;
|
|
54
59
|
private reportClose;
|
|
55
60
|
}
|
|
@@ -1,20 +1,11 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.CamScripterAPICameraEventsGenerator = void 0;
|
|
13
4
|
const EventEmitter = require("events");
|
|
14
5
|
const WsClient_1 = require("./internal/WsClient");
|
|
15
6
|
class CamScripterAPICameraEventsGenerator extends EventEmitter {
|
|
16
7
|
constructor(options) {
|
|
17
|
-
var _a, _b, _c, _d, _e, _f;
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
18
9
|
super();
|
|
19
10
|
this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
|
|
20
11
|
this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
|
|
@@ -22,20 +13,18 @@ class CamScripterAPICameraEventsGenerator extends EventEmitter {
|
|
|
22
13
|
this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
|
|
23
14
|
this.user = (_e = options === null || options === void 0 ? void 0 : options.user) !== null && _e !== void 0 ? _e : '';
|
|
24
15
|
this.pass = (_f = options === null || options === void 0 ? void 0 : options.pass) !== null && _f !== void 0 ? _f : '';
|
|
16
|
+
this.camScripterAcapName = (_g = options === null || options === void 0 ? void 0 : options.camScripterAcapName) !== null && _g !== void 0 ? _g : 'camscripter';
|
|
25
17
|
this.callId = 0;
|
|
26
18
|
this.sendMessages = {};
|
|
19
|
+
this.wsConnected = false;
|
|
20
|
+
this.createWsClient();
|
|
27
21
|
EventEmitter.call(this);
|
|
28
22
|
}
|
|
29
23
|
connect() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
this.reportErr(err);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
24
|
+
this.ws.open();
|
|
25
|
+
}
|
|
26
|
+
disconnect() {
|
|
27
|
+
this.ws.close();
|
|
39
28
|
}
|
|
40
29
|
declareEvent(eventDeclaration) {
|
|
41
30
|
return this.sendMessage({
|
|
@@ -58,9 +47,48 @@ class CamScripterAPICameraEventsGenerator extends EventEmitter {
|
|
|
58
47
|
data: event,
|
|
59
48
|
});
|
|
60
49
|
}
|
|
50
|
+
createWsClient() {
|
|
51
|
+
const options = {
|
|
52
|
+
user: this.user,
|
|
53
|
+
pass: this.pass,
|
|
54
|
+
tlsInsecure: this.tlsInsecure,
|
|
55
|
+
tls: this.tls,
|
|
56
|
+
ip: this.ip,
|
|
57
|
+
port: this.port,
|
|
58
|
+
address: `/local/${this.camScripterAcapName}/ws`,
|
|
59
|
+
protocol: 'camera-events',
|
|
60
|
+
};
|
|
61
|
+
this.ws = new WsClient_1.WsClient(options);
|
|
62
|
+
this.ws.on('open', () => {
|
|
63
|
+
this.wsConnected = true;
|
|
64
|
+
this.emit('open');
|
|
65
|
+
});
|
|
66
|
+
this.ws.on('message', (data) => {
|
|
67
|
+
const dataJSON = JSON.parse(data.toString());
|
|
68
|
+
if (Object.hasOwn(dataJSON, 'call_id') && dataJSON['call_id'] in this.sendMessages) {
|
|
69
|
+
if (Object.hasOwn(dataJSON, 'error')) {
|
|
70
|
+
this.sendMessages[dataJSON['call_id']].reject(new Error(dataJSON.error));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.sendMessages[dataJSON['call_id']].resolve(dataJSON);
|
|
74
|
+
}
|
|
75
|
+
delete this.sendMessages[dataJSON['call_id']];
|
|
76
|
+
}
|
|
77
|
+
if (Object.hasOwn(dataJSON, 'error')) {
|
|
78
|
+
this.reportErr(new Error(dataJSON.error));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
this.ws.on('error', (error) => {
|
|
82
|
+
this.reportErr(error);
|
|
83
|
+
});
|
|
84
|
+
this.ws.on('close', () => {
|
|
85
|
+
this.wsConnected = false;
|
|
86
|
+
this.reportClose();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
61
89
|
sendMessage(msgJson) {
|
|
62
90
|
return new Promise((resolve, reject) => {
|
|
63
|
-
if (this.
|
|
91
|
+
if (!this.wsConnected) {
|
|
64
92
|
throw new Error("Websocket hasn't been opened yet.");
|
|
65
93
|
}
|
|
66
94
|
try {
|
|
@@ -73,50 +101,7 @@ class CamScripterAPICameraEventsGenerator extends EventEmitter {
|
|
|
73
101
|
}
|
|
74
102
|
});
|
|
75
103
|
}
|
|
76
|
-
openWebsocket() {
|
|
77
|
-
return new Promise((resolve, reject) => {
|
|
78
|
-
const options = {
|
|
79
|
-
user: this.user,
|
|
80
|
-
pass: this.pass,
|
|
81
|
-
tlsInsecure: this.tlsInsecure,
|
|
82
|
-
tls: this.tls,
|
|
83
|
-
ip: this.ip,
|
|
84
|
-
port: this.port,
|
|
85
|
-
address: '/local/camscripter/ws',
|
|
86
|
-
protocol: 'camera-events',
|
|
87
|
-
};
|
|
88
|
-
this.ws = new WsClient_1.WsClient(options);
|
|
89
|
-
this.ws.on('open', () => {
|
|
90
|
-
resolve();
|
|
91
|
-
});
|
|
92
|
-
this.ws.on('message', (data) => {
|
|
93
|
-
const dataJSON = JSON.parse(data.toString());
|
|
94
|
-
if (Object.hasOwn(dataJSON, 'call_id') && dataJSON['call_id'] in this.sendMessages) {
|
|
95
|
-
if (Object.hasOwn(dataJSON, 'error')) {
|
|
96
|
-
this.sendMessages[dataJSON['call_id']].reject(new Error(dataJSON.error));
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.sendMessages[dataJSON['call_id']].resolve(dataJSON);
|
|
100
|
-
}
|
|
101
|
-
delete this.sendMessages[dataJSON['call_id']];
|
|
102
|
-
}
|
|
103
|
-
if (Object.hasOwn(dataJSON, 'error')) {
|
|
104
|
-
this.reportErr(new Error(dataJSON.error));
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
this.ws.on('error', (error) => {
|
|
108
|
-
this.reportErr(error);
|
|
109
|
-
reject(error);
|
|
110
|
-
});
|
|
111
|
-
this.ws.on('close', () => {
|
|
112
|
-
this.reportClose();
|
|
113
|
-
});
|
|
114
|
-
this.ws.open();
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
104
|
reportErr(err) {
|
|
118
|
-
var _a;
|
|
119
|
-
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.close();
|
|
120
105
|
this.emit('error', err);
|
|
121
106
|
}
|
|
122
107
|
reportClose() {
|
package/CamStreamerAPI.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type CamStreamerAPIOptions =
|
|
1
|
+
import { IClient, HttpOptions } from './internal/common';
|
|
2
|
+
export type CamStreamerAPIOptions = HttpOptions;
|
|
3
3
|
export type TStreamAttributes = {
|
|
4
4
|
enabled: string;
|
|
5
5
|
active: string;
|
package/CamSwitcherAPI.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as EventEmitter from 'events';
|
|
3
|
-
import {
|
|
4
|
-
export type CamSwitcherAPIOptions =
|
|
3
|
+
import { HttpOptions, IClient } from './internal/common';
|
|
4
|
+
export type CamSwitcherAPIOptions = HttpOptions;
|
|
5
5
|
export type TStreamInfo = {
|
|
6
6
|
id: string;
|
|
7
7
|
isTimeoutCustom: boolean;
|
package/CamSwitcherEvents.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as EventEmitter from 'events';
|
|
3
|
-
import {
|
|
4
|
-
export type CamSwitcherEventsOptions =
|
|
3
|
+
import { HttpOptions } from './internal/common';
|
|
4
|
+
export type CamSwitcherEventsOptions = HttpOptions;
|
|
5
5
|
export declare class CamSwitcherEvents extends EventEmitter {
|
|
6
|
-
private ws?;
|
|
7
|
-
private client;
|
|
8
6
|
private tls;
|
|
9
7
|
private tlsInsecure;
|
|
10
8
|
private ip;
|
|
11
9
|
private port;
|
|
12
10
|
private user;
|
|
13
11
|
private pass;
|
|
12
|
+
private client;
|
|
13
|
+
private ws;
|
|
14
14
|
constructor(options?: CamSwitcherEventsOptions);
|
|
15
|
-
connect():
|
|
15
|
+
connect(): void;
|
|
16
|
+
disconnect(): void;
|
|
17
|
+
private createWsClient;
|
|
16
18
|
private get;
|
|
17
19
|
}
|
package/CamSwitcherEvents.js
CHANGED
|
@@ -24,48 +24,54 @@ class CamSwitcherEvents extends EventEmitter {
|
|
|
24
24
|
this.user = (_e = options.user) !== null && _e !== void 0 ? _e : 'root';
|
|
25
25
|
this.pass = (_f = options.pass) !== null && _f !== void 0 ? _f : '';
|
|
26
26
|
this.client = new DefaultAgent_1.DefaultAgent(options);
|
|
27
|
+
this.createWsClient();
|
|
27
28
|
EventEmitter.call(this);
|
|
28
29
|
}
|
|
29
30
|
connect() {
|
|
30
|
-
|
|
31
|
+
this.ws.open();
|
|
32
|
+
}
|
|
33
|
+
disconnect() {
|
|
34
|
+
this.ws.close();
|
|
35
|
+
}
|
|
36
|
+
createWsClient() {
|
|
37
|
+
const options = {
|
|
38
|
+
ip: this.ip,
|
|
39
|
+
port: this.port,
|
|
40
|
+
user: this.user,
|
|
41
|
+
pass: this.pass,
|
|
42
|
+
tls: this.tls,
|
|
43
|
+
tlsInsecure: this.tlsInsecure,
|
|
44
|
+
address: '/local/camswitcher/events',
|
|
45
|
+
protocol: 'events',
|
|
46
|
+
};
|
|
47
|
+
this.ws = new WsClient_1.WsClient(options);
|
|
48
|
+
this.ws.on('open', () => __awaiter(this, void 0, void 0, function* () {
|
|
31
49
|
try {
|
|
32
50
|
const token = yield this.get('/local/camswitcher/ws_authorization.cgi');
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
tlsInsecure: this.tlsInsecure,
|
|
40
|
-
address: '/local/camswitcher/events',
|
|
41
|
-
protocol: 'events',
|
|
42
|
-
};
|
|
43
|
-
this.ws = new WsClient_1.WsClient(options);
|
|
44
|
-
this.ws.on('open', () => {
|
|
45
|
-
var _a;
|
|
46
|
-
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({ authorization: token }));
|
|
47
|
-
});
|
|
48
|
-
this.ws.on('message', (data) => {
|
|
49
|
-
try {
|
|
50
|
-
const parsedData = JSON.parse(data.toString());
|
|
51
|
-
this.emit('event', parsedData);
|
|
52
|
-
}
|
|
53
|
-
catch (err) {
|
|
54
|
-
console.log(err);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
this.ws.on('close', () => {
|
|
58
|
-
this.emit('event_connection_close');
|
|
59
|
-
});
|
|
60
|
-
this.ws.on('error', (err) => {
|
|
61
|
-
this.emit('event_connection_error', err);
|
|
62
|
-
});
|
|
51
|
+
this.ws.send(JSON.stringify({ authorization: token }));
|
|
52
|
+
this.emit('open');
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
this.emit('error', err);
|
|
56
|
+
this.ws.close();
|
|
63
57
|
this.ws.open();
|
|
64
58
|
}
|
|
59
|
+
}));
|
|
60
|
+
this.ws.on('message', (data) => {
|
|
61
|
+
try {
|
|
62
|
+
const parsedData = JSON.parse(data.toString());
|
|
63
|
+
this.emit('event', parsedData);
|
|
64
|
+
}
|
|
65
65
|
catch (err) {
|
|
66
|
-
|
|
66
|
+
console.error(err);
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
|
+
this.ws.on('error', (err) => {
|
|
70
|
+
this.emit('error', err);
|
|
71
|
+
});
|
|
72
|
+
this.ws.on('close', () => {
|
|
73
|
+
this.emit('close');
|
|
74
|
+
});
|
|
69
75
|
}
|
|
70
76
|
get(path) {
|
|
71
77
|
return __awaiter(this, void 0, void 0, function* () {
|
package/CameraVapix.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { WritableStream } from 'node:stream/web';
|
|
4
4
|
import { EventEmitter2 as EventEmitter } from 'eventemitter2';
|
|
5
|
-
import {
|
|
6
|
-
export type CameraVapixOptions =
|
|
5
|
+
import { HttpOptions, IClient } from './internal/common';
|
|
6
|
+
export type CameraVapixOptions = HttpOptions;
|
|
7
7
|
export type TApplicationList = {
|
|
8
8
|
reply: {
|
|
9
9
|
$: {
|
package/CameraVapix.js
CHANGED
|
@@ -40,12 +40,12 @@ class CameraVapix extends eventemitter2_1.EventEmitter2 {
|
|
|
40
40
|
const response = yield (yield this.vapixGet(`/axis-cgi/param.cgi?action=list&group=${encodeURIComponent(groupNames)}`)).text();
|
|
41
41
|
const params = {};
|
|
42
42
|
const lines = response.split(/[\r\n]/);
|
|
43
|
-
for (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
for (const line of lines) {
|
|
44
|
+
const delimiterPos = line.indexOf('=');
|
|
45
|
+
if (delimiterPos !== -1) {
|
|
46
|
+
const key = line.substring(0, delimiterPos);
|
|
47
|
+
const value = line.substring(delimiterPos + 1);
|
|
48
|
+
params[key] = value;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
return params;
|
|
@@ -65,10 +65,11 @@ class CameraVapix extends eventemitter2_1.EventEmitter2 {
|
|
|
65
65
|
const positions = [];
|
|
66
66
|
const lines = response.split(/[\r\n]/);
|
|
67
67
|
for (const line of lines) {
|
|
68
|
-
if (line.
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
|
|
68
|
+
if (line.indexOf('presetposno') !== -1) {
|
|
69
|
+
const delimiterPos = line.indexOf('=');
|
|
70
|
+
if (delimiterPos !== -1) {
|
|
71
|
+
const value = line.substring(delimiterPos + 1);
|
|
72
|
+
positions.push(value);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
}
|