pubo-node 1.0.34 → 1.0.35

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 CHANGED
@@ -1 +1 @@
1
- !function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["pubo-node"]=n():t["pubo-node"]=n()}(this,(function(){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=7)}([function(t,n){t.exports=require("pubo-utils")},function(t,n){t.exports=require("fs")},function(t,n){t.exports=require("pako")},function(t,n){t.exports=require("crypto")},function(t,n){t.exports=require("grpc")},function(t,n){function e(t){var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}e.keys=function(){return[]},e.resolve=e,t.exports=e,e.id=5},function(t,n){function e(t){var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}e.keys=function(){return[]},e.resolve=e,t.exports=e,e.id=6},function(t,n,e){"use strict";e.r(n),e.d(n,"JsonStorage",(function(){return c})),e.d(n,"FtpClient",(function(){return y})),e.d(n,"md5",(function(){return b})),e.d(n,"createGrpcService",(function(){return E})),e.d(n,"GrpcPool",(function(){return w}));var r=e(1),o=e(2),i=function(){return(i=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},c=function(){function t(t){this._state={},this.path=t,this.init()}return t.prototype.init=function(){try{var t=Object(r.readFileSync)(this.path),n=o.inflate(t,{to:"string"});this._state=JSON.parse(n)}catch(t){this.state={}}},Object.defineProperty(t.prototype,"state",{get:function(){return this._state},set:function(t){var n=o.deflate(JSON.stringify(t)),e=Buffer.from(n);Object(r.writeFile)(this.path,e,(function(t){return t&&console.log(t)})),this._state=t},enumerable:!1,configurable:!0}),t.prototype.get=function(t){return t?this.state[t]:i({},this.state)},t.prototype.set=function(t,n){var e=i({},this.state);e[t]=n,this.state=e},t.prototype.merge=function(t){this.state=i(i({},this._state),t)},t}(),u=e(0),a=function(){return(a=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},s=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function c(t){try{a(r.next(t))}catch(t){i(t)}}function u(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(c,u)}a((r=r.apply(t,n||[])).next())}))},f=function(t,n){var e,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;c;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,r=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=n.call(t,c)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},l=function(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(e[r[o]]=t[r[o]])}return e},p=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),c=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)c.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return c},h=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(p(arguments[n]));return t},y=function(){function t(t){var n=t.driver,e=l(t,["driver"]);this.queue=new u.SyncQueue,this.get=this._bind("get"),this.put=this._bind("put"),this.delete=this._bind("delete"),this.list=this._bind("list"),this.rename=this._bind("rename"),this.driver=n,this.options=e}return t.prototype._push=function(t){var n=this;return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return n.queue.push((function(){return t.call.apply(t,h([n],e))}))}},t.prototype._bind=function(t){var n=this;return this._push((function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return s(n,void 0,void 0,(function(){var n;return f(this,(function(r){switch(r.label){case 0:return[4,this.connect()];case 1:return n=r.sent(),[2,this._run(t,n,e)]}}))}))}))},t.prototype._run=function(t,n,e){return new Promise((function(r,o){n[t].apply(n,h(e,[function(e,i){e?(o(e),n.end()):(r(i||"operation successful."),"get"===t?i.once("close",(function(){return n.end()})):n.end())}]))}))},t.prototype.connect=function(){var t=this;return new Promise((function(n,e){var r=new t.driver;r.once("ready",(function(){n(r)})),r.once("error",(function(t){e(t),r.end()})),r.connect(a({},t.options))}))},t}(),d=e(3),b=function(t){return Object(d.createHash)("md5").update(t).digest("hex")},v=e(4),g=function(){return(g=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},m=function(){function t(t){this.options={"grpc.max_send_message_length":-1,"grpc.max_receive_message_length":-1},this.instance=null,this.config=t,this.common=e(5)(this.config.root+"/common_pb"),this.RpcClient=e(6)(this.config.root+"/service_grpc_pb").RpcClient,this.proto=global.proto,global.proto={}}return Object.defineProperty(t.prototype,"client",{get:function(){if(!this.instance){var t=g(g({},this.options),this.config.options||{});this.instance=new this.RpcClient(this.config.url,v.credentials.createInsecure(),t)}return this.instance},enumerable:!1,configurable:!0}),t}(),w=function(){function t(t){this.list=[],this.list=t.map((function(t){return{id:t.id,grpc:new m(t)}}))}return t.prototype.getGrpc=function(t){var n;return null===(n=this.list.find((function(n){return n.id===t})))||void 0===n?void 0:n.grpc},t.pool=[],t.instance=null,t.getPool=function(){return t.instance||(t.instance=new t(t.pool)),t.instance},t.setPool=function(n){t.pool=n,t.instance=new t(t.pool)},t}(),O=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function c(t){try{a(r.next(t))}catch(t){i(t)}}function u(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(c,u)}a((r=r.apply(t,n||[])).next())}))},x=function(t,n){var e,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;c;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,r=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=n.call(t,c)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},_=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),c=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)c.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return c},j=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(_(arguments[n]));return t},S=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};var P=function(){function t(t){if(this.config=t,this.grpc=w.getPool().getGrpc(this.config.client),!this.grpc||!this.grpc.client[this.config.serviceName])throw new Error("rpc service not found:"+this.config.serviceName);var n,e;this.promise=(n=this.grpc.client[this.config.serviceName],e=this.grpc,function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return new Promise((function(r,o){var i=e.client;n.call.apply(n,j([i],t,[function(t,n){global.proto=e.proto,t?o(t):r(n)}]))}))})}return t.prototype.serializer=function(t,n){var e,r;if(void 0===n&&(n={}),!this.grpc)throw new Error("rpc client not found:"+this.config.client);global.proto=this.grpc.proto;var o=new this.grpc.common[t];try{for(var i=S(Object.keys(o.toObject())),c=i.next();!c.done;c=i.next()){var u=c.value;void 0!==n[u]&&o["set"+u[0].toUpperCase()+u.slice(1)](n[u])}}catch(t){e={error:t}}finally{try{c&&!c.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return o},t.prototype.send=function(t){return O(this,void 0,void 0,(function(){return x(this,(function(n){switch(n.label){case 0:return[4,this.promise(this.serializer(this.config.requestType,t))];case 1:return[2,n.sent().toObject()]}}))}))},t}(),k=function(){return(k=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},E=Object(u.superFactory)((function(t,n){return new P(k(k({},t),{serviceName:t.service||n}))}))}])}));
1
+ !function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["pubo-node"]=n():t["pubo-node"]=n()}(this,(function(){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=8)}([function(t,n){t.exports=require("pubo-utils")},function(t,n){t.exports=require("fs")},function(t,n){t.exports=require("pako")},function(t,n){t.exports=require("child_process")},function(t,n){t.exports=require("crypto")},function(t,n){t.exports=require("grpc")},function(t,n){function e(t){var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}e.keys=function(){return[]},e.resolve=e,t.exports=e,e.id=6},function(t,n){function e(t){var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}e.keys=function(){return[]},e.resolve=e,t.exports=e,e.id=7},function(t,n,e){"use strict";e.r(n),e.d(n,"JsonStorage",(function(){return c})),e.d(n,"initRtspVideos",(function(){return y})),e.d(n,"FtpClient",(function(){return O})),e.d(n,"md5",(function(){return j})),e.d(n,"createGrpcService",(function(){return F})),e.d(n,"GrpcPool",(function(){return E}));var r=e(1),o=e(2),i=function(){return(i=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},c=function(){function t(t){this._state={},this.path=t,this.init()}return t.prototype.init=function(){try{var t=Object(r.readFileSync)(this.path),n=o.inflate(t,{to:"string"});this._state=JSON.parse(n)}catch(t){this.state={}}},Object.defineProperty(t.prototype,"state",{get:function(){return this._state},set:function(t){var n=o.deflate(JSON.stringify(t)),e=Buffer.from(n);Object(r.writeFile)(this.path,e,(function(t){return t&&console.log(t)})),this._state=t},enumerable:!1,configurable:!0}),t.prototype.get=function(t){return t?this.state[t]:i({},this.state)},t.prototype.set=function(t,n){var e=i({},this.state);e[t]=n,this.state=e},t.prototype.merge=function(t){this.state=i(i({},this._state),t)},t}(),u=e(3),s=e(0),a=function(){return(a=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},l=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),c=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)c.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return c},f=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(l(arguments[n]));return t},p=function(){function t(t,n){var e=this;this.eventEmitter=new s.Emitter,this.dog=new s.WatchDog({limit:10,onTimeout:function(){return e.connect()}}),this.url=t,this.options=a({},n),this.options.input||(this.options.input=["-rtsp_transport","tcp","-i"]),this.options.output||(this.options.output=["-f","mpegts","-codec:v","mpeg1video"]),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 n=f(this.options.input,[this.url],this.options.output,["-"]);this.s=Object(u.spawn)("ffmpeg",n,{detached:!1}),this.s.stderr.on("data",(function(n){return t.onMessage(n)})),this.s.stdout.on("data",(function(n){return t.eventEmitter.emit("data",n)}))},t.prototype.on=function(t,n){return this.eventEmitter.on(t,n)},t.prototype.cancel=function(t){this.eventEmitter.cancel(t)},t}(),h=function(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(e[r[o]]=t[r[o]])}return e},y=function(t){var n=t.app,e=t.server,r=t.videos,o=t.path,i=t.expressWs,c=r.map((function(t){var n=t.url,e=h(t,["url"]);return new p(n,e)}));return n.ws||i(n,e),n.ws(o,(function(t,n){var e=n.query.channel,r=void 0===e?0:e,o=null;c[r]&&(o=c[r].on("data",(function(n){t.send(n)}))),t.on("close",(function(){o&&c[r].cancel(o)}))})),c},d=function(){return(d=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},v=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function c(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(c,u)}s((r=r.apply(t,n||[])).next())}))},b=function(t,n){var e,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;c;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,r=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=n.call(t,c)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},g=function(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(e[r[o]]=t[r[o]])}return e},m=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),c=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)c.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return c},w=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(m(arguments[n]));return t},O=function(){function t(t){var n=t.driver,e=g(t,["driver"]);this.queue=new s.SyncQueue,this.get=this._bind("get"),this.put=this._bind("put"),this.delete=this._bind("delete"),this.list=this._bind("list"),this.rename=this._bind("rename"),this.driver=n,this.options=e}return t.prototype._push=function(t){var n=this;return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return n.queue.push((function(){return t.call.apply(t,w([n],e))}))}},t.prototype._bind=function(t){var n=this;return this._push((function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return v(n,void 0,void 0,(function(){var n;return b(this,(function(r){switch(r.label){case 0:return[4,this.connect()];case 1:return n=r.sent(),[2,this._run(t,n,e)]}}))}))}))},t.prototype._run=function(t,n,e){return new Promise((function(r,o){n[t].apply(n,w(e,[function(e,i){e?(o(e),n.end()):(r(i||"operation successful."),"get"===t?i.once("close",(function(){return n.end()})):n.end())}]))}))},t.prototype.connect=function(){var t=this;return new Promise((function(n,e){var r=new t.driver;r.once("ready",(function(){n(r)})),r.once("error",(function(t){e(t),r.end()})),r.connect(d({},t.options))}))},t}(),x=e(4),j=function(t){return Object(x.createHash)("md5").update(t).digest("hex")},_=e(5),S=function(){return(S=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},P=function(){function t(t){this.options={"grpc.max_send_message_length":-1,"grpc.max_receive_message_length":-1},this.instance=null,this.config=t,this.common=e(6)(this.config.root+"/common_pb"),this.RpcClient=e(7)(this.config.root+"/service_grpc_pb").RpcClient,this.proto=global.proto,global.proto={}}return Object.defineProperty(t.prototype,"client",{get:function(){if(!this.instance){var t=S(S({},this.options),this.config.options||{});this.instance=new this.RpcClient(this.config.url,_.credentials.createInsecure(),t)}return this.instance},enumerable:!1,configurable:!0}),t}(),E=function(){function t(t){this.list=[],this.list=t.map((function(t){return{id:t.id,grpc:new P(t)}}))}return t.prototype.getGrpc=function(t){var n;return null===(n=this.list.find((function(n){return n.id===t})))||void 0===n?void 0:n.grpc},t.pool=[],t.instance=null,t.getPool=function(){return t.instance||(t.instance=new t(t.pool)),t.instance},t.setPool=function(n){t.pool=n,t.instance=new t(t.pool)},t}(),k=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function c(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(c,u)}s((r=r.apply(t,n||[])).next())}))},q=function(t,n){var e,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;c;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,r=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=n.call(t,c)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},N=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),c=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)c.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return c},T=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(N(arguments[n]));return t},M=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};var C=function(){function t(t){if(this.config=t,this.grpc=E.getPool().getGrpc(this.config.client),!this.grpc||!this.grpc.client[this.config.serviceName])throw new Error("rpc service not found:"+this.config.serviceName);var n,e;this.promise=(n=this.grpc.client[this.config.serviceName],e=this.grpc,function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return new Promise((function(r,o){var i=e.client;n.call.apply(n,T([i],t,[function(t,n){global.proto=e.proto,t?o(t):r(n)}]))}))})}return t.prototype.serializer=function(t,n){var e,r;if(void 0===n&&(n={}),!this.grpc)throw new Error("rpc client not found:"+this.config.client);global.proto=this.grpc.proto;var o=new this.grpc.common[t];try{for(var i=M(Object.keys(o.toObject())),c=i.next();!c.done;c=i.next()){var u=c.value;void 0!==n[u]&&o["set"+u[0].toUpperCase()+u.slice(1)](n[u])}}catch(t){e={error:t}}finally{try{c&&!c.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return o},t.prototype.send=function(t){return k(this,void 0,void 0,(function(){return q(this,(function(n){switch(n.label){case 0:return[4,this.promise(this.serializer(this.config.requestType,t))];case 1:return[2,n.sent().toObject()]}}))}))},t}(),G=function(){return(G=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},F=Object(s.superFactory)((function(t,n){return new C(G(G({},t),{serviceName:t.service||n}))}))}])}));
package/es/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { JsonStorage } from './storage/json';
2
+ export { initRtspVideos } from './rtsp-video';
2
3
  export { FtpClient } from './ftp-client';
