pubo-node 1.0.43 → 1.0.45

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,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
+ !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=6)}([function(t,e){t.exports=require("fs")},function(t,e){t.exports=require("pubo-utils")},function(t,e){t.exports=require("pako")},function(t,e){t.exports=require("path")},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 s})),n.d(e,"initRtspVideos",(function(){return O})),n.d(e,"RtspVideosManager",(function(){return g})),n.d(e,"FtpClient",(function(){return E})),n.d(e,"md5",(function(){return k})),n.d(e,"createRpcClient",(function(){return F}));var r=n(0),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)},s=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}(),u=n(3),c=n(4),a=n(1),l=function(){return(l=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),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.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 s},p=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(f(arguments[e]));return t},h=function(){function t(t,e){var n=this;this.eventEmitter=new a.Emitter,this.dog=new a.WatchDog({limit:10,onTimeout:function(){return n.connect()}}),this.url=t,this.options=l({},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=p(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.prototype.destroy=function(){this.eventEmitter.clear(),this.dog.stop(),this.s&&(this.s.kill(),this.s=null)},t}(),y=function(){return(y=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)},d=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},v=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.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 s},m=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(v(arguments[e]));return t},b=function(){function t(){this.path=Object(u.resolve)("resources/temp/videos.json")}return t.prototype.async=function(t){try{Object(r.writeFileSync)(this.path,JSON.stringify(t))}catch(t){console.log(t)}},Object.defineProperty(t.prototype,"data",{get:function(){try{var t=Object(r.readFileSync)(this.path);return console.log(t.toString()),JSON.parse(t.toString())}catch(t){return console.log(t),null}},enumerable:!1,configurable:!0}),t}(),g=function(){function t(t){this._system=[],this._customer=[],this.system=[],this.customer=[],this.storage=new b,this._system=t.map((function(t){return y(y({},t),{system:!0})})),this._customer=this.storage.data||[],this.system=t.map((function(t){var e=t.url,n=d(t,["url"]);return new h(e,n)})),this.customer=this._customer.map((function(t){var e=t.url,n=d(t,["url"]);return new h(e,n)}))}return Object.defineProperty(t.prototype,"list",{get:function(){return m(this.system,this.customer)},enumerable:!1,configurable:!0}),t.prototype.getVideos=function(){return m(this._system,this._customer)},t.prototype.create=function(t){if(this._customer.some((function(e){return e.url===t.url})))throw new Error("该地址已存在");var e=new h(t.url,t);this._customer.push(t),this.customer.push(e),this.storage.async(this._customer)},t.prototype.remove=function(t){if(t<this.system.length)throw new Error("系统配置不可删除");if(t>this.system.length+this.customer.length-1)throw new Error("超限");this._customer.splice(t-this.system.length-1,1),this.customer.splice(t-this.system.length-1,1)[0].destroy(),this.storage.async(this._customer)},t}(),O=function(t){var e=t.app,n=t.server,r=t.videos,o=t.path,i=t.expressWs,s=new g(r);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;s.list[r]&&(o=s.list[r].on("data",(function(e){t.send(e)}))),t.on("close",(function(){o&&s.list[r].cancel(o)}))})),s},w=function(){return(w=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(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function u(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}c((r=r.apply(t,e||[])).next())}))},j=function(t,e){var n,r,o,i,s={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(n)throw new TypeError("Generator is already executing.");for(;s;)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 s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}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,u])}}},x=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},S=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.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 s},P=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(S(arguments[e]));return t},E=function(){function t(t){var e=t.driver,n=x(t,["driver"]);this.queue=new a.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,P([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 _(e,void 0,void 0,(function(){var e;return j(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,P(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(w({},t.options))}))},t}(),q=n(5),k=function(t){return Object(q.createHash)("md5").update(t).digest("hex")},M=function(){return(M=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 F(t){var e=t.url,n=t.options,r=void 0===n?{}:n,o=t.ServiceImp,i=t.Grpc,s=M({"grpc.max_send_message_length":-1,"grpc.max_receive_message_length":-1},r),u=new i.Client(e,i.credentials.createInsecure(),s);return new o({request:function(t,e,n){var r="/"+t+"/"+e;return new Promise((function(t,e){var o=function(t){return t};u.makeUnaryRequest(r,o,o,n,(function(n,r){n?e(n):t(r)}))}))}})}}])}));
package/es/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { JsonStorage } from './storage/json';
2
- export { initRtspVideos } from './rtsp-video';
2
+ export { initRtspVideos, RtspVideosManager } from './rtsp-video';
3
3
  export { FtpClient } from './ftp-client';
