camstreamerlib 3.0.0 → 3.2.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 +5 -10
- package/CamOverlayAPI.js +16 -32
- package/CamOverlayDrawingAPI.d.ts +9 -6
- package/CamOverlayDrawingAPI.js +49 -78
- package/CamOverlayPainter/Frame.js +2 -2
- package/CamOverlayPainter/Painter.d.ts +2 -1
- package/CamOverlayPainter/Painter.js +11 -7
- package/CamScripterAPICameraEventsGenerator.d.ts +11 -5
- package/CamScripterAPICameraEventsGenerator.js +48 -63
- package/CamStreamerAPI.d.ts +32 -14
- package/CamStreamerAPI.js +12 -25
- package/CamSwitcherAPI.d.ts +49 -21
- package/CamSwitcherAPI.js +23 -76
- package/CamSwitcherEvents.d.ts +19 -0
- package/CamSwitcherEvents.js +94 -0
- package/CameraVapix.d.ts +6 -14
- package/CameraVapix.js +24 -107
- package/CreatePackage.js +12 -5
- package/DefaultAgent.d.ts +15 -0
- package/DefaultAgent.js +67 -0
- package/HttpServer.d.ts +2 -0
- package/README.md +11 -1
- package/VapixEvents.d.ts +17 -0
- package/VapixEvents.js +82 -0
- package/events/AxisCameraStationEvents.d.ts +8 -0
- package/events/AxisCameraStationEvents.js +65 -0
- package/internal/HttpRequestSender.d.ts +28 -0
- package/internal/HttpRequestSender.js +114 -0
- package/internal/WsClient.d.ts +7 -4
- package/internal/WsClient.js +63 -30
- package/internal/common.d.ts +16 -1
- package/internal/common.js +9 -0
- package/package.json +4 -3
- package/internal/HttpRequest.d.ts +0 -13
- package/internal/HttpRequest.js +0 -65
package/CamStreamerAPI.js
CHANGED
|
@@ -10,16 +10,16 @@ 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 common_1 = require("./internal/common");
|
|
14
|
+
const DefaultAgent_1 = require("./DefaultAgent");
|
|
14
15
|
class CamStreamerAPI {
|
|
15
|
-
constructor(options) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.pass = (_f = options === null || options === void 0 ? void 0 : options.pass) !== null && _f !== void 0 ? _f : '';
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
if ((0, common_1.isClient)(options)) {
|
|
18
|
+
this.client = options;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
this.client = new DefaultAgent_1.DefaultAgent(options);
|
|
22
|
+
}
|
|
23
23
|
}
|
|
24
24
|
getStreamList() {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -35,19 +35,18 @@ class CamStreamerAPI {
|
|
|
35
35
|
}
|
|
36
36
|
setStreamParameter(streamID, paramName, value) {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
|
|
38
|
+
yield this.get(`/local/camstreamer/stream/set.cgi?stream_id=${streamID}&${paramName}=${value}`);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
isStreaming(streamID) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
43
|
const response = yield this.get(`/local/camstreamer/get_streamstat.cgi?stream_id=${streamID}`);
|
|
44
|
-
return response.data.is_streaming;
|
|
44
|
+
return response.data.is_streaming === 1;
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
get(path) {
|
|
48
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
const
|
|
50
|
-
const res = yield (0, HttpRequest_1.sendRequest)(options);
|
|
49
|
+
const res = yield this.client.get(path);
|
|
51
50
|
if (res.ok) {
|
|
52
51
|
return yield res.json();
|
|
53
52
|
}
|
|
@@ -56,17 +55,5 @@ class CamStreamerAPI {
|
|
|
56
55
|
}
|
|
57
56
|
});
|
|
58
57
|
}
|
|
59
|
-
getBaseConnectionParams(path, method = 'GET') {
|
|
60
|
-
return {
|
|
61
|
-
method: method,
|
|
62
|
-
protocol: this.tls ? 'https:' : 'http:',
|
|
63
|
-
host: this.ip,
|
|
64
|
-
port: this.port,
|
|
65
|
-
path: path,
|
|
66
|
-
user: this.user,
|
|
67
|
-
pass: this.pass,
|
|
68
|
-
rejectUnauthorized: !this.tlsInsecure,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
58
|
}
|
|
72
59
|
exports.CamStreamerAPI = CamStreamerAPI;
|
package/CamSwitcherAPI.d.ts
CHANGED
|
@@ -1,24 +1,52 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import * as EventEmitter from 'events';
|
|
2
|
-
import {
|
|
3
|
-
export type CamSwitcherAPIOptions =
|
|
3
|
+
import { HttpOptions, IClient } from './internal/common';
|
|
4
|
+
export type CamSwitcherAPIOptions = HttpOptions;
|
|
5
|
+
export type TStreamInfo = {
|
|
6
|
+
id: string;
|
|
7
|
+
isTimeoutCustom: boolean;
|
|
8
|
+
ptz_preset_pos_name: string;
|
|
9
|
+
repeat: number;
|
|
10
|
+
timeout: number;
|
|
11
|
+
video: Record<string, string>;
|
|
12
|
+
audio: Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
export type TPlaylistInfo = {
|
|
15
|
+
channel: string;
|
|
16
|
+
isFavourite: false;
|
|
17
|
+
keyboard: object;
|
|
18
|
+
loop: boolean;
|
|
19
|
+
niceName: string;
|
|
20
|
+
sortIndexFavourite: number;
|
|
21
|
+
sortIndexOverview: number;
|
|
22
|
+
stream_list: TStreamInfo[];
|
|
23
|
+
};
|
|
24
|
+
export type TClipInfo = {
|
|
25
|
+
niceName: string;
|
|
26
|
+
channel: string;
|
|
27
|
+
keyboard: object;
|
|
28
|
+
sortIndexOverview: number;
|
|
29
|
+
};
|
|
30
|
+
export type TPlaylistList = Record<string, TPlaylistInfo>;
|
|
31
|
+
export type TClipList = Record<string, TClipInfo>;
|
|
32
|
+
export type TPlaylistQueue = {
|
|
33
|
+
playlist_queue_list: string[];
|
|
34
|
+
};
|
|
35
|
+
export type TOutputInfo = {
|
|
36
|
+
rtsp_url: string;
|
|
37
|
+
ws: string;
|
|
38
|
+
ws_initial_message: string;
|
|
39
|
+
};
|
|
4
40
|
export declare class CamSwitcherAPI extends EventEmitter {
|
|
5
|
-
private
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
playlistSwitch(playlistName: string): Promise<object>;
|
|
17
|
-
playlistQueueList(): Promise<object>;
|
|
18
|
-
playlistQueueClear(): Promise<object>;
|
|
19
|
-
playlistQueuePush(playlistName: string): Promise<object>;
|
|
20
|
-
playlistQueuePlayNext(): Promise<object>;
|
|
21
|
-
getOutputInfo(): Promise<object>;
|
|
22
|
-
get(path: string): Promise<object>;
|
|
23
|
-
private getBaseConnectionParams;
|
|
41
|
+
private client;
|
|
42
|
+
constructor(options?: CamSwitcherAPIOptions | IClient);
|
|
43
|
+
getPlaylistList(): Promise<TPlaylistList>;
|
|
44
|
+
getClipList(): Promise<TClipList>;
|
|
45
|
+
playlistSwitch(playlistName: string): Promise<void>;
|
|
46
|
+
playlistQueueList(): Promise<TPlaylistQueue>;
|
|
47
|
+
playlistQueueClear(): Promise<void>;
|
|
48
|
+
playlistQueuePush(playlistName: string): Promise<void>;
|
|
49
|
+
playlistQueuePlayNext(): Promise<void>;
|
|
50
|
+
getOutputInfo(): Promise<TOutputInfo>;
|
|
51
|
+
get(path: string): Promise<any>;
|
|
24
52
|
}
|
package/CamSwitcherAPI.js
CHANGED
|
@@ -11,61 +11,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CamSwitcherAPI = void 0;
|
|
13
13
|
const EventEmitter = require("events");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const DefaultAgent_1 = require("./DefaultAgent");
|
|
15
|
+
const common_1 = require("./internal/common");
|
|
16
16
|
class CamSwitcherAPI extends EventEmitter {
|
|
17
|
-
constructor(options) {
|
|
18
|
-
var _a, _b, _c, _d, _e, _f;
|
|
17
|
+
constructor(options = {}) {
|
|
19
18
|
super();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
if ((0, common_1.isClient)(options)) {
|
|
20
|
+
this.client = options;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.client = new DefaultAgent_1.DefaultAgent(options);
|
|
24
|
+
}
|
|
26
25
|
EventEmitter.call(this);
|
|
27
26
|
}
|
|
28
|
-
connect() {
|
|
29
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
try {
|
|
31
|
-
const token = yield this.get('/local/camswitcher/ws_authorization.cgi');
|
|
32
|
-
const options = {
|
|
33
|
-
ip: this.ip,
|
|
34
|
-
port: this.port,
|
|
35
|
-
user: this.user,
|
|
36
|
-
pass: this.pass,
|
|
37
|
-
tls: this.tls,
|
|
38
|
-
tlsInsecure: this.tlsInsecure,
|
|
39
|
-
address: '/local/camswitcher/events',
|
|
40
|
-
protocol: 'events',
|
|
41
|
-
};
|
|
42
|
-
this.ws = new WsClient_1.WsClient(options);
|
|
43
|
-
this.ws.on('open', () => {
|
|
44
|
-
var _a;
|
|
45
|
-
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({ authorization: token }));
|
|
46
|
-
});
|
|
47
|
-
this.ws.on('message', (data) => {
|
|
48
|
-
try {
|
|
49
|
-
const parsedData = JSON.parse(data.toString());
|
|
50
|
-
this.emit('event', parsedData);
|
|
51
|
-
}
|
|
52
|
-
catch (err) {
|
|
53
|
-
console.log(err);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
this.ws.on('close', () => {
|
|
57
|
-
this.emit('event_connection_close');
|
|
58
|
-
});
|
|
59
|
-
this.ws.on('error', (err) => {
|
|
60
|
-
this.emit('event_connection_error', err);
|
|
61
|
-
});
|
|
62
|
-
this.ws.open();
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
this.emit('event_connection_error', err);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
27
|
getPlaylistList() {
|
|
70
28
|
return this.get('/local/camswitcher/playlists.cgi?action=get');
|
|
71
29
|
}
|
|
@@ -73,52 +31,41 @@ class CamSwitcherAPI extends EventEmitter {
|
|
|
73
31
|
return this.get('/local/camswitcher/clips.cgi?action=get');
|
|
74
32
|
}
|
|
75
33
|
playlistSwitch(playlistName) {
|
|
76
|
-
return this
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
yield this.get(`/local/camswitcher/playlist_switch.cgi?playlist_name=${playlistName}`);
|
|
36
|
+
});
|
|
77
37
|
}
|
|
78
38
|
playlistQueueList() {
|
|
79
39
|
return this.get('/local/camswitcher/playlist_queue_list.cgi');
|
|
80
40
|
}
|
|
81
41
|
playlistQueueClear() {
|
|
82
|
-
return this
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
yield this.get('/local/camswitcher/playlist_queue_clear.cgi');
|
|
44
|
+
});
|
|
83
45
|
}
|
|
84
46
|
playlistQueuePush(playlistName) {
|
|
85
|
-
return this
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
yield this.get(`/local/camswitcher/playlist_queue_push.cgi?playlist_name=${playlistName}`);
|
|
49
|
+
});
|
|
86
50
|
}
|
|
87
51
|
playlistQueuePlayNext() {
|
|
88
|
-
return this
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
yield this.get('/local/camswitcher/playlist_queue_play_next.cgi');
|
|
54
|
+
});
|
|
89
55
|
}
|
|
90
56
|
getOutputInfo() {
|
|
91
57
|
return this.get('/local/camswitcher/output_info.cgi');
|
|
92
58
|
}
|
|
93
59
|
get(path) {
|
|
94
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
const
|
|
96
|
-
const res = yield (0, HttpRequest_1.sendRequest)(options);
|
|
61
|
+
const res = yield this.client.get(path);
|
|
97
62
|
if (res.ok) {
|
|
98
|
-
|
|
99
|
-
if (responseText.status === 200) {
|
|
100
|
-
return responseText.data;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
throw new Error(`Request (${path}) error, response: ${JSON.stringify(responseText)}`);
|
|
104
|
-
}
|
|
63
|
+
return yield res.json();
|
|
105
64
|
}
|
|
106
65
|
else {
|
|
107
66
|
throw new Error(JSON.stringify(res));
|
|
108
67
|
}
|
|
109
68
|
});
|
|
110
69
|
}
|
|
111
|
-
getBaseConnectionParams(path, method = 'GET') {
|
|
112
|
-
return {
|
|
113
|
-
method: method,
|
|
114
|
-
protocol: this.tls ? 'https:' : 'http:',
|
|
115
|
-
host: this.ip,
|
|
116
|
-
port: this.port,
|
|
117
|
-
path: path,
|
|
118
|
-
user: this.user,
|
|
119
|
-
pass: this.pass,
|
|
120
|
-
rejectUnauthorized: !this.tlsInsecure,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
70
|
}
|
|
124
71
|
exports.CamSwitcherAPI = CamSwitcherAPI;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as EventEmitter from 'events';
|
|
3
|
+
import { HttpOptions } from './internal/common';
|
|
4
|
+
export type CamSwitcherEventsOptions = HttpOptions;
|
|
5
|
+
export declare class CamSwitcherEvents extends EventEmitter {
|
|
6
|
+
private tls;
|
|
7
|
+
private tlsInsecure;
|
|
8
|
+
private ip;
|
|
9
|
+
private port;
|
|
10
|
+
private user;
|
|
11
|
+
private pass;
|
|
12
|
+
private client;
|
|
13
|
+
private ws;
|
|
14
|
+
constructor(options?: CamSwitcherEventsOptions);
|
|
15
|
+
connect(): void;
|
|
16
|
+
disconnect(): void;
|
|
17
|
+
private createWsClient;
|
|
18
|
+
private get;
|
|
19
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
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.CamSwitcherEvents = void 0;
|
|
13
|
+
const EventEmitter = require("events");
|
|
14
|
+
const WsClient_1 = require("./internal/WsClient");
|
|
15
|
+
const DefaultAgent_1 = require("./DefaultAgent");
|
|
16
|
+
class CamSwitcherEvents extends EventEmitter {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
var _a, _b, _c, _d, _e, _f;
|
|
19
|
+
super();
|
|
20
|
+
this.tls = (_a = options.tls) !== null && _a !== void 0 ? _a : false;
|
|
21
|
+
this.tlsInsecure = (_b = options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
|
|
22
|
+
this.ip = (_c = options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
|
|
23
|
+
this.port = (_d = options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
|
|
24
|
+
this.user = (_e = options.user) !== null && _e !== void 0 ? _e : 'root';
|
|
25
|
+
this.pass = (_f = options.pass) !== null && _f !== void 0 ? _f : '';
|
|
26
|
+
this.client = new DefaultAgent_1.DefaultAgent(options);
|
|
27
|
+
this.createWsClient();
|
|
28
|
+
EventEmitter.call(this);
|
|
29
|
+
}
|
|
30
|
+
connect() {
|
|
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* () {
|
|
49
|
+
try {
|
|
50
|
+
const token = yield this.get('/local/camswitcher/ws_authorization.cgi');
|
|
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();
|
|
57
|
+
this.ws.open();
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
this.ws.on('message', (data) => {
|
|
61
|
+
try {
|
|
62
|
+
const parsedData = JSON.parse(data.toString());
|
|
63
|
+
this.emit('event', parsedData);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.error(err);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
this.ws.on('error', (err) => {
|
|
70
|
+
this.emit('error', err);
|
|
71
|
+
});
|
|
72
|
+
this.ws.on('close', () => {
|
|
73
|
+
this.emit('close');
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
get(path) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const res = yield this.client.get(path);
|
|
79
|
+
if (res.ok) {
|
|
80
|
+
const responseText = JSON.parse(yield res.text());
|
|
81
|
+
if (responseText.status === 200) {
|
|
82
|
+
return responseText.data;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
throw new Error(`Request (${path}) error, response: ${JSON.stringify(responseText)}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw new Error(JSON.stringify(res));
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.CamSwitcherEvents = CamSwitcherEvents;
|
package/CameraVapix.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
1
3
|
import { WritableStream } from 'node:stream/web';
|
|
2
4
|
import { EventEmitter2 as EventEmitter } from 'eventemitter2';
|
|
3
|
-
import {
|
|
4
|
-
export type CameraVapixOptions =
|
|
5
|
+
import { HttpOptions, IClient } from './internal/common';
|
|
6
|
+
export type CameraVapixOptions = HttpOptions;
|
|
5
7
|
export type TApplicationList = {
|
|
6
8
|
reply: {
|
|
7
9
|
$: {
|
|
@@ -40,14 +42,8 @@ export type TGuardTour = {
|
|
|
40
42
|
}[];
|
|
41
43
|
};
|
|
42
44
|
export declare class CameraVapix extends EventEmitter {
|
|
43
|
-
private
|
|
44
|
-
|
|
45
|
-
private ip;
|
|
46
|
-
private port;
|
|
47
|
-
private user;
|
|
48
|
-
private pass;
|
|
49
|
-
private ws?;
|
|
50
|
-
constructor(options?: CameraVapixOptions);
|
|
45
|
+
private client;
|
|
46
|
+
constructor(options?: CameraVapixOptions | IClient);
|
|
51
47
|
vapixGet(path: string): Promise<Response>;
|
|
52
48
|
vapixPost(path: string, data: string, contentType?: string): Promise<Response>;
|
|
53
49
|
getParameterGroup(groupNames: string): Promise<Record<string, string>>;
|
|
@@ -61,8 +57,4 @@ export declare class CameraVapix extends EventEmitter {
|
|
|
61
57
|
getApplicationList(): Promise<TApplication[]>;
|
|
62
58
|
getCameraImage(camera: string, compression: string, resolution: string, outputStream: WritableStream): Promise<WritableStream<any>>;
|
|
63
59
|
getEventDeclarations(): Promise<string>;
|
|
64
|
-
eventsConnect(): void;
|
|
65
|
-
eventsDisconnect(): void;
|
|
66
|
-
private isReservedEventName;
|
|
67
|
-
private getBaseVapixConnectionParams;
|
|
68
60
|
}
|
package/CameraVapix.js
CHANGED
|
@@ -13,41 +13,39 @@ exports.CameraVapix = void 0;
|
|
|
13
13
|
const prettifyXml = require("prettify-xml");
|
|
14
14
|
const xml2js_1 = require("xml2js");
|
|
15
15
|
const eventemitter2_1 = require("eventemitter2");
|
|
16
|
-
const
|
|
17
|
-
const
|
|
16
|
+
const common_1 = require("./internal/common");
|
|
17
|
+
const DefaultAgent_1 = require("./DefaultAgent");
|
|
18
18
|
class CameraVapix extends eventemitter2_1.EventEmitter2 {
|
|
19
|
-
constructor(options) {
|
|
20
|
-
var _a, _b, _c, _d, _e, _f;
|
|
19
|
+
constructor(options = {}) {
|
|
21
20
|
super();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
if ((0, common_1.isClient)(options)) {
|
|
22
|
+
this.client = options;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.client = new DefaultAgent_1.DefaultAgent(options);
|
|
26
|
+
}
|
|
28
27
|
}
|
|
29
28
|
vapixGet(path) {
|
|
30
|
-
|
|
31
|
-
return (0, HttpRequest_1.sendRequest)(options, undefined);
|
|
29
|
+
return this.client.get(path);
|
|
32
30
|
}
|
|
33
31
|
vapixPost(path, data, contentType) {
|
|
34
|
-
|
|
32
|
+
let headers = {};
|
|
35
33
|
if (contentType !== undefined) {
|
|
36
|
-
|
|
34
|
+
headers = { 'Content-Type': contentType };
|
|
37
35
|
}
|
|
38
|
-
return (
|
|
36
|
+
return this.client.post(path, data, {}, headers);
|
|
39
37
|
}
|
|
40
38
|
getParameterGroup(groupNames) {
|
|
41
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
40
|
const response = yield (yield this.vapixGet(`/axis-cgi/param.cgi?action=list&group=${encodeURIComponent(groupNames)}`)).text();
|
|
43
41
|
const params = {};
|
|
44
42
|
const lines = response.split(/[\r\n]/);
|
|
45
|
-
for (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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;
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
51
|
return params;
|
|
@@ -67,10 +65,11 @@ class CameraVapix extends eventemitter2_1.EventEmitter2 {
|
|
|
67
65
|
const positions = [];
|
|
68
66
|
const lines = response.split(/[\r\n]/);
|
|
69
67
|
for (const line of lines) {
|
|
70
|
-
if (line.
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
|
|
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);
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
}
|
|
@@ -165,87 +164,5 @@ class CameraVapix extends eventemitter2_1.EventEmitter2 {
|
|
|
165
164
|
return prettifyXml(declarations);
|
|
166
165
|
});
|
|
167
166
|
}
|
|
168
|
-
eventsConnect() {
|
|
169
|
-
if (this.ws !== undefined) {
|
|
170
|
-
throw new Error('Websocket is already opened.');
|
|
171
|
-
}
|
|
172
|
-
const options = {
|
|
173
|
-
tls: this.tls,
|
|
174
|
-
tlsInsecure: this.tlsInsecure,
|
|
175
|
-
user: this.user,
|
|
176
|
-
pass: this.pass,
|
|
177
|
-
ip: this.ip,
|
|
178
|
-
port: this.port,
|
|
179
|
-
address: '/vapix/ws-data-stream?sources=events',
|
|
180
|
-
};
|
|
181
|
-
this.ws = new WsClient_1.WsClient(options);
|
|
182
|
-
this.ws.on('open', () => {
|
|
183
|
-
var _a;
|
|
184
|
-
const topics = [];
|
|
185
|
-
const eventNames = this.eventNames();
|
|
186
|
-
for (let i = 0; i < eventNames.length; i++) {
|
|
187
|
-
if (!this.isReservedEventName(eventNames[i])) {
|
|
188
|
-
const topic = {
|
|
189
|
-
topicFilter: eventNames[i],
|
|
190
|
-
};
|
|
191
|
-
topics.push(topic);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
const topicFilter = {
|
|
195
|
-
apiVersion: '1.0',
|
|
196
|
-
method: 'events:configure',
|
|
197
|
-
params: {
|
|
198
|
-
eventFilterList: topics,
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(topicFilter));
|
|
202
|
-
});
|
|
203
|
-
this.ws.on('message', (data) => {
|
|
204
|
-
const dataJSON = JSON.parse(data.toString());
|
|
205
|
-
if (dataJSON.method === 'events:configure') {
|
|
206
|
-
if (dataJSON.error === undefined) {
|
|
207
|
-
this.emit('eventsConnect');
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
this.emit('eventsDisconnect', dataJSON.error);
|
|
211
|
-
this.eventsDisconnect();
|
|
212
|
-
}
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const eventName = dataJSON.params.notification.topic;
|
|
216
|
-
this.emit(eventName, dataJSON);
|
|
217
|
-
});
|
|
218
|
-
this.ws.on('error', (error) => {
|
|
219
|
-
this.emit('eventsDisconnect', error);
|
|
220
|
-
this.ws = undefined;
|
|
221
|
-
});
|
|
222
|
-
this.ws.on('close', () => {
|
|
223
|
-
if (this.ws !== undefined) {
|
|
224
|
-
this.emit('eventsClose');
|
|
225
|
-
}
|
|
226
|
-
this.ws = undefined;
|
|
227
|
-
});
|
|
228
|
-
this.ws.open();
|
|
229
|
-
}
|
|
230
|
-
eventsDisconnect() {
|
|
231
|
-
if (this.ws !== undefined) {
|
|
232
|
-
this.ws.close();
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
isReservedEventName(eventName) {
|
|
236
|
-
return eventName === 'eventsConnect' || eventName === 'eventsDisconnect' || eventName === 'eventsClose';
|
|
237
|
-
}
|
|
238
|
-
getBaseVapixConnectionParams(path, method = 'GET') {
|
|
239
|
-
return {
|
|
240
|
-
method: method,
|
|
241
|
-
protocol: this.tls ? 'https:' : 'http:',
|
|
242
|
-
host: this.ip,
|
|
243
|
-
port: this.port,
|
|
244
|
-
path: path,
|
|
245
|
-
user: this.user,
|
|
246
|
-
pass: this.pass,
|
|
247
|
-
rejectUnauthorized: !this.tlsInsecure,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
167
|
}
|
|
251
168
|
exports.CameraVapix = CameraVapix;
|
package/CreatePackage.js
CHANGED
|
@@ -4,16 +4,19 @@ const AdmZip = require("adm-zip");
|
|
|
4
4
|
const Path = require("path");
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const child_process_1 = require("child_process");
|
|
7
|
+
const productionModulesFolder = 'production_modules';
|
|
7
8
|
function isDirectory(path) {
|
|
8
9
|
const stat = fs.statSync(path);
|
|
9
10
|
return stat.isDirectory();
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
function getPackageVersion(folder) {
|
|
12
|
+
function getPackageInfo(folder) {
|
|
13
13
|
try {
|
|
14
14
|
const manifest = fs.readFileSync(Path.join(folder, 'manifest.json'));
|
|
15
15
|
const manifestParsed = JSON.parse(manifest.toString());
|
|
16
|
-
return
|
|
16
|
+
return {
|
|
17
|
+
packageName: manifestParsed.package_name,
|
|
18
|
+
packageVersion: manifestParsed.package_version.replace(/\./g, '_'),
|
|
19
|
+
};
|
|
17
20
|
}
|
|
18
21
|
catch (err) {
|
|
19
22
|
console.error('Get package version:', err);
|
|
@@ -81,8 +84,12 @@ function main(args) {
|
|
|
81
84
|
options.typeScriptPackage = true;
|
|
82
85
|
}
|
|
83
86
|
const folder = Path.resolve('.');
|
|
84
|
-
const
|
|
85
|
-
|
|
87
|
+
const packageInfo = getPackageInfo(folder);
|
|
88
|
+
if (packageInfo === undefined) {
|
|
89
|
+
console.error('Package info not found');
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
const zipFile = `${options.outputFolder}/${packageInfo.packageName}_${packageInfo.packageVersion}.zip`;
|
|
86
93
|
if (fs.existsSync(zipFile)) {
|
|
87
94
|
try {
|
|
88
95
|
fs.unlinkSync(zipFile);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { IClient, HttpOptions } from './internal/common';
|
|
4
|
+
export declare class DefaultAgent implements IClient {
|
|
5
|
+
private tls;
|
|
6
|
+
private ip;
|
|
7
|
+
private port;
|
|
8
|
+
private user;
|
|
9
|
+
private pass;
|
|
10
|
+
private httpRequestSender;
|
|
11
|
+
constructor(opt?: HttpOptions);
|
|
12
|
+
get(path: string, parameters?: Record<string, string>, headers?: Record<string, string>): Promise<Response>;
|
|
13
|
+
post(path: string, data: string | Buffer | FormData, parameters?: Record<string, string>, headers?: Record<string, string>): Promise<Response>;
|
|
14
|
+
private getBaseConnectionParams;
|
|
15
|
+
}
|