3
4
  export { md5 } from './md5';
4
5
  export { createGrpcService } from './grpc';
package/es/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { JsonStorage } from './storage/json';
2
+ export { initRtspVideos } from './rtsp-video';
2
3
  export { FtpClient } from './ftp-client';
3
4
  export { md5 } from './md5';
4
5
  export { createGrpcService } from './grpc';
@@ -0,0 +1,15 @@
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 {};
@@ -0,0 +1,50 @@
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
+ };
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,125 @@
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 };
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { JsonStorage } from './storage/json';
2
+ export { initRtspVideos } from './rtsp-video';
2
3
  export { FtpClient } from './ftp-client';
3
4
  export { md5 } from './md5';
4
5
  export { createGrpcService } from './grpc';
package/lib/index.js CHANGED
@@ -13,6 +13,15 @@ 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
+
16
25
  var ftp_client_1 = require("./ftp-client");
17
26
 
18
27
  Object.defineProperty(exports, "FtpClient", {
@@ -0,0 +1,15 @@
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 {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ var __rest = this && this.__rest || function (s, e) {
4
+ var t = {};
5
+
6
+ for (var p in s) {
7
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
8
+ }
9
+
10
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
11
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
12
+ }
13
+ return t;
14
+ };
15
+
16
+ Object.defineProperty(exports, "__esModule", {
17
+ value: true
18
+ });
19
+ exports.initRtspVideos = void 0;
20
+
21
+ var rtsp2mpeg_1 = require("./rtsp2mpeg");
22
+
23
+ exports.initRtspVideos = function (_a) {
24
+ var app = _a.app,
25
+ server = _a.server,
26
+ videos = _a.videos,
27
+ path = _a.path,
28
+ expressWs = _a.expressWs;
29
+ var mpegList = videos.map(function (_a) {
30
+ var url = _a.url,
31
+ options = __rest(_a, ["url"]);
32
+
33
+ return new rtsp2mpeg_1.RTSP2Mpeg(url, options);
34
+ });
35
+
36
+ if (!app.ws) {
37
+ expressWs(app, server);
38
+ }
39
+
40
+ app.ws(path, function (ws, req) {
41
+ var _a = req.query.channel,
42
+ channel = _a === void 0 ? 0 : _a;
43
+ var listener = null;
44
+
45
+ if (mpegList[channel]) {
46
+ listener = mpegList[channel].on('data', function (chunk) {
47
+ ws.send(chunk);
48
+ });
49
+ }
50
+
51
+ ws.on('close', function () {
52
+ if (listener) {
53
+ mpegList[channel].cancel(listener);
54
+ }
55
+ });
56
+ });
57
+ return mpegList;
58
+ };
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,133 @@
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
+ var __read = this && this.__read || function (o, n) {
20
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
21
+ if (!m) return o;
22
+ var i = m.call(o),
23
+ r,
24
+ ar = [],
25
+ e;
26
+
27
+ try {
28
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
29
+ ar.push(r.value);
30
+ }
31
+ } catch (error) {
32
+ e = {
33
+ error: error
34
+ };
35
+ } finally {
36
+ try {
37
+ if (r && !r.done && (m = i["return"])) m.call(i);
38
+ } finally {
39
+ if (e) throw e.error;
40
+ }
41
+ }
42
+
43
+ return ar;
44
+ };
45
+
46
+ var __spread = this && this.__spread || function () {
47
+ for (var ar = [], i = 0; i < arguments.length; i++) {
48
+ ar = ar.concat(__read(arguments[i]));
49
+ }
50
+
51
+ return ar;
52
+ };
53
+
54
+ Object.defineProperty(exports, "__esModule", {
55
+ value: true
56
+ });
57
+ exports.RTSP2Mpeg = void 0;
58
+
59
+ var child_process_1 = require("child_process");
60
+
61
+ var pubo_utils_1 = require("pubo-utils");
62
+
63
+ var RTSP2Mpeg =
64
+ /** @class */
65
+ function () {
66
+ function RTSP2Mpeg(url, options) {
67
+ var _this = this;
68
+
69
+ this.eventEmitter = new pubo_utils_1.Emitter();
70
+ this.dog = new pubo_utils_1.WatchDog({
71
+ limit: 10,
72
+ onTimeout: function onTimeout() {
73
+ return _this.connect();
74
+ }
75
+ });
76
+ this.url = url;
77
+ this.options = __assign({}, options);
78
+
79
+ if (!this.options.input) {
80
+ this.options.input = ['-rtsp_transport', 'tcp', '-i'];
81
+ }
82
+
83
+ if (!this.options.output) {
84
+ this.options.output = ['-f', 'mpegts', '-codec:v', 'mpeg1video'];
85
+ }
86
+
87
+ this.connect();
88
+ this.dog.init();
89
+ }
90
+
91
+ RTSP2Mpeg.prototype.onMessage = function (msg) {
92
+ this.dog.feed();
93
+ this.eventEmitter.emit('message', msg.toString());
94
+ };
95
+
96
+ RTSP2Mpeg.prototype.closeOld = function () {
97
+ if (this.s) {
98
+ console.log("LOG Video-Server: " + this.url + " try to reconnect;");
99
+ this.s.kill();
100
+ this.s = null;
101
+ }
102
+ };
103
+
104
+ RTSP2Mpeg.prototype.connect = function () {
105
+ var _this = this;
106
+
107
+ this.closeOld();
108
+
109
+ var options = __spread(this.options.input, [this.url], this.options.output, ['-']);
110
+
111
+ this.s = child_process_1.spawn('ffmpeg', options, {
112
+ detached: false
113
+ });
114
+ this.s.stderr.on('data', function (buffer) {
115
+ return _this.onMessage(buffer);
116
+ });
117
+ this.s.stdout.on('data', function (buffer) {
118
+ return _this.eventEmitter.emit('data', buffer);
119
+ });
120
+ };
121
+
122
+ RTSP2Mpeg.prototype.on = function (event, cb) {
123
+ return this.eventEmitter.on(event, cb);
124
+ };
125
+
126
+ RTSP2Mpeg.prototype.cancel = function (id) {
127
+ this.eventEmitter.cancel(id);
128
+ };
129
+
130
+ return RTSP2Mpeg;
131
+ }();
132
+
133
+ exports.RTSP2Mpeg = RTSP2Mpeg;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-node",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "@types/node": "^17.0.25",
23
23
  "grpc": "^1.24.11",
24
24
  "pako": "^2.0.4",
25
- "pubo-utils": "^1.0.34"
25
+ "pubo-utils": "^1.0.35-alpha.0"
26
26
  },
27
- "gitHead": "c5218221058a304c692c4e9e789e7b8f8a2c7bce"
27
+ "gitHead": "b8ce14e2272518a06835d63a07087d347823b19f"
28
28
  }