4
4
  export { md5 } from './md5';
5
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
+ export { initRtspVideos, RtspVideosManager } from './rtsp-video';
3
3
  export { FtpClient } from './ftp-client';
4
4
  export { md5 } from './md5';
5
5
  export { createRpcClient } from './grpc';
@@ -11,5 +11,17 @@ interface Props {
11
11
  path: string;
12
12
  expressWs?: any;
13
13
  }
14
- export declare const initRtspVideos: ({ app, server, videos, path, expressWs }: Props) => RTSP2Mpeg[];
14
+ export declare class RtspVideosManager {
15
+ private readonly _system;
16
+ private readonly _customer;
17
+ private readonly system;
18
+ private readonly customer;
19
+ private readonly storage;
20
+ constructor(videos: VideoConfig[]);
21
+ get list(): RTSP2Mpeg[];
22
+ getVideos(): VideoConfig[];
23
+ create(conf: VideoConfig): void;
24
+ remove(index: number): void;
25
+ }
26
+ export declare const initRtspVideos: ({ app, server, videos, path, expressWs }: Props) => RtspVideosManager;
15
27
  export {};
@@ -1,3 +1,19 @@
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
+
1
17
  var __rest = this && this.__rest || function (s, e) {
2
18
  var t = {};
3
19
 
@@ -11,19 +27,158 @@ var __rest = this && this.__rest || function (s, e) {
11
27
  return t;
12
28
  };
13
29
 
30
+ var __read = this && this.__read || function (o, n) {
31
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
32
+ if (!m) return o;
33
+ var i = m.call(o),
34
+ r,
35
+ ar = [],
36
+ e;
37
+
38
+ try {
39
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
40
+ ar.push(r.value);
41
+ }
42
+ } catch (error) {
43
+ e = {
44
+ error: error
45
+ };
46
+ } finally {
47
+ try {
48
+ if (r && !r.done && (m = i["return"])) m.call(i);
49
+ } finally {
50
+ if (e) throw e.error;
51
+ }
52
+ }
53
+
54
+ return ar;
55
+ };
56
+
57
+ var __spread = this && this.__spread || function () {
58
+ for (var ar = [], i = 0; i < arguments.length; i++) {
59
+ ar = ar.concat(__read(arguments[i]));
60
+ }
61
+
62
+ return ar;
63
+ };
64
+
65
+ import { readFileSync, writeFileSync } from 'fs';
66
+ import { resolve } from 'path';
14
67
  import { RTSP2Mpeg } from './rtsp2mpeg';
