pubo-node 1.0.70 → 1.0.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pubo-node.js +1 -1
- package/es/file-system/index.d.ts +1 -0
- package/es/file-system/index.js +2 -1
- package/es/grpc/index.d.ts +3 -1
- package/es/grpc/index.js +4 -2
- package/lib/file-system/index.d.ts +1 -0
- package/lib/file-system/index.js +2 -1
- package/lib/grpc/index.d.ts +3 -1
- package/lib/grpc/index.js +4 -2
- package/package.json +2 -2
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,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{FtpClient:()=>x,FtpClientPool:()=>E,JsonStorage:()=>i,PuboFileSystem:()=>J,RtspVideosManager:()=>m,createRpcClient:()=>A,initRtspVideos:()=>b,md5:()=>k});const n=require("fs"),r=require("pako");var o=function(){return o=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},o.apply(this,arguments)},i=function(){function t(t){this._state={},this.path=t,this.init()}return t.prototype.init=function(){try{var t=(0,n.readFileSync)(this.path),e=r.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=r.deflate(JSON.stringify(t)),o=Buffer.from(e);(0,n.writeFile)(this.path,o,(function(t){return t&&console.log(t)})),this._state=t},enumerable:!1,configurable:!0}),t.prototype.get=function(t){return t?this.state[t]:o({},this.state)},t.prototype.set=function(t,e){var n=o({},this.state);n[t]=e,this.state=n},t.prototype.merge=function(t){this.state=o(o({},this._state),t)},t}();const s=require("path"),c=require("child_process"),u=require("pubo-utils");var 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},a.apply(this,arguments)},l=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},h=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},f=function(){function t(t,e){var n=this;this.eventEmitter=new u.Emitter,this.dog=new u.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: ".concat(this.url," try to reconnect;")),this.s.kill(),this.s=null)},t.prototype.connect=function(){var t=this;this.closeOld();var e=h(h(h(h([],l(this.options.input),!1),[this.url],!1),l(this.options.output),!1),["-"],!1);this.s=(0,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}(),p=function(){return p=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},p.apply(this,arguments)},y=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},d=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},v=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},g=function(){function t(){this.path=(0,s.resolve)("resources/temp/videos.json")}return t.prototype.async=function(t){try{(0,n.writeFileSync)(this.path,JSON.stringify(t))}catch(t){console.log(t)}},Object.defineProperty(t.prototype,"data",{get:function(){try{var t=(0,n.readFileSync)(this.path);return console.log(t.toString()),JSON.parse(t.toString())}catch(t){return console.log(t),null}},enumerable:!1,configurable:!0}),t}(),m=function(){function t(t){this._system=[],this._customer=[],this.system=[],this.customer=[],this.storage=new g,this._system=t.map((function(t){return p(p({},t),{system:!0})})),this._customer=this.storage.data||[],this.system=t.map((function(t){var e=t.url,n=y(t,["url"]);return new f(e,n)})),this.customer=this._customer.map((function(t){var e=t.url,n=y(t,["url"]);return new f(e,n)}))}return Object.defineProperty(t.prototype,"list",{get:function(){return v(v([],d(this.system),!1),d(this.customer),!1)},enumerable:!1,configurable:!0}),t.prototype.getVideos=function(){return v(v([],d(this._system),!1),d(this._customer),!1)},t.prototype.create=function(t){if(this._customer.some((function(e){return e.url===t.url})))throw new Error("该地址已存在");var e=new f(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}(),b=function(t){var e=t.app,n=t.server,r=t.videos,o=t.path,i=t.expressWs,s=new m(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]&&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},w.apply(this,arguments)},O=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function c(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,c)}u((r=r.apply(t,e||[])).next())}))},S=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:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(u){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return s.label++,{value:c[1],done:!1};case 5:s.label++,r=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){s.label=c[1];break}if(6===c[0]&&s.label<o[1]){s.label=o[1],o=c;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(c);break}o[2]&&s.ops.pop(),s.trys.pop();continue}c=e.call(t,s)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}},j=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},_=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(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},x=function(){function t(t){var e=t.driver,n=j(t,["driver"]);this.state={running:!1,connected:!1,destroyed:!1,connecting:!1},this._len=0,this.id=(0,u.random)(),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 Object.defineProperty(t.prototype,"len",{get:function(){return this._len},set:function(t){this._len=t,this._len<1&&this.close()},enumerable:!1,configurable:!0}),t.prototype.connect=function(){return O(this,void 0,void 0,(function(){var t=this;return S(this,(function(e){switch(e.label){case 0:return this.client||(this.client=new this.driver),this.state.destroyed=!1,this.state.connecting?[4,(0,u.waitFor)((function(){return t.state.connected}),{checkTime:1e3,timeout:1e4})]:[3,2];case 1:return e.sent(),[2,"connected"];case 2:return this.state.connecting=!0,[2,new Promise((function(e,n){t.client.once("ready",(function(){t.state.connected=!0,e("connected"),t.state.connecting=!1})),t.client.once("error",(function(e){n(e),t.close()})),t.client.connect(w({},t.options))}))]}}))}))},t.prototype.close=function(){this.client.end(),this.state.connected=!1,this.state.destroyed=!0,this.state.connecting=!1,this.client=null},t.prototype.run=function(t){var e=t.fn,n=t.args;return O(this,void 0,void 0,(function(){var t=this;return S(this,(function(r){switch(r.label){case 0:return this.len+=1,this.state.connected?[3,2]:[4,this.connect()];case 1:r.sent(),r.label=2;case 2:return this.state.running?[4,(0,u.waitFor)((function(){return!t.state.running}),{checkTime:1e3,timeout:6e6})]:[3,4];case 3:r.sent(),r.label=4;case 4:return this.state.running=!0,[2,new Promise((function(r,o){var i;(i=t.client)[e].apply(i,P(P([],_(n),!1),[function(t,e){t?o(t):r(e)}],!1))}))]}}))}))},t.prototype.bind=function(t){var e=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return O(e,void 0,void 0,(function(){var e;return S(this,(function(r){switch(r.label){case 0:return[4,this.run({fn:t,args:n})];case 1:return e=r.sent(),this.state.running=!1,this.len-=1,[2,e]}}))}))}},t.prototype.get=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return O(this,void 0,void 0,(function(){var e,n,r=this;return S(this,(function(o){switch(o.label){case 0:return e=Buffer.alloc(0),[4,this.run({fn:"get",args:t})];case 1:return n=o.sent(),[2,new Promise((function(t){n.on("data",(function(t){e=Buffer.concat([e,t],e.byteLength+t.byteLength)})),n.on("end",(function(){t(e),r.state.running=!1,r.len-=1}))}))]}}))}))},t}(),E=function(){function t(t){var e=t.maxConnection,n=void 0===e?5:e,r=j(t,["maxConnection"]);this.pool=[],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.options=r,this.maxConnection=n}return Object.defineProperty(t.prototype,"len",{get:function(){return this.pool.length},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"client",{get:function(){if(this.pool.length<this.maxConnection){var t=new x(this.options);return this.pool.push(t),t}return this.pool.sort((function(t,e){return t.len-e.len})),this.pool[0]},enumerable:!1,configurable:!0}),t.prototype.bind=function(t){var e=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return O(e,void 0,void 0,(function(){var e,r,o;return S(this,(function(i){switch(i.label){case 0:return[4,(e=this.client)[t].apply(e,P([],_(n),!1))];case 1:return r=i.sent(),e.len<1&&(o=this.pool.findIndex((function(t){return t.id===e.id})),this.pool.splice(o,1)),[2,r]}}))}))}},t}();const F=require("crypto");var k=function(t){return(0,F.createHash)("md5").update(t).digest("hex")},q=function(){return q=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},q.apply(this,arguments)};function A(t){var e=t.url,n=t.options,r=void 0===n?{}:n,o=t.ServiceImp,i=t.Grpc,s=q({"grpc.max_send_message_length":-1,"grpc.max_receive_message_length":-1},r),c=new i.Client(e,i.credentials.createInsecure(),s);return new o({request:function(t,e,n){var r="/".concat(t,"/").concat(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)}))}))}})}var C=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},T=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},I=function(t){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return new Promise((function(n,r){t.apply(void 0,T(T([],C(e),!1),[function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];t&&r(t),e.length<2?n(e[0]):n(T([],C(e),!1))}],!1))}))}},J={read:I(n.read),readFile:I(n.readFile),writeFile:I(n.writeFile),readdir:I(n.readdir),open:I(n.open),close:I(n.close),write:I(n.write)};return e})()));
|
|
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,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{FtpClient:()=>x,FtpClientPool:()=>E,JsonStorage:()=>i,PuboFileSystem:()=>J,RtspVideosManager:()=>m,createRpcClient:()=>A,initRtspVideos:()=>b,md5:()=>k});const n=require("fs"),r=require("pako");var o=function(){return o=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},o.apply(this,arguments)},i=function(){function t(t){this._state={},this.path=t,this.init()}return t.prototype.init=function(){try{var t=(0,n.readFileSync)(this.path),e=r.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=r.deflate(JSON.stringify(t)),o=Buffer.from(e);(0,n.writeFile)(this.path,o,(function(t){return t&&console.log(t)})),this._state=t},enumerable:!1,configurable:!0}),t.prototype.get=function(t){return t?this.state[t]:o({},this.state)},t.prototype.set=function(t,e){var n=o({},this.state);n[t]=e,this.state=n},t.prototype.merge=function(t){this.state=o(o({},this._state),t)},t}();const s=require("path"),c=require("child_process"),a=require("pubo-utils");var u=function(){return u=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},u.apply(this,arguments)},l=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},h=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},f=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=u({},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: ".concat(this.url," try to reconnect;")),this.s.kill(),this.s=null)},t.prototype.connect=function(){var t=this;this.closeOld();var e=h(h(h(h([],l(this.options.input),!1),[this.url],!1),l(this.options.output),!1),["-"],!1);this.s=(0,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}(),p=function(){return p=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},p.apply(this,arguments)},y=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},d=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},v=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},g=function(){function t(){this.path=(0,s.resolve)("resources/temp/videos.json")}return t.prototype.async=function(t){try{(0,n.writeFileSync)(this.path,JSON.stringify(t))}catch(t){console.log(t)}},Object.defineProperty(t.prototype,"data",{get:function(){try{var t=(0,n.readFileSync)(this.path);return console.log(t.toString()),JSON.parse(t.toString())}catch(t){return console.log(t),null}},enumerable:!1,configurable:!0}),t}(),m=function(){function t(t){this._system=[],this._customer=[],this.system=[],this.customer=[],this.storage=new g,this._system=t.map((function(t){return p(p({},t),{system:!0})})),this._customer=this.storage.data||[],this.system=t.map((function(t){var e=t.url,n=y(t,["url"]);return new f(e,n)})),this.customer=this._customer.map((function(t){var e=t.url,n=y(t,["url"]);return new f(e,n)}))}return Object.defineProperty(t.prototype,"list",{get:function(){return v(v([],d(this.system),!1),d(this.customer),!1)},enumerable:!1,configurable:!0}),t.prototype.getVideos=function(){return v(v([],d(this._system),!1),d(this._customer),!1)},t.prototype.create=function(t){if(this._customer.some((function(e){return e.url===t.url})))throw new Error("该地址已存在");var e=new f(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}(),b=function(t){var e=t.app,n=t.server,r=t.videos,o=t.path,i=t.expressWs,s=new m(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]&&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},w.apply(this,arguments)},O=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,c)}a((r=r.apply(t,e||[])).next())}))},S=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:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return s.label++,{value:c[1],done:!1};case 5:s.label++,r=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){s.label=c[1];break}if(6===c[0]&&s.label<o[1]){s.label=o[1],o=c;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(c);break}o[2]&&s.ops.pop(),s.trys.pop();continue}c=e.call(t,s)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}},j=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},_=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(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},x=function(){function t(t){var e=t.driver,n=j(t,["driver"]);this.state={running:!1,connected:!1,destroyed:!1,connecting:!1},this._len=0,this.id=(0,a.random)(),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 Object.defineProperty(t.prototype,"len",{get:function(){return this._len},set:function(t){this._len=t,this._len<1&&this.close()},enumerable:!1,configurable:!0}),t.prototype.connect=function(){return O(this,void 0,void 0,(function(){var t=this;return S(this,(function(e){switch(e.label){case 0:return this.client||(this.client=new this.driver),this.state.destroyed=!1,this.state.connecting?[4,(0,a.waitFor)((function(){return t.state.connected}),{checkTime:1e3,timeout:1e4})]:[3,2];case 1:return e.sent(),[2,"connected"];case 2:return this.state.connecting=!0,[2,new Promise((function(e,n){t.client.once("ready",(function(){t.state.connected=!0,e("connected"),t.state.connecting=!1})),t.client.once("error",(function(e){n(e),t.close()})),t.client.connect(w({},t.options))}))]}}))}))},t.prototype.close=function(){this.client.end(),this.state.connected=!1,this.state.destroyed=!0,this.state.connecting=!1,this.client=null},t.prototype.run=function(t){var e=t.fn,n=t.args;return O(this,void 0,void 0,(function(){var t=this;return S(this,(function(r){switch(r.label){case 0:return this.len+=1,this.state.connected?[3,2]:[4,this.connect()];case 1:r.sent(),r.label=2;case 2:return this.state.running?[4,(0,a.waitFor)((function(){return!t.state.running}),{checkTime:1e3,timeout:6e6})]:[3,4];case 3:r.sent(),r.label=4;case 4:return this.state.running=!0,[2,new Promise((function(r,o){var i;(i=t.client)[e].apply(i,P(P([],_(n),!1),[function(t,e){t?o(t):r(e)}],!1))}))]}}))}))},t.prototype.bind=function(t){var e=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return O(e,void 0,void 0,(function(){var e;return S(this,(function(r){switch(r.label){case 0:return[4,this.run({fn:t,args:n})];case 1:return e=r.sent(),this.state.running=!1,this.len-=1,[2,e]}}))}))}},t.prototype.get=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return O(this,void 0,void 0,(function(){var e,n,r=this;return S(this,(function(o){switch(o.label){case 0:return e=Buffer.alloc(0),[4,this.run({fn:"get",args:t})];case 1:return n=o.sent(),[2,new Promise((function(t){n.on("data",(function(t){e=Buffer.concat([e,t],e.byteLength+t.byteLength)})),n.on("end",(function(){t(e),r.state.running=!1,r.len-=1}))}))]}}))}))},t}(),E=function(){function t(t){var e=t.maxConnection,n=void 0===e?5:e,r=j(t,["maxConnection"]);this.pool=[],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.options=r,this.maxConnection=n}return Object.defineProperty(t.prototype,"len",{get:function(){return this.pool.length},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"client",{get:function(){if(this.pool.length<this.maxConnection){var t=new x(this.options);return this.pool.push(t),t}return this.pool.sort((function(t,e){return t.len-e.len})),this.pool[0]},enumerable:!1,configurable:!0}),t.prototype.bind=function(t){var e=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return O(e,void 0,void 0,(function(){var e,r,o;return S(this,(function(i){switch(i.label){case 0:return[4,(e=this.client)[t].apply(e,P([],_(n),!1))];case 1:return r=i.sent(),e.len<1&&(o=this.pool.findIndex((function(t){return t.id===e.id})),this.pool.splice(o,1)),[2,r]}}))}))}},t}();const F=require("crypto");var k=function(t){return(0,F.createHash)("md5").update(t).digest("hex")},q=function(){return q=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},q.apply(this,arguments)};function A(t){var e=t.url,n=t.options,r=void 0===n?{}:n,o=t.ServiceImp,i=t.Grpc,s=t.cert,c=q({"grpc.max_send_message_length":-1,"grpc.max_receive_message_length":-1},r),a=s?i.credentials.createSsl(s):i.credentials.createInsecure(),u=new i.Client(e,a,c);return new o({request:function(t,e,n){var r="/".concat(t,"/").concat(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)}))}))}})}var C=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},T=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},I=function(t){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return new Promise((function(n,r){t.apply(void 0,T(T([],C(e),!1),[function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];t&&r(t),e.length<2?n(e[0]):n(T([],C(e),!1))}],!1))}))}},J={read:I(n.read),readFile:I(n.readFile),writeFile:I(n.writeFile),readdir:I(n.readdir),open:I(n.open),close:I(n.close),write:I(n.write),stat:I(n.stat)};return e})()));
|
|
@@ -6,6 +6,7 @@ import type EventEmitter from 'events';
|
|
|
6
6
|
import * as fs from 'fs';
|
|
7
7
|
interface PuboFileSystemInterface {
|
|
8
8
|
read: <TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer?: TBuffer, offset?: number, length?: number, position?: fs.ReadPosition | null) => Promise<[number, TBuffer]>;
|
|
9
|
+
stat: (path: fs.PathLike) => Promise<fs.Stats>;
|
|
9
10
|
readFile: (path: fs.PathOrFileDescriptor, options?: ({
|
|
10
11
|
encoding?: null;
|
|
11
12
|
flag?: string;
|
package/es/file-system/index.js
CHANGED
|
@@ -61,5 +61,6 @@ export var PuboFileSystem = {
|
|
|
61
61
|
readdir: callbackToPromise(fs.readdir),
|
|
62
62
|
open: callbackToPromise(fs.open),
|
|
63
63
|
close: callbackToPromise(fs.close),
|
|
64
|
-
write: callbackToPromise(fs.write)
|
|
64
|
+
write: callbackToPromise(fs.write),
|
|
65
|
+
stat: callbackToPromise(fs.stat)
|
|
65
66
|
};
|
package/es/grpc/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
interface CreateClientProps {
|
|
2
3
|
url: string;
|
|
3
4
|
options?: any;
|
|
4
5
|
ServiceImp: any;
|
|
5
6
|
Grpc: any;
|
|
7
|
+
cert?: Buffer;
|
|
6
8
|
}
|
|
7
|
-
export declare function createRpcClient<T>({ url, options, ServiceImp, Grpc }: CreateClientProps): T;
|
|
9
|
+
export declare function createRpcClient<T>({ url, options, ServiceImp, Grpc, cert }: CreateClientProps): T;
|
|
8
10
|
export {};
|
package/es/grpc/index.js
CHANGED
|
@@ -13,12 +13,14 @@ export function createRpcClient(_a) {
|
|
|
13
13
|
_b = _a.options,
|
|
14
14
|
options = _b === void 0 ? {} : _b,
|
|
15
15
|
ServiceImp = _a.ServiceImp,
|
|
16
|
-
Grpc = _a.Grpc
|
|
16
|
+
Grpc = _a.Grpc,
|
|
17
|
+
cert = _a.cert;
|
|
17
18
|
var opt = __assign({
|
|
18
19
|
'grpc.max_send_message_length': -1,
|
|
19
20
|
'grpc.max_receive_message_length': -1
|
|
20
21
|
}, options);
|
|
21
|
-
var
|
|
22
|
+
var credentials = cert ? Grpc.credentials.createSsl(cert) : Grpc.credentials.createInsecure();
|
|
23
|
+
var connection = new Grpc.Client(url, credentials, opt);
|
|
22
24
|
var request = function request(service, method, data) {
|
|
23
25
|
var path = "/".concat(service, "/").concat(method);
|
|
24
26
|
return new Promise(function (resolve, reject) {
|
|
@@ -6,6 +6,7 @@ import type EventEmitter from 'events';
|
|
|
6
6
|
import * as fs from 'fs';
|
|
7
7
|
interface PuboFileSystemInterface {
|
|
8
8
|
read: <TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer?: TBuffer, offset?: number, length?: number, position?: fs.ReadPosition | null) => Promise<[number, TBuffer]>;
|
|
9
|
+
stat: (path: fs.PathLike) => Promise<fs.Stats>;
|
|
9
10
|
readFile: (path: fs.PathOrFileDescriptor, options?: ({
|
|
10
11
|
encoding?: null;
|
|
11
12
|
flag?: string;
|
package/lib/file-system/index.js
CHANGED
|
@@ -98,5 +98,6 @@ exports.PuboFileSystem = {
|
|
|
98
98
|
readdir: callbackToPromise(fs.readdir),
|
|
99
99
|
open: callbackToPromise(fs.open),
|
|
100
100
|
close: callbackToPromise(fs.close),
|
|
101
|
-
write: callbackToPromise(fs.write)
|
|
101
|
+
write: callbackToPromise(fs.write),
|
|
102
|
+
stat: callbackToPromise(fs.stat)
|
|
102
103
|
};
|
package/lib/grpc/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
interface CreateClientProps {
|
|
2
3
|
url: string;
|
|
3
4
|
options?: any;
|
|
4
5
|
ServiceImp: any;
|
|
5
6
|
Grpc: any;
|
|
7
|
+
cert?: Buffer;
|
|
6
8
|
}
|
|
7
|
-
export declare function createRpcClient<T>({ url, options, ServiceImp, Grpc }: CreateClientProps): T;
|
|
9
|
+
export declare function createRpcClient<T>({ url, options, ServiceImp, Grpc, cert }: CreateClientProps): T;
|
|
8
10
|
export {};
|
package/lib/grpc/index.js
CHANGED
|
@@ -19,12 +19,14 @@ function createRpcClient(_a) {
|
|
|
19
19
|
_b = _a.options,
|
|
20
20
|
options = _b === void 0 ? {} : _b,
|
|
21
21
|
ServiceImp = _a.ServiceImp,
|
|
22
|
-
Grpc = _a.Grpc
|
|
22
|
+
Grpc = _a.Grpc,
|
|
23
|
+
cert = _a.cert;
|
|
23
24
|
var opt = __assign({
|
|
24
25
|
'grpc.max_send_message_length': -1,
|
|
25
26
|
'grpc.max_receive_message_length': -1
|
|
26
27
|
}, options);
|
|
27
|
-
var
|
|
28
|
+
var credentials = cert ? Grpc.credentials.createSsl(cert) : Grpc.credentials.createInsecure();
|
|
29
|
+
var connection = new Grpc.Client(url, credentials, opt);
|
|
28
30
|
var request = function request(service, method, data) {
|
|
29
31
|
var path = "/".concat(service, "/").concat(method);
|
|
30
32
|
return new Promise(function (resolve, reject) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.74",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"pako": "^2.0.4",
|
|
24
24
|
"pubo-utils": "^1.0.69"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "431d9611aca301aa3f01286a41617384e62d2bf2"
|
|
27
27
|
}
|