pubo-node 1.0.32 → 1.0.34
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/dist/pubo-node.js +1 -1
- package/es/grpc/Grpc.d.ts +15 -0
- package/es/grpc/Grpc.js +52 -0
- package/es/grpc/GrpcPool.d.ts +14 -0
- package/es/grpc/GrpcPool.js +43 -0
- package/es/grpc/GrpcService.d.ts +13 -0
- package/es/grpc/GrpcService.js +295 -0
- package/es/grpc/index.d.ts +8 -0
- package/es/grpc/index.js +23 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +3 -2
- package/lib/grpc/Grpc.d.ts +15 -0
- package/lib/grpc/Grpc.js +93 -0
- package/lib/grpc/GrpcPool.d.ts +14 -0
- package/lib/grpc/GrpcPool.js +50 -0
- package/lib/grpc/GrpcService.d.ts +13 -0
- package/lib/grpc/GrpcService.js +302 -0
- package/lib/grpc/index.d.ts +8 -0
- package/lib/grpc/index.js +32 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +18 -9
- package/package.json +4 -3
- package/es/rtsp-video/index.d.ts +0 -15
- package/es/rtsp-video/index.js +0 -50
- package/es/rtsp-video/rtsp2mpeg.d.ts +0 -13
- package/es/rtsp-video/rtsp2mpeg.js +0 -125
- package/lib/rtsp-video/index.d.ts +0 -15
- package/lib/rtsp-video/index.js +0 -58
- package/lib/rtsp-video/rtsp2mpeg.d.ts +0 -13
- package/lib/rtsp-video/rtsp2mpeg.js +0 -133
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GrpcPool = void 0;
|
|
7
|
+
|
|
8
|
+
var Grpc_1 = require("./Grpc");
|
|
9
|
+
|
|
10
|
+
var GrpcPool =
|
|
11
|
+
/** @class */
|
|
12
|
+
function () {
|
|
13
|
+
function GrpcPool(list) {
|
|
14
|
+
this.list = [];
|
|
15
|
+
this.list = list.map(function (conf) {
|
|
16
|
+
return {
|
|
17
|
+
id: conf.id,
|
|
18
|
+
grpc: new Grpc_1.Grpc(conf)
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
GrpcPool.prototype.getGrpc = function (id) {
|
|
24
|
+
var _a;
|
|
25
|
+
|
|
26
|
+
return (_a = this.list.find(function (item) {
|
|
27
|
+
return item.id === id;
|
|
28
|
+
})) === null || _a === void 0 ? void 0 : _a.grpc;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
GrpcPool.pool = [];
|
|
32
|
+
GrpcPool.instance = null;
|
|
33
|
+
|
|
34
|
+
GrpcPool.getPool = function () {
|
|
35
|
+
if (!GrpcPool.instance) {
|
|
36
|
+
GrpcPool.instance = new GrpcPool(GrpcPool.pool);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return GrpcPool.instance;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
GrpcPool.setPool = function (pool) {
|
|
43
|
+
GrpcPool.pool = pool;
|
|
44
|
+
GrpcPool.instance = new GrpcPool(GrpcPool.pool);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return GrpcPool;
|
|
48
|
+
}();
|
|
49
|
+
|
|
50
|
+
exports.GrpcPool = GrpcPool;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface GrpcServiceConfig {
|
|
2
|
+
client: string;
|
|
3
|
+
serviceName: string;
|
|
4
|
+
requestType: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class GrpcService {
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly grpc?;
|
|
9
|
+
private readonly promise;
|
|
10
|
+
constructor(conf: GrpcServiceConfig);
|
|
11
|
+
serializer(requestType: string, payload?: any): any;
|
|
12
|
+
send(request?: any): Promise<any>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
6
|
+
resolve(value);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) {
|
|
12
|
+
try {
|
|
13
|
+
step(generator.next(value));
|
|
14
|
+
} catch (e) {
|
|
15
|
+
reject(e);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator["throw"](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function step(result) {
|
|
28
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
36
|
+
var _ = {
|
|
37
|
+
label: 0,
|
|
38
|
+
sent: function sent() {
|
|
39
|
+
if (t[0] & 1) throw t[1];
|
|
40
|
+
return t[1];
|
|
41
|
+
},
|
|
42
|
+
trys: [],
|
|
43
|
+
ops: []
|
|
44
|
+
},
|
|
45
|
+
f,
|
|
46
|
+
y,
|
|
47
|
+
t,
|
|
48
|
+
g;
|
|
49
|
+
return g = {
|
|
50
|
+
next: verb(0),
|
|
51
|
+
"throw": verb(1),
|
|
52
|
+
"return": verb(2)
|
|
53
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
54
|
+
return this;
|
|
55
|
+
}), g;
|
|
56
|
+
|
|
57
|
+
function verb(n) {
|
|
58
|
+
return function (v) {
|
|
59
|
+
return step([n, v]);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function step(op) {
|
|
64
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
65
|
+
|
|
66
|
+
while (_) {
|
|
67
|
+
try {
|
|
68
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
69
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
70
|
+
|
|
71
|
+
switch (op[0]) {
|
|
72
|
+
case 0:
|
|
73
|
+
case 1:
|
|
74
|
+
t = op;
|
|
75
|
+
break;
|
|
76
|
+
|
|
77
|
+
case 4:
|
|
78
|
+
_.label++;
|
|
79
|
+
return {
|
|
80
|
+
value: op[1],
|
|
81
|
+
done: false
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
case 5:
|
|
85
|
+
_.label++;
|
|
86
|
+
y = op[1];
|
|
87
|
+
op = [0];
|
|
88
|
+
continue;
|
|
89
|
+
|
|
90
|
+
case 7:
|
|
91
|
+
op = _.ops.pop();
|
|
92
|
+
|
|
93
|
+
_.trys.pop();
|
|
94
|
+
|
|
95
|
+
continue;
|
|
96
|
+
|
|
97
|
+
default:
|
|
98
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
99
|
+
_ = 0;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
104
|
+
_.label = op[1];
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
109
|
+
_.label = t[1];
|
|
110
|
+
t = op;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (t && _.label < t[2]) {
|
|
115
|
+
_.label = t[2];
|
|
116
|
+
|
|
117
|
+
_.ops.push(op);
|
|
118
|
+
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (t[2]) _.ops.pop();
|
|
123
|
+
|
|
124
|
+
_.trys.pop();
|
|
125
|
+
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
op = body.call(thisArg, _);
|
|
130
|
+
} catch (e) {
|
|
131
|
+
op = [6, e];
|
|
132
|
+
y = 0;
|
|
133
|
+
} finally {
|
|
134
|
+
f = t = 0;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (op[0] & 5) throw op[1];
|
|
139
|
+
return {
|
|
140
|
+
value: op[0] ? op[1] : void 0,
|
|
141
|
+
done: true
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
var __read = this && this.__read || function (o, n) {
|
|
147
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
148
|
+
if (!m) return o;
|
|
149
|
+
var i = m.call(o),
|
|
150
|
+
r,
|
|
151
|
+
ar = [],
|
|
152
|
+
e;
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
156
|
+
ar.push(r.value);
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
e = {
|
|
160
|
+
error: error
|
|
161
|
+
};
|
|
162
|
+
} finally {
|
|
163
|
+
try {
|
|
164
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
165
|
+
} finally {
|
|
166
|
+
if (e) throw e.error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return ar;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
var __spread = this && this.__spread || function () {
|
|
174
|
+
for (var ar = [], i = 0; i < arguments.length; i++) {
|
|
175
|
+
ar = ar.concat(__read(arguments[i]));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return ar;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
var __values = this && this.__values || function (o) {
|
|
182
|
+
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
183
|
+
m = s && o[s],
|
|
184
|
+
i = 0;
|
|
185
|
+
if (m) return m.call(o);
|
|
186
|
+
if (o && typeof o.length === "number") return {
|
|
187
|
+
next: function next() {
|
|
188
|
+
if (o && i >= o.length) o = void 0;
|
|
189
|
+
return {
|
|
190
|
+
value: o && o[i++],
|
|
191
|
+
done: !o
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
Object.defineProperty(exports, "__esModule", {
|
|
199
|
+
value: true
|
|
200
|
+
});
|
|
201
|
+
exports.GrpcService = void 0;
|
|
202
|
+
|
|
203
|
+
var GrpcPool_1 = require("./GrpcPool");
|
|
204
|
+
|
|
205
|
+
function createRpcPromise(fn, grpc) {
|
|
206
|
+
return function () {
|
|
207
|
+
var args = [];
|
|
208
|
+
|
|
209
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
210
|
+
args[_i] = arguments[_i];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return new Promise(function (resolve, reject) {
|
|
214
|
+
var client = grpc.client;
|
|
215
|
+
fn.call.apply(fn, __spread([client], args, [function (err, response) {
|
|
216
|
+
global.proto = grpc.proto;
|
|
217
|
+
|
|
218
|
+
if (err) {
|
|
219
|
+
reject(err);
|
|
220
|
+
} else {
|
|
221
|
+
resolve(response);
|
|
222
|
+
}
|
|
223
|
+
}]));
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
var GrpcService =
|
|
229
|
+
/** @class */
|
|
230
|
+
function () {
|
|
231
|
+
function GrpcService(conf) {
|
|
232
|
+
this.config = conf;
|
|
233
|
+
this.grpc = GrpcPool_1.GrpcPool.getPool().getGrpc(this.config.client);
|
|
234
|
+
|
|
235
|
+
if (!this.grpc || !this.grpc.client[this.config.serviceName]) {
|
|
236
|
+
throw new Error("rpc service not found:" + this.config.serviceName);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
this.promise = createRpcPromise(this.grpc.client[this.config.serviceName], this.grpc);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
GrpcService.prototype.serializer = function (requestType, payload) {
|
|
243
|
+
var e_1, _a;
|
|
244
|
+
|
|
245
|
+
if (payload === void 0) {
|
|
246
|
+
payload = {};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (!this.grpc) {
|
|
250
|
+
throw new Error("rpc client not found:" + this.config.client);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
global.proto = this.grpc.proto;
|
|
254
|
+
var request = new this.grpc.common[requestType]();
|
|
255
|
+
|
|
256
|
+
try {
|
|
257
|
+
for (var _b = __values(Object.keys(request.toObject())), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
258
|
+
var key = _c.value;
|
|
259
|
+
|
|
260
|
+
if (payload[key] !== undefined) {
|
|
261
|
+
request["set" + key[0].toUpperCase() + key.slice(1)](payload[key]);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
} catch (e_1_1) {
|
|
265
|
+
e_1 = {
|
|
266
|
+
error: e_1_1
|
|
267
|
+
};
|
|
268
|
+
} finally {
|
|
269
|
+
try {
|
|
270
|
+
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
|
|
271
|
+
} finally {
|
|
272
|
+
if (e_1) throw e_1.error;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return request;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
GrpcService.prototype.send = function (request) {
|
|
280
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
281
|
+
var res;
|
|
282
|
+
return __generator(this, function (_a) {
|
|
283
|
+
switch (_a.label) {
|
|
284
|
+
case 0:
|
|
285
|
+
return [4
|
|
286
|
+
/*yield*/
|
|
287
|
+
, this.promise(this.serializer(this.config.requestType, request))];
|
|
288
|
+
|
|
289
|
+
case 1:
|
|
290
|
+
res = _a.sent();
|
|
291
|
+
return [2
|
|
292
|
+
/*return*/
|
|
293
|
+
, res.toObject()];
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
return GrpcService;
|
|
300
|
+
}();
|
|
301
|
+
|
|
302
|
+
exports.GrpcService = GrpcService;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GrpcService } from './GrpcService';
|
|
2
|
+
interface GrpcServiceOptions {
|
|
3
|
+
client: string;
|
|
4
|
+
requestType: string;
|
|
5
|
+
service?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const createGrpcService: import("pubo-utils/lib/factory").CreateFactory<GrpcServiceOptions, GrpcService>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __assign = this && this.__assign || function () {
|
|
4
|
+
__assign = Object.assign || function (t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
|
|
8
|
+
for (var p in s) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return __assign.apply(this, arguments);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
Object.defineProperty(exports, "__esModule", {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
exports.createGrpcService = void 0;
|
|
23
|
+
|
|
24
|
+
var pubo_utils_1 = require("pubo-utils");
|
|
25
|
+
|
|
26
|
+
var GrpcService_1 = require("./GrpcService");
|
|
27
|
+
|
|
28
|
+
exports.createGrpcService = pubo_utils_1.superFactory(function (config, key) {
|
|
29
|
+
return new GrpcService_1.GrpcService(__assign(__assign({}, config), {
|
|
30
|
+
serviceName: config.service || key
|
|
31
|
+
}));
|
|
32
|
+
});
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -13,15 +13,6 @@ Object.defineProperty(exports, "JsonStorage", {
|
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
var rtsp_video_1 = require("./rtsp-video");
|
|
17
|
-
|
|
18
|
-
Object.defineProperty(exports, "initRtspVideos", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function get() {
|
|
21
|
-
return rtsp_video_1.initRtspVideos;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
16
|
var ftp_client_1 = require("./ftp-client");
|
|
26
17
|
|
|
27
18
|
Object.defineProperty(exports, "FtpClient", {
|
|
@@ -38,4 +29,22 @@ Object.defineProperty(exports, "md5", {
|
|
|
38
29
|
get: function get() {
|
|
39
30
|
return md5_1.md5;
|
|
40
31
|
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
var grpc_1 = require("./grpc");
|
|
35
|
+
|
|
36
|
+
Object.defineProperty(exports, "createGrpcService", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function get() {
|
|
39
|
+
return grpc_1.createGrpcService;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
var GrpcPool_1 = require("./grpc/GrpcPool");
|
|
44
|
+
|
|
45
|
+
Object.defineProperty(exports, "GrpcPool", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function get() {
|
|
48
|
+
return GrpcPool_1.GrpcPool;
|
|
49
|
+
}
|
|
41
50
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@types/node": "^17.0.25",
|
|
23
|
+
"grpc": "^1.24.11",
|
|
23
24
|
"pako": "^2.0.4",
|
|
24
|
-
"pubo-utils": "^1.0.
|
|
25
|
+
"pubo-utils": "^1.0.34"
|
|
25
26
|
},
|
|
26
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "c5218221058a304c692c4e9e789e7b8f8a2c7bce"
|
|
27
28
|
}
|
package/es/rtsp-video/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { RTSP2Mpeg } from './rtsp2mpeg';
|
|
2
|
-
interface VideoConfig {
|
|
3
|
-
url: string;
|
|
4
|
-
input?: string[];
|
|
5
|
-
output?: string[];
|
|
6
|
-
}
|
|
7
|
-
interface Props {
|
|
8
|
-
app: any;
|
|
9
|
-
server?: any;
|
|
10
|
-
videos: VideoConfig[];
|
|
11
|
-
path: string;
|
|
12
|
-
expressWs?: any;
|
|
13
|
-
}
|
|
14
|
-
export declare const initRtspVideos: ({ app, server, videos, path, expressWs }: Props) => RTSP2Mpeg[];
|
|
15
|
-
export {};
|
package/es/rtsp-video/index.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
var __rest = this && this.__rest || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
|
|
4
|
-
for (var p in s) {
|
|
5
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
9
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
import { RTSP2Mpeg } from './rtsp2mpeg';
|
|
15
|
-
export var initRtspVideos = function initRtspVideos(_a) {
|
|
16
|
-
var app = _a.app,
|
|
17
|
-
server = _a.server,
|
|
18
|
-
videos = _a.videos,
|
|
19
|
-
path = _a.path,
|
|
20
|
-
expressWs = _a.expressWs;
|
|
21
|
-
var mpegList = videos.map(function (_a) {
|
|
22
|
-
var url = _a.url,
|
|
23
|
-
options = __rest(_a, ["url"]);
|
|
24
|
-
|
|
25
|
-
return new RTSP2Mpeg(url, options);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (!app.ws) {
|
|
29
|
-
expressWs(app, server);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
app.ws(path, function (ws, req) {
|
|
33
|
-
var _a = req.query.channel,
|
|
34
|
-
channel = _a === void 0 ? 0 : _a;
|
|
35
|
-
var listener = null;
|
|
36
|
-
|
|
37
|
-
if (mpegList[channel]) {
|
|
38
|
-
listener = mpegList[channel].on('data', function (chunk) {
|
|
39
|
-
ws.send(chunk);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
ws.on('close', function () {
|
|
44
|
-
if (listener) {
|
|
45
|
-
mpegList[channel].cancel(listener);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
return mpegList;
|
|
50
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare class RTSP2Mpeg {
|
|
2
|
-
private readonly eventEmitter;
|
|
3
|
-
private readonly dog;
|
|
4
|
-
private readonly url;
|
|
5
|
-
private s;
|
|
6
|
-
private readonly options;
|
|
7
|
-
constructor(url: string, options: any);
|
|
8
|
-
private onMessage;
|
|
9
|
-
private closeOld;
|
|
10
|
-
private connect;
|
|
11
|
-
on(event: string, cb: (data: any) => void): string;
|
|
12
|
-
cancel(id: any): void;
|
|
13
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
var __assign = this && this.__assign || function () {
|
|
2
|
-
__assign = Object.assign || function (t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
|
|
6
|
-
for (var p in s) {
|
|
7
|
-
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
return __assign.apply(this, arguments);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
var __read = this && this.__read || function (o, n) {
|
|
18
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o),
|
|
21
|
-
r,
|
|
22
|
-
ar = [],
|
|
23
|
-
e;
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
27
|
-
ar.push(r.value);
|
|
28
|
-
}
|
|
29
|
-
} catch (error) {
|
|
30
|
-
e = {
|
|
31
|
-
error: error
|
|
32
|
-
};
|
|
33
|
-
} finally {
|
|
34
|
-
try {
|
|
35
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
36
|
-
} finally {
|
|
37
|
-
if (e) throw e.error;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return ar;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
var __spread = this && this.__spread || function () {
|
|
45
|
-
for (var ar = [], i = 0; i < arguments.length; i++) {
|
|
46
|
-
ar = ar.concat(__read(arguments[i]));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return ar;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
import { spawn } from 'child_process';
|
|
53
|
-
import { Emitter, WatchDog } from 'pubo-utils';
|
|
54
|
-
|
|
55
|
-
var RTSP2Mpeg =
|
|
56
|
-
/** @class */
|
|
57
|
-
function () {
|
|
58
|
-
function RTSP2Mpeg(url, options) {
|
|
59
|
-
var _this = this;
|
|
60
|
-
|
|
61
|
-
this.eventEmitter = new Emitter();
|
|
62
|
-
this.dog = new WatchDog({
|
|
63
|
-
limit: 10,
|
|
64
|
-
onTimeout: function onTimeout() {
|
|
65
|
-
return _this.connect();
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
this.url = url;
|
|
69
|
-
this.options = __assign({}, options);
|
|
70
|
-
|
|
71
|
-
if (!this.options.input) {
|
|
72
|
-
this.options.input = ['-rtsp_transport', 'tcp', '-i'];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (!this.options.output) {
|
|
76
|
-
this.options.output = ['-f', 'mpegts', '-codec:v', 'mpeg1video'];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
this.connect();
|
|
80
|
-
this.dog.init();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
RTSP2Mpeg.prototype.onMessage = function (msg) {
|
|
84
|
-
this.dog.feed();
|
|
85
|
-
this.eventEmitter.emit('message', msg.toString());
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
RTSP2Mpeg.prototype.closeOld = function () {
|
|
89
|
-
if (this.s) {
|
|
90
|
-
console.log("LOG Video-Server: " + this.url + " try to reconnect;");
|
|
91
|
-
this.s.kill();
|
|
92
|
-
this.s = null;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
RTSP2Mpeg.prototype.connect = function () {
|
|
97
|
-
var _this = this;
|
|
98
|
-
|
|
99
|
-
this.closeOld();
|
|
100
|
-
|
|
101
|
-
var options = __spread(this.options.input, [this.url], this.options.output, ['-']);
|
|
102
|
-
|
|
103
|
-
this.s = spawn('ffmpeg', options, {
|
|
104
|
-
detached: false
|
|
105
|
-
});
|
|
106
|
-
this.s.stderr.on('data', function (buffer) {
|
|
107
|
-
return _this.onMessage(buffer);
|
|
108
|
-
});
|
|
109
|
-
this.s.stdout.on('data', function (buffer) {
|
|
110
|
-
return _this.eventEmitter.emit('data', buffer);
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
RTSP2Mpeg.prototype.on = function (event, cb) {
|
|
115
|
-
return this.eventEmitter.on(event, cb);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
RTSP2Mpeg.prototype.cancel = function (id) {
|
|
119
|
-
this.eventEmitter.cancel(id);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
return RTSP2Mpeg;
|
|
123
|
-
}();
|
|
124
|
-
|
|
125
|
-
export { RTSP2Mpeg };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { RTSP2Mpeg } from './rtsp2mpeg';
|
|
2
|
-
interface VideoConfig {
|
|
3
|
-
url: string;
|
|
4
|
-
input?: string[];
|
|
5
|
-
output?: string[];
|
|
6
|
-
}
|
|
7
|
-
interface Props {
|
|
8
|
-
app: any;
|
|
9
|
-
server?: any;
|
|
10
|
-
videos: VideoConfig[];
|
|
11
|
-
path: string;
|
|
12
|
-
expressWs?: any;
|
|
13
|
-
}
|
|
14
|
-
export declare const initRtspVideos: ({ app, server, videos, path, expressWs }: Props) => RTSP2Mpeg[];
|
|
15
|
-
export {};
|