68
+
69
+ var VideoStorage =
70
+ /** @class */
71
+ function () {
72
+ function VideoStorage() {
73
+ this.path = resolve('resources/temp/videos.json');
74
+ }
75
+
76
+ VideoStorage.prototype.async = function (data) {
77
+ try {
78
+ writeFileSync(this.path, JSON.stringify(data));
79
+ } catch (err) {
80
+ console.log(err);
81
+ }
82
+ };
83
+
84
+ Object.defineProperty(VideoStorage.prototype, "data", {
85
+ get: function get() {
86
+ try {
87
+ var buffer = readFileSync(this.path);
88
+ console.log(buffer.toString());
89
+ return JSON.parse(buffer.toString());
90
+ } catch (err) {
91
+ console.log(err);
92
+ return null;
93
+ }
94
+ },
95
+ enumerable: false,
96
+ configurable: true
97
+ });
98
+ return VideoStorage;
99
+ }();
100
+
101
+ var RtspVideosManager =
102
+ /** @class */
103
+ function () {
104
+ function RtspVideosManager(videos) {
105
+ this._system = [];
106
+ this._customer = [];
107
+ this.system = [];
108
+ this.customer = [];
109
+ this.storage = new VideoStorage();
110
+ this._system = videos.map(function (item) {
111
+ return __assign(__assign({}, item), {
112
+ system: true
113
+ });
114
+ });
115
+ this._customer = this.storage.data || [];
116
+ this.system = videos.map(function (_a) {
117
+ var url = _a.url,
118
+ options = __rest(_a, ["url"]);
119
+
120
+ return new RTSP2Mpeg(url, options);
121
+ });
122
+ this.customer = this._customer.map(function (_a) {
123
+ var url = _a.url,
124
+ options = __rest(_a, ["url"]);
125
+
126
+ return new RTSP2Mpeg(url, options);
127
+ });
128
+ }
129
+
130
+ Object.defineProperty(RtspVideosManager.prototype, "list", {
131
+ get: function get() {
132
+ return __spread(this.system, this.customer);
133
+ },
134
+ enumerable: false,
135
+ configurable: true
136
+ });
137
+
138
+ RtspVideosManager.prototype.getVideos = function () {
139
+ return __spread(this._system, this._customer);
140
+ };
141
+
142
+ RtspVideosManager.prototype.create = function (conf) {
143
+ if (this._customer.some(function (item) {
144
+ return item.url === conf.url;
145
+ })) {
146
+ throw new Error('该地址已存在');
147
+ }
148
+
149
+ var video = new RTSP2Mpeg(conf.url, conf);
150
+
151
+ this._customer.push(conf);
152
+
153
+ this.customer.push(video);
154
+ this.storage.async(this._customer);
155
+ };
156
+
157
+ RtspVideosManager.prototype.remove = function (index) {
158
+ if (index < this.system.length) {
159
+ throw new Error('系统配置不可删除');
160
+ } else if (index > this.system.length + this.customer.length - 1) {
161
+ throw new Error('超限');
162
+ }
163
+
164
+ this._customer.splice(index - this.system.length - 1, 1);
165
+
166
+ var video = this.customer.splice(index - this.system.length - 1, 1);
167
+ video[0].destroy();
168
+ this.storage.async(this._customer);
169
+ };
170
+
171
+ return RtspVideosManager;
172
+ }();
173
+
174
+ export { RtspVideosManager };
15
175
  export var initRtspVideos = function initRtspVideos(_a) {
16
176
  var app = _a.app,
17
177
  server = _a.server,
18
178
  videos = _a.videos,
19
179
  path = _a.path,
20
180
  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
- });
181
+ var manager = new RtspVideosManager(videos);
27
182
 
28
183
  if (!app.ws) {
29
184
  expressWs(app, server);
@@ -34,17 +189,17 @@ export var initRtspVideos = function initRtspVideos(_a) {
34
189
  channel = _a === void 0 ? 0 : _a;
35
190
  var listener = null;
36
191
 
37
- if (mpegList[channel]) {
38
- listener = mpegList[channel].on('data', function (chunk) {
192
+ if (manager.list[channel]) {
193
+ listener = manager.list[channel].on('data', function (chunk) {
39
194
  ws.send(chunk);
40
195
  });
41
196
  }
42
197
 
43
198
  ws.on('close', function () {
44
199
  if (listener) {
45
- mpegList[channel].cancel(listener);
200
+ manager.list[channel].cancel(listener);
46
201
  }
47
202
  });
48
203
  });
49
- return mpegList;
204
+ return manager;
50
205
  };
@@ -10,4 +10,5 @@ export declare class RTSP2Mpeg {
10
10
  private connect;
11
11
  on(event: string, cb: (data: any) => void): string;
12
12
  cancel(id: any): void;
13
+ destroy(): void;
13
14
  }
@@ -119,6 +119,16 @@ function () {
119
119
  this.eventEmitter.cancel(id);
120
120
  };
121
121
 
122
+ RTSP2Mpeg.prototype.destroy = function () {
123
+ this.eventEmitter.clear();
124
+ this.dog.stop();
125
+
126
+ if (this.s) {
127
+ this.s.kill();
128
+ this.s = null;
129
+ }
130
+ };
131
+
122
132
  return RTSP2Mpeg;
123
133
  }();
124
134
 
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { JsonStorage } from './storage/json';
2
- export { initRtspVideos } from './rtsp-video';
2
+ export { initRtspVideos, RtspVideosManager } from './rtsp-video';
3
3
  export { FtpClient } from './ftp-client';
4
4
  export { md5 } from './md5';
5
5
  export { createRpcClient } from './grpc';
package/lib/index.js CHANGED
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "initRtspVideos", {
21
21
  return rtsp_video_1.initRtspVideos;
22
22
  }
23
23
  });
