pubo-node 1.0.35-alpha.0 → 1.0.36

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,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(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},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 r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},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=5)}([function(t,e){t.exports=require("pubo-utils")},function(t,e){t.exports=require("fs")},function(t,e){t.exports=require("pako")},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,"JsonStorage",(function(){return u})),n.d(e,"initRtspVideos",(function(){return y})),n.d(e,"FtpClient",(function(){return w})),n.d(e,"md5",(function(){return x})),n.d(e,"createRpcClient",(function(){return S}));var r=n(1),o=n(2),i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},u=function(){function t(t){this._state={},this.path=t,this.init()}return t.prototype.init=function(){try{var t=Object(r.readFileSync)(this.path),e=o.inflate(t,{to:"string"});this._state=JSON.parse(e)}catch(t){this.state={}}},Object.defineProperty(t.prototype,"state",{get:function(){return this._state},set:function(t){var e=o.deflate(JSON.stringify(t)),n=Buffer.from(e);Object(r.writeFile)(this.path,n,(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,e){var n=i({},this.state);n[t]=e,this.state=n},t.prototype.merge=function(t){this.state=i(i({},this._state),t)},t}(),c=n(3),s=n(0),a=function(){return(a=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},f=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u},l=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(f(arguments[e]));return t},p=function(){function t(t,e){var n=this;this.eventEmitter=new s.Emitter,this.dog=new s.WatchDog({limit:10,onTimeout:function(){return n.connect()}}),this.url=t,this.options=a({},e),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 e=l(this.options.input,[this.url],this.options.output,["-"]);this.s=Object(c.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}(),h=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},y=function(t){var e=t.app,n=t.server,r=t.videos,o=t.path,i=t.expressWs,u=r.map((function(t){var e=t.url,n=h(t,["url"]);return new p(e,n)}));return e.ws||i(e,n),e.ws(o,(function(t,e){var n=e.query.channel,r=void 0===n?0:n,o=null;u[r]&&(o=u[r].on("data",(function(e){t.send(e)}))),t.on("close",(function(){o&&u[r].cancel(o)}))})),u},d=function(){return(d=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},v=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function u(t){try{s(r.next(t))}catch(t){i(t)}}function c(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,c)}s((r=r.apply(t,e||[])).next())}))},b=function(t,e){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=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 u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},g=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},m=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u},O=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(m(arguments[e]));return t},w=function(){function t(t){var e=t.driver,n=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=e,this.options=n}return t.prototype._push=function(t){var e=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return e.queue.push((function(){return t.call.apply(t,O([e],n))}))}},t.prototype._bind=function(t){var e=this;return this._push((function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return v(e,void 0,void 0,(function(){var e;return b(this,(function(r){switch(r.label){case 0:return[4,this.connect()];case 1:return e=r.sent(),[2,this._run(t,e,n)]}}))}))}))},t.prototype._run=function(t,e,n){return new Promise((function(r,o){e[t].apply(e,O(n,[function(n,i){n?(o(n),e.end()):(r(i||"operation successful."),"get"===t?i.once("close",(function(){return e.end()})):e.end())}]))}))},t.prototype.connect=function(){var t=this;return new Promise((function(e,n){var r=new t.driver;r.once("ready",(function(){e(r)})),r.once("error",(function(t){n(t),r.end()})),r.connect(d({},t.options))}))},t}(),j=n(4),x=function(t){return Object(j.createHash)("md5").update(t).digest("hex")},_=function(){return(_=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function S(t){var e=t.url,n=t.options,r=void 0===n?{}:n,o=t.ServiceImp,i=t.Grpc,u=_({"grpc.max_send_message_length":-1,"grpc.max_receive_message_length":-1},r),c=new i.Client(e,i.credentials.createInsecure(),u);return new o({request:function(t,e,n){var r="/"+t+"/"+e;return new Promise((function(t,e){var o=function(t){return t};c.makeUnaryRequest(r,o,o,n,(function(n,r){n?e(n):t(r)}))}))}})}}])}));
@@ -1,8 +1,8 @@
1
- import { GrpcService } from './GrpcService';
2
- interface GrpcServiceOptions {
3
- client: string;
4
- requestType: string;
5
- service?: string;
1
+ interface CreateClientProps {
2
+ url: string;
3
+ options?: any;
4
+ ServiceImp: any;
5
+ Grpc: any;
6
6
  }
7
- export declare const createGrpcService: import("pubo-utils/lib/factory").CreateFactory<GrpcServiceOptions, GrpcService>;
7
+ export declare function createRpcClient<T>({ url, options, ServiceImp, Grpc }: CreateClientProps): T;
8
8
  export {};
package/es/grpc/index.js CHANGED
@@ -14,10 +14,40 @@ var __assign = this && this.__assign || function () {
14
14
  return __assign.apply(this, arguments);
15
15
  };
16
16
 
17
- import { superFactory } from 'pubo-utils';
18
- import { GrpcService } from './GrpcService';
19
- export var createGrpcService = superFactory(function (config, key) {
20
- return new GrpcService(__assign(__assign({}, config), {
21
- serviceName: config.service || key
22
- }));
23
- });
17
+ export function createRpcClient(_a) {
18
+ var url = _a.url,
19
+ _b = _a.options,
20
+ options = _b === void 0 ? {} : _b,
21
+ ServiceImp = _a.ServiceImp,
22
+ Grpc = _a.Grpc;
23
+
24
+ var opt = __assign({
25
+ 'grpc.max_send_message_length': -1,
26
+ 'grpc.max_receive_message_length': -1
27
+ }, options);
28
+
29
+ var connection = new Grpc.Client(url, Grpc.credentials.createInsecure(), opt);
30
+
31
+ var request = function request(service, method, data) {
32
+ var path = "/" + service + "/" + method;
33
+ return new Promise(function (resolve, reject) {
34
+ var resultCallback = function resultCallback(err, res) {
35
+ if (err) {
36
+ reject(err);
37
+ } else {
38
+ resolve(res);
39
+ }
40
+ };
41
+
42
+ var passThrough = function passThrough(argument) {
43
+ return argument;
44
+ };
45
+
46
+ connection.makeUnaryRequest(path, passThrough, passThrough, data, resultCallback);
47
+ });
48
+ };
49
+
50
+ return new ServiceImp({
51
+ request: request
52
+ });
53
+ }
package/es/index.d.ts CHANGED
@@ -1,5 +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
- export { createGrpcService } from './grpc';
5
- export { GrpcPool } from './grpc/GrpcPool';
5
+ export { createRpcClient } from './grpc';
package/es/index.js CHANGED
@@ -1,5 +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
- export { createGrpcService } from './grpc';
5
- export { GrpcPool } from './grpc/GrpcPool';
5
+ export { createRpcClient } 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 };
@@ -1,8 +1,8 @@
1
- import { GrpcService } from './GrpcService';
2
- interface GrpcServiceOptions {
3
- client: string;
4
- requestType: string;
5
- service?: string;
1
+ interface CreateClientProps {
2
+ url: string;
3
+ options?: any;
4
+ ServiceImp: any;
5
+ Grpc: any;
6
6
  }
7
- export declare const createGrpcService: import("pubo-utils/lib/factory").CreateFactory<GrpcServiceOptions, GrpcService>;
7
+ export declare function createRpcClient<T>({ url, options, ServiceImp, Grpc }: CreateClientProps): T;
8
8
  export {};
package/lib/grpc/index.js CHANGED
@@ -19,14 +19,44 @@ var __assign = this && this.__assign || function () {
19
19
  Object.defineProperty(exports, "__esModule", {
20
20
  value: true
21
21
  });
22
- exports.createGrpcService = void 0;
23
-
24
- var pubo_utils_1 = require("pubo-utils");
22
+ exports.createRpcClient = void 0;
23
+
24
+ function createRpcClient(_a) {
25
+ var url = _a.url,
26
+ _b = _a.options,
27
+ options = _b === void 0 ? {} : _b,
28
+ ServiceImp = _a.ServiceImp,
29
+ Grpc = _a.Grpc;
30
+
31
+ var opt = __assign({
32
+ 'grpc.max_send_message_length': -1,
33
+ 'grpc.max_receive_message_length': -1
34
+ }, options);
35
+
36
+ var connection = new Grpc.Client(url, Grpc.credentials.createInsecure(), opt);
37
+
38
+ var request = function request(service, method, data) {
39
+ var path = "/" + service + "/" + method;
40
+ return new Promise(function (resolve, reject) {
41
+ var resultCallback = function resultCallback(err, res) {
42
+ if (err) {
43
+ reject(err);
44
+ } else {
45
+ resolve(res);
46
+ }
47
+ };
48
+
49
+ var passThrough = function passThrough(argument) {
50
+ return argument;
51
+ };
52
+
53
+ connection.makeUnaryRequest(path, passThrough, passThrough, data, resultCallback);
54
+ });
55
+ };
25
56
 
26
- var GrpcService_1 = require("./GrpcService");
57
+ return new ServiceImp({
58
+ request: request
59
+ });
60
+ }
27
61
 
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
- });
62
+ exports.createRpcClient = createRpcClient;
package/lib/index.d.ts CHANGED
@@ -1,5 +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
- export { createGrpcService } from './grpc';
5
- export { GrpcPool } from './grpc/GrpcPool';
5
+ export { createRpcClient } 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", {
@@ -33,18 +42,9 @@ Object.defineProperty(exports, "md5", {
33
42
 
34
43
  var grpc_1 = require("./grpc");
35
44
 
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", {
45
+ Object.defineProperty(exports, "createRpcClient", {
46
46
  enumerable: true,
47
47
  get: function get() {
48
- return GrpcPool_1.GrpcPool;
48
+ return grpc_1.createRpcClient;
49
49
  }
50
50
  });
@@ -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;