pubo-node 1.0.4-alpha.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.
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["pubo-node"]=e():t["pubo-node"]=e()}(this,(function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=4)}([function(t,e){t.exports=require("pubo-utils")},function(t,e){t.exports=require("express-ws")},function(t,e){t.exports=require("child_process")},function(t,e){t.exports=require("crypto")},function(t,e,n){"use strict";n.r(e),n.d(e,"initRtspVideos",(function(){return f})),n.d(e,"md5",(function(){return r}));var o=n(3),r=function(t){return Object(o.createHash)("md5").update(t).digest("hex")},i=n(1),u=n(2),c=n(0),s=function(){function t(t){var e=this;this.eventEmitter=new c.Emitter,this.dog=new c.WatchDog({limit:10,onTimeout:function(){return e.connect()}}),this.url=t,this.connect(),this.dog.init()}return t.prototype.onMessage=function(t){this.dog.feed(),this.eventEmitter.emit("message",t.toString())},t.prototype.closeOld=function(){this.s&&(console.log("LOG Video-Server: "+this.url+" try to reconnect;"),this.s.kill(),this.s=null)},t.prototype.connect=function(){var t=this;this.closeOld();var e=["-rtsp_transport","tcp","-i",this.url,"-f","mpegts","-codec:v","mpeg1video","-"];this.s=Object(u.spawn)("ffmpeg",e,{detached:!1}),this.s.stderr.on("data",(function(e){return t.onMessage(e)})),this.s.stdout.on("data",(function(e){return t.eventEmitter.emit("data",e)}))},t.prototype.on=function(t,e){return this.eventEmitter.on(t,e)},t.prototype.cancel=function(t){this.eventEmitter.cancel(t)},t}(),f=function(t){var e=t.app,n=t.server,o=t.videos,r=t.path,u=o.map((function(t){return new s(t)}));return i(e,n),e.ws(r,(function(t,e){var n=e.query.channel,o=void 0===n?0:n,r=null;u[o]&&(r=u[o].on("data",(function(e){t.send(e)}))),t.on("close",(function(){r&&u[o].cancel(r)}))})),u}}])}));
package/es/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { md5 } from './md5';
2
+ import { initRtspVideos } from './rtsp-video';
3
+ export { initRtspVideos, md5 };
package/es/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { md5 } from './md5';
2
+ import { initRtspVideos } from './rtsp-video';
3
+ export { initRtspVideos, md5 };
@@ -0,0 +1 @@
1
+ export declare const md5: (str: string) => string;
@@ -0,0 +1,4 @@
1
+ import { createHash } from 'crypto';
2
+ export var md5 = function md5(str) {
3
+ return createHash('md5').update(str).digest('hex');
4
+ };
@@ -0,0 +1,6 @@
1
+ export declare const initRtspVideos: ({ app, server, videos, path }: {
2
+ app: any;
3
+ server: any;
4
+ videos: any;
5
+ path: any;
6
+ }) => any;
@@ -0,0 +1,30 @@
1
+ import * as expressWs from 'express-ws';
2
+ import { RTSP2Mpeg } from './rtsp2mpeg';
3
+ export var initRtspVideos = function initRtspVideos(_a) {
4
+ var app = _a.app,
5
+ server = _a.server,
6
+ videos = _a.videos,
7
+ path = _a.path;
8
+ var mpegList = videos.map(function (url) {
9
+ return new RTSP2Mpeg(url);
10
+ });
11
+ expressWs(app, server);
12
+ app.ws(path, function (ws, req) {
13
+ var _a = req.query.channel,
14
+ channel = _a === void 0 ? 0 : _a;
15
+ var listener = null;
16
+
17
+ if (mpegList[channel]) {
18
+ listener = mpegList[channel].on('data', function (chunk) {
19
+ ws.send(chunk);
20
+ });
21
+ }
22
+
23
+ ws.on('close', function () {
24
+ if (listener) {
25
+ mpegList[channel].cancel(listener);
26
+ }
27
+ });
28
+ });
29
+ return mpegList;
30
+ };
@@ -0,0 +1,12 @@
1
+ export declare class RTSP2Mpeg {
2
+ private readonly eventEmitter;
3
+ private readonly dog;
4
+ private readonly url;
5
+ private s;
6
+ constructor(url: string);
7
+ private onMessage;
8
+ private closeOld;
9
+ private connect;
10
+ on(event: string, cb: (data: any) => void): string;
11
+ cancel(id: any): void;
12
+ }
@@ -0,0 +1,62 @@
1
+ import { spawn } from 'child_process';
2
+ import { Emitter, WatchDog } from 'pubo-utils';
3
+
4
+ var RTSP2Mpeg =
5
+ /** @class */
6
+ function () {
7
+ function RTSP2Mpeg(url) {
8
+ var _this = this;
9
+
10
+ this.eventEmitter = new Emitter();
11
+ this.dog = new WatchDog({
12
+ limit: 10,
13
+ onTimeout: function onTimeout() {
14
+ return _this.connect();
15
+ }
16
+ });
17
+ this.url = url;
18
+ this.connect();
19
+ this.dog.init();
20
+ }
21
+
22
+ RTSP2Mpeg.prototype.onMessage = function (msg) {
23
+ this.dog.feed();
24
+ this.eventEmitter.emit('message', msg.toString());
25
+ };
26
+
27
+ RTSP2Mpeg.prototype.closeOld = function () {
28
+ if (this.s) {
29
+ console.log("LOG Video-Server: " + this.url + " try to reconnect;");
30
+ this.s.kill();
31
+ this.s = null;
32
+ }
33
+ };
34
+
35
+ RTSP2Mpeg.prototype.connect = function () {
36
+ var _this = this;
37
+
38
+ this.closeOld();
39
+ var options = ['-rtsp_transport', 'tcp', '-i', this.url, '-f', 'mpegts', '-codec:v', 'mpeg1video', '-'];
40
+ this.s = spawn('ffmpeg', options, {
41
+ detached: false
42
+ });
43
+ this.s.stderr.on('data', function (buffer) {
44
+ return _this.onMessage(buffer);
45
+ });
46
+ this.s.stdout.on('data', function (buffer) {
47
+ return _this.eventEmitter.emit('data', buffer);
48
+ });
49
+ };
50
+
51
+ RTSP2Mpeg.prototype.on = function (event, cb) {
52
+ return this.eventEmitter.on(event, cb);
53
+ };
54
+
55
+ RTSP2Mpeg.prototype.cancel = function (id) {
56
+ this.eventEmitter.cancel(id);
57
+ };
58
+
59
+ return RTSP2Mpeg;
60
+ }();
61
+
62
+ export { RTSP2Mpeg };
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { md5 } from './md5';
2
+ import { initRtspVideos } from './rtsp-video';
3
+ export { initRtspVideos, md5 };
package/lib/index.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.md5 = exports.initRtspVideos = void 0;
7
+
8
+ var md5_1 = require("./md5");
9
+
10
+ Object.defineProperty(exports, "md5", {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return md5_1.md5;
14
+ }
15
+ });
16
+
17
+ var rtsp_video_1 = require("./rtsp-video");
18
+
19
+ Object.defineProperty(exports, "initRtspVideos", {
20
+ enumerable: true,
21
+ get: function get() {
22
+ return rtsp_video_1.initRtspVideos;
23
+ }
24
+ });
@@ -0,0 +1 @@
1
+ export declare const md5: (str: string) => string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.md5 = void 0;
7
+
8
+ var crypto_1 = require("crypto");
9
+
10
+ exports.md5 = function (str) {
11
+ return crypto_1.createHash('md5').update(str).digest('hex');
12
+ };
@@ -0,0 +1,6 @@
1
+ export declare const initRtspVideos: ({ app, server, videos, path }: {
2
+ app: any;
3
+ server: any;
4
+ videos: any;
5
+ path: any;
6
+ }) => any;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ Object.defineProperty(o, k2, {
6
+ enumerable: true,
7
+ get: function get() {
8
+ return m[k];
9
+ }
10
+ });
11
+ } : function (o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ });
15
+
16
+ var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
17
+ Object.defineProperty(o, "default", {
18
+ enumerable: true,
19
+ value: v
20
+ });
21
+ } : function (o, v) {
22
+ o["default"] = v;
23
+ });
24
+
25
+ var __importStar = this && this.__importStar || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) {
29
+ if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
30
+ }
31
+
32
+ __setModuleDefault(result, mod);
33
+
34
+ return result;
35
+ };
36
+
37
+ Object.defineProperty(exports, "__esModule", {
38
+ value: true
39
+ });
40
+ exports.initRtspVideos = void 0;
41
+
42
+ var expressWs = __importStar(require("express-ws"));
43
+
44
+ var rtsp2mpeg_1 = require("./rtsp2mpeg");
45
+
46
+ exports.initRtspVideos = function (_a) {
47
+ var app = _a.app,
48
+ server = _a.server,
49
+ videos = _a.videos,
50
+ path = _a.path;
51
+ var mpegList = videos.map(function (url) {
52
+ return new rtsp2mpeg_1.RTSP2Mpeg(url);
53
+ });
54
+ expressWs(app, server);
55
+ app.ws(path, function (ws, req) {
56
+ var _a = req.query.channel,
57
+ channel = _a === void 0 ? 0 : _a;
58
+ var listener = null;
59
+
60
+ if (mpegList[channel]) {
61
+ listener = mpegList[channel].on('data', function (chunk) {
62
+ ws.send(chunk);
63
+ });
64
+ }
65
+
66
+ ws.on('close', function () {
67
+ if (listener) {
68
+ mpegList[channel].cancel(listener);
69
+ }
70
+ });
71
+ });
72
+ return mpegList;
73
+ };
@@ -0,0 +1,12 @@
1
+ export declare class RTSP2Mpeg {
2
+ private readonly eventEmitter;
3
+ private readonly dog;
4
+ private readonly url;
5
+ private s;
6
+ constructor(url: string);
7
+ private onMessage;
8
+ private closeOld;
9
+ private connect;
10
+ on(event: string, cb: (data: any) => void): string;
11
+ cancel(id: any): void;
12
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RTSP2Mpeg = void 0;
7
+
8
+ var child_process_1 = require("child_process");
9
+
10
+ var pubo_utils_1 = require("pubo-utils");
11
+
12
+ var RTSP2Mpeg =
13
+ /** @class */
14
+ function () {
15
+ function RTSP2Mpeg(url) {
16
+ var _this = this;
17
+
18
+ this.eventEmitter = new pubo_utils_1.Emitter();
19
+ this.dog = new pubo_utils_1.WatchDog({
20
+ limit: 10,
21
+ onTimeout: function onTimeout() {
22
+ return _this.connect();
23
+ }
24
+ });
25
+ this.url = url;
26
+ this.connect();
27
+ this.dog.init();
28
+ }
29
+
30
+ RTSP2Mpeg.prototype.onMessage = function (msg) {
31
+ this.dog.feed();
32
+ this.eventEmitter.emit('message', msg.toString());
33
+ };
34
+
35
+ RTSP2Mpeg.prototype.closeOld = function () {
36
+ if (this.s) {
37
+ console.log("LOG Video-Server: " + this.url + " try to reconnect;");
38
+ this.s.kill();
39
+ this.s = null;
40
+ }
41
+ };
42
+
43
+ RTSP2Mpeg.prototype.connect = function () {
44
+ var _this = this;
45
+
46
+ this.closeOld();
47
+ var options = ['-rtsp_transport', 'tcp', '-i', this.url, '-f', 'mpegts', '-codec:v', 'mpeg1video', '-'];
48
+ this.s = child_process_1.spawn('ffmpeg', options, {
49
+ detached: false
50
+ });
51
+ this.s.stderr.on('data', function (buffer) {
52
+ return _this.onMessage(buffer);
53
+ });
54
+ this.s.stdout.on('data', function (buffer) {
55
+ return _this.eventEmitter.emit('data', buffer);
56
+ });
57
+ };
58
+
59
+ RTSP2Mpeg.prototype.on = function (event, cb) {
60
+ return this.eventEmitter.on(event, cb);
61
+ };
62
+
63
+ RTSP2Mpeg.prototype.cancel = function (id) {
64
+ this.eventEmitter.cancel(id);
65
+ };
66
+
67
+ return RTSP2Mpeg;
68
+ }();
69
+
70
+ exports.RTSP2Mpeg = RTSP2Mpeg;
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "pubo-node",
3
+ "version": "1.0.4-alpha.0",
4
+ "main": "./lib/index.js",
5
+ "module": "./es/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "unpkg": "dist/index.js",
8
+ "sideEffects": false,
9
+ "scripts": {
10
+ "build": "gulp && webpack-cli"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "lib",
15
+ "es",
16
+ "package.json"
17
+ ],
18
+ "engines": {
19
+ "node": ">=8.0.0"
20
+ },
21
+ "dependencies": {
22
+ "@types/node": "^17.0.25",
23
+ "express": "^4.17.3",
24
+ "express-ws": "^5.0.2",
25
+ "pubo-utils": "^1.0.3-alpha.0"
26
+ },
27
+ "gitHead": "34e995171bfc1cb3010bc1e68949e8a6e326b883"
28
+ }