24
+ Object.defineProperty(exports, "RtspVideosManager", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return rtsp_video_1.RtspVideosManager;
28
+ }
29
+ });
24
30
 
25
31
  var ftp_client_1 = require("./ftp-client");
26
32
 
@@ -11,5 +11,17 @@ interface Props {
11
11
  path: string;
12
12
  expressWs?: any;
13
13
  }
14
- export declare const initRtspVideos: ({ app, server, videos, path, expressWs }: Props) => RTSP2Mpeg[];
14
+ export declare class RtspVideosManager {
15
+ private readonly _system;
16
+ private readonly _customer;
17
+ private readonly system;
18
+ private readonly customer;
19
+ private readonly storage;
20
+ constructor(videos: VideoConfig[]);
21
+ get list(): RTSP2Mpeg[];
22
+ getVideos(): VideoConfig[];
23
+ create(conf: VideoConfig): void;
24
+ remove(index: number): void;
25
+ }
26
+ export declare const initRtspVideos: ({ app, server, videos, path, expressWs }: Props) => RtspVideosManager;
15
27
  export {};
@@ -1,5 +1,21 @@
1
1
  "use strict";
2
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
+
3
19
  var __rest = this && this.__rest || function (s, e) {
4
20
  var t = {};
5
21
 
@@ -13,25 +29,166 @@ var __rest = this && this.__rest || function (s, e) {
13
29
  return t;
14
30
  };
15
31
 
32
+ var __read = this && this.__read || function (o, n) {
33
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
34
+ if (!m) return o;
35
+ var i = m.call(o),
36
+ r,
37
+ ar = [],
38
+ e;
39
+
40
+ try {
41
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
42
+ ar.push(r.value);
43
+ }
44
+ } catch (error) {
45
+ e = {
46
+ error: error
47
+ };
48
+ } finally {
49
+ try {
50
+ if (r && !r.done && (m = i["return"])) m.call(i);
51
+ } finally {
52
+ if (e) throw e.error;
53
+ }
54
+ }
55
+
56
+ return ar;
57
+ };
58
+
59
+ var __spread = this && this.__spread || function () {
60
+ for (var ar = [], i = 0; i < arguments.length; i++) {
61
+ ar = ar.concat(__read(arguments[i]));
62
+ }
63
+
64
+ return ar;
65
+ };
66
+
16
67
  Object.defineProperty(exports, "__esModule", {
17
68
  value: true
18
69
  });
19
- exports.initRtspVideos = void 0;
70
+ exports.initRtspVideos = exports.RtspVideosManager = void 0;
71
+
72
+ var fs_1 = require("fs");
73
+
74
+ var path_1 = require("path");
20
75
 
21
76
  var rtsp2mpeg_1 = require("./rtsp2mpeg");
22
77
 
78
+ var VideoStorage =
79
+ /** @class */
80
+ function () {
81
+ function VideoStorage() {
82
+ this.path = path_1.resolve('resources/temp/videos.json');
83
+ }
84
+
85
+ VideoStorage.prototype.async = function (data) {
86
+ try {
87
+ fs_1.writeFileSync(this.path, JSON.stringify(data));
88
+ } catch (err) {
89
+ console.log(err);
90
+ }
91
+ };
92
+
93
+ Object.defineProperty(VideoStorage.prototype, "data", {
94
+ get: function get() {
95
+ try {
96
+ var buffer = fs_1.readFileSync(this.path);
97
+ console.log(buffer.toString());
98
+ return JSON.parse(buffer.toString());
99
+ } catch (err) {
100
+ console.log(err);
101
+ return null;
102
+ }
103
+ },
104
+ enumerable: false,
105
+ configurable: true
106
+ });
107
+ return VideoStorage;
108
+ }();
109
+
110
+ var RtspVideosManager =
111
+ /** @class */
112
+ function () {
113
+ function RtspVideosManager(videos) {
114
+ this._system = [];
115
+ this._customer = [];
116
+ this.system = [];
117
+ this.customer = [];
118
+ this.storage = new VideoStorage();
119
+ this._system = videos.map(function (item) {
120
+ return __assign(__assign({}, item), {
121
+ system: true
122
+ });
123
+ });
124
+ this._customer = this.storage.data || [];
125
+ this.system = videos.map(function (_a) {
126
+ var url = _a.url,
127
+ options = __rest(_a, ["url"]);
128
+
129
+ return new rtsp2mpeg_1.RTSP2Mpeg(url, options);
130
+ });
131
+ this.customer = this._customer.map(function (_a) {
132
+ var url = _a.url,
133
+ options = __rest(_a, ["url"]);
134
+
135
+ return new rtsp2mpeg_1.RTSP2Mpeg(url, options);
136
+ });
137
+ }
138
+
139
+ Object.defineProperty(RtspVideosManager.prototype, "list", {
140
+ get: function get() {
141
+ return __spread(this.system, this.customer);
142
+ },
143
+ enumerable: false,
144
+ configurable: true
145
+ });
146
+
147
+ RtspVideosManager.prototype.getVideos = function () {
148
+ return __spread(this._system, this._customer);
149
+ };
150
+
151
+ RtspVideosManager.prototype.create = function (conf) {
152
+ if (this._customer.some(function (item) {
153
+ return item.url === conf.url;
154
+ })) {
155
+ throw new Error('该地址已存在');
156
+ }
157
+
158
+ var video = new rtsp2mpeg_1.RTSP2Mpeg(conf.url, conf);
159
+
160
+ this._customer.push(conf);
161
+
162
+ this.customer.push(video);
163
+ this.storage.async(this._customer);
164
+ };
165
+
166
+ RtspVideosManager.prototype.remove = function (index) {
167
+ if (index < this.system.length) {
168
+ throw new Error('系统配置不可删除');
169
+ } else if (index > this.system.length + this.customer.length - 1) {
170
+ throw new Error('超限');
171
+ }
172
+
173
+ this._customer.splice(index - this.system.length - 1, 1);
174
+
175
+ var video = this.customer.splice(index - this.system.length - 1, 1);
176
+ video[0].destroy();
177
+ this.storage.async(this._customer);
178
+ };
179
+
180
+ return RtspVideosManager;
181
+ }();
182
+
183
+ exports.RtspVideosManager = RtspVideosManager;
184
+
23
185
  exports.initRtspVideos = function (_a) {
24
186
  var app = _a.app,
25
187
  server = _a.server,
26
188
  videos = _a.videos,
27
189
  path = _a.path,
28
190
  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
- });
191
+ var manager = new RtspVideosManager(videos);
35
192
 
36
193
  if (!app.ws) {
37
194
  expressWs(app, server);
@@ -42,17 +199,17 @@ exports.initRtspVideos = function (_a) {
42
199
  channel = _a === void 0 ? 0 : _a;
43
200
  var listener = null;
44
201
 
45
- if (mpegList[channel]) {
46
- listener = mpegList[channel].on('data', function (chunk) {
202
+ if (manager.list[channel]) {
203
+ listener = manager.list[channel].on('data', function (chunk) {
47
204
  ws.send(chunk);
48
205
  });
49
206
  }
50
207
 
51
208
  ws.on('close', function () {
52
209
  if (listener) {
53
- mpegList[channel].cancel(listener);
210
+ manager.list[channel].cancel(listener);
54
211
  }
55
212
  });
56
213
  });
57
- return mpegList;
214
+ return manager;
58
215
  };
@@ -10,4 +10,5 @@ export declare class RTSP2Mpeg {
10
10
  private connect;
11
11
  on(event: string, cb: (data: any) => void): string;
12
12
  cancel(id: any): void;
13
+ destroy(): void;
13
14
  }
@@ -127,6 +127,16 @@ function () {
127
127
  this.eventEmitter.cancel(id);
128
128
  };
129
129
 
130
+ RTSP2Mpeg.prototype.destroy = function () {
131
+ this.eventEmitter.clear();
132
+ this.dog.stop();
133
+
134
+ if (this.s) {
135
+ this.s.kill();
136
+ this.s = null;
137
+ }
138
+ };
139
+
130
140
  return RTSP2Mpeg;
131
141
  }();
132
142
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-node",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -24,5 +24,5 @@
24
24
  "pako": "^2.0.4",
25
25
  "pubo-utils": "^1.0.43"
26
26
  },
27
- "gitHead": "648dc63c3e9866e0288aa6237c3c2df83235469b"
27
+ "gitHead": "42fb9c31d4284db451b31f1536ff973d9e9289ef"
28
28
  }