pubo-node 1.0.33 → 1.0.34
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/grpc/Grpc.d.ts +15 -0
- package/es/grpc/Grpc.js +52 -0
- package/es/grpc/GrpcPool.d.ts +14 -0
- package/es/grpc/GrpcPool.js +43 -0
- package/es/grpc/GrpcService.d.ts +13 -0
- package/es/grpc/GrpcService.js +295 -0
- package/es/grpc/index.d.ts +8 -0
- package/es/grpc/index.js +23 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +3 -2
- package/lib/grpc/Grpc.d.ts +15 -0
- package/lib/grpc/Grpc.js +93 -0
- package/lib/grpc/GrpcPool.d.ts +14 -0
- package/lib/grpc/GrpcPool.js +50 -0
- package/lib/grpc/GrpcService.d.ts +13 -0
- package/lib/grpc/GrpcService.js +302 -0
- package/lib/grpc/index.d.ts +8 -0
- package/lib/grpc/index.js +32 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +18 -9
- package/package.json +4 -3
- package/es/rtsp-video/index.d.ts +0 -15
- package/es/rtsp-video/index.js +0 -50
- package/es/rtsp-video/rtsp2mpeg.d.ts +0 -13
- package/es/rtsp-video/rtsp2mpeg.js +0 -125
- package/lib/rtsp-video/index.d.ts +0 -15
- package/lib/rtsp-video/index.js +0 -58
- package/lib/rtsp-video/rtsp2mpeg.d.ts +0 -13
- package/lib/rtsp-video/rtsp2mpeg.js +0 -133
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}));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")}}])}));
|
|
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}))}))}])}));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface GrpcConfig {
|
|
2
|
+
root: string;
|
|
3
|
+
url: string;
|
|
4
|
+
options?: any;
|
|
5
|
+
}
|
|
6
|
+
export declare class Grpc {
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly options;
|
|
9
|
+
private instance;
|
|
10
|
+
private readonly RpcClient;
|
|
11
|
+
common: any;
|
|
12
|
+
proto: any;
|
|
13
|
+
constructor(conf: GrpcConfig);
|
|
14
|
+
get client(): any;
|
|
15
|
+
}
|
package/es/grpc/Grpc.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
import * as grpc from 'grpc';
|
|
18
|
+
|
|
19
|
+
var Grpc =
|
|
20
|
+
/** @class */
|
|
21
|
+
function () {
|
|
22
|
+
function Grpc(conf) {
|
|
23
|
+
this.options = {
|
|
24
|
+
'grpc.max_send_message_length': -1,
|
|
25
|
+
'grpc.max_receive_message_length': -1
|
|
26
|
+
};
|
|
27
|
+
this.instance = null;
|
|
28
|
+
this.config = conf;
|
|
29
|
+
this.common = require(this.config.root + "/common_pb"); // eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
30
|
+
|
|
31
|
+
this.RpcClient = require(this.config.root + "/service_grpc_pb").RpcClient;
|
|
32
|
+
this.proto = global.proto;
|
|
33
|
+
global.proto = {};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Object.defineProperty(Grpc.prototype, "client", {
|
|
37
|
+
get: function get() {
|
|
38
|
+
if (!this.instance) {
|
|
39
|
+
var options = __assign(__assign({}, this.options), this.config.options || {});
|
|
40
|
+
|
|
41
|
+
this.instance = new this.RpcClient(this.config.url, grpc.credentials.createInsecure(), options);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return this.instance;
|
|
45
|
+
},
|
|
46
|
+
enumerable: false,
|
|
47
|
+
configurable: true
|
|
48
|
+
});
|
|
49
|
+
return Grpc;
|
|
50
|
+
}();
|
|
51
|
+
|
|
52
|
+
export { Grpc };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GrpcConfig } from './Grpc';
|
|
2
|
+
import { Grpc } from './Grpc';
|
|
3
|
+
export declare type GrpcPoolType = (GrpcConfig & {
|
|
4
|
+
id: any;
|
|
5
|
+
})[];
|
|
6
|
+
export declare class GrpcPool {
|
|
7
|
+
static pool: GrpcPoolType;
|
|
8
|
+
private static instance;
|
|
9
|
+
static getPool: () => GrpcPool;
|
|
10
|
+
static setPool: (pool: GrpcPoolType) => void;
|
|
11
|
+
private readonly list;
|
|
12
|
+
constructor(list: GrpcPoolType);
|
|
13
|
+
getGrpc(id: string): Grpc | undefined;
|
|
14
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Grpc } from './Grpc';
|
|
2
|
+
|
|
3
|
+
var GrpcPool =
|
|
4
|
+
/** @class */
|
|
5
|
+
function () {
|
|
6
|
+
function GrpcPool(list) {
|
|
7
|
+
this.list = [];
|
|
8
|
+
this.list = list.map(function (conf) {
|
|
9
|
+
return {
|
|
10
|
+
id: conf.id,
|
|
11
|
+
grpc: new Grpc(conf)
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
GrpcPool.prototype.getGrpc = function (id) {
|
|
17
|
+
var _a;
|
|
18
|
+
|
|
19
|
+
return (_a = this.list.find(function (item) {
|
|
20
|
+
return item.id === id;
|
|
21
|
+
})) === null || _a === void 0 ? void 0 : _a.grpc;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
GrpcPool.pool = [];
|
|
25
|
+
GrpcPool.instance = null;
|
|
26
|
+
|
|
27
|
+
GrpcPool.getPool = function () {
|
|
28
|
+
if (!GrpcPool.instance) {
|
|
29
|
+
GrpcPool.instance = new GrpcPool(GrpcPool.pool);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return GrpcPool.instance;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
GrpcPool.setPool = function (pool) {
|
|
36
|
+
GrpcPool.pool = pool;
|
|
37
|
+
GrpcPool.instance = new GrpcPool(GrpcPool.pool);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return GrpcPool;
|
|
41
|
+
}();
|
|
42
|
+
|
|
43
|
+
export { GrpcPool };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface GrpcServiceConfig {
|
|
2
|
+
client: string;
|
|
3
|
+
serviceName: string;
|
|
4
|
+
requestType: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class GrpcService {
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly grpc?;
|
|
9
|
+
private readonly promise;
|
|
10
|
+
constructor(conf: GrpcServiceConfig);
|
|
11
|
+
serializer(requestType: string, payload?: any): any;
|
|
12
|
+
send(request?: any): Promise<any>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function step(result) {
|
|
26
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
34
|
+
var _ = {
|
|
35
|
+
label: 0,
|
|
36
|
+
sent: function sent() {
|
|
37
|
+
if (t[0] & 1) throw t[1];
|
|
38
|
+
return t[1];
|
|
39
|
+
},
|
|
40
|
+
trys: [],
|
|
41
|
+
ops: []
|
|
42
|
+
},
|
|
43
|
+
f,
|
|
44
|
+
y,
|
|
45
|
+
t,
|
|
46
|
+
g;
|
|
47
|
+
return g = {
|
|
48
|
+
next: verb(0),
|
|
49
|
+
"throw": verb(1),
|
|
50
|
+
"return": verb(2)
|
|
51
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
52
|
+
return this;
|
|
53
|
+
}), g;
|
|
54
|
+
|
|
55
|
+
function verb(n) {
|
|
56
|
+
return function (v) {
|
|
57
|
+
return step([n, v]);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function step(op) {
|
|
62
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
63
|
+
|
|
64
|
+
while (_) {
|
|
65
|
+
try {
|
|
66
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
67
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
68
|
+
|
|
69
|
+
switch (op[0]) {
|
|
70
|
+
case 0:
|
|
71
|
+
case 1:
|
|
72
|
+
t = op;
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case 4:
|
|
76
|
+
_.label++;
|
|
77
|
+
return {
|
|
78
|
+
value: op[1],
|
|
79
|
+
done: false
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
case 5:
|
|
83
|
+
_.label++;
|
|
84
|
+
y = op[1];
|
|
85
|
+
op = [0];
|
|
86
|
+
continue;
|
|
87
|
+
|
|
88
|
+
case 7:
|
|
89
|
+
op = _.ops.pop();
|
|
90
|
+
|
|
91
|
+
_.trys.pop();
|
|
92
|
+
|
|
93
|
+
continue;
|
|
94
|
+
|
|
95
|
+
default:
|
|
96
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
97
|
+
_ = 0;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
102
|
+
_.label = op[1];
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
107
|
+
_.label = t[1];
|
|
108
|
+
t = op;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (t && _.label < t[2]) {
|
|
113
|
+
_.label = t[2];
|
|
114
|
+
|
|
115
|
+
_.ops.push(op);
|
|
116
|
+
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (t[2]) _.ops.pop();
|
|
121
|
+
|
|
122
|
+
_.trys.pop();
|
|
123
|
+
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
op = body.call(thisArg, _);
|
|
128
|
+
} catch (e) {
|
|
129
|
+
op = [6, e];
|
|
130
|
+
y = 0;
|
|
131
|
+
} finally {
|
|
132
|
+
f = t = 0;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (op[0] & 5) throw op[1];
|
|
137
|
+
return {
|
|
138
|
+
value: op[0] ? op[1] : void 0,
|
|
139
|
+
done: true
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
var __read = this && this.__read || function (o, n) {
|
|
145
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
146
|
+
if (!m) return o;
|
|
147
|
+
var i = m.call(o),
|
|
148
|
+
r,
|
|
149
|
+
ar = [],
|
|
150
|
+
e;
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
154
|
+
ar.push(r.value);
|
|
155
|
+
}
|
|
156
|
+
} catch (error) {
|
|
157
|
+
e = {
|
|
158
|
+
error: error
|
|
159
|
+
};
|
|
160
|
+
} finally {
|
|
161
|
+
try {
|
|
162
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
163
|
+
} finally {
|
|
164
|
+
if (e) throw e.error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return ar;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
var __spread = this && this.__spread || function () {
|
|
172
|
+
for (var ar = [], i = 0; i < arguments.length; i++) {
|
|
173
|
+
ar = ar.concat(__read(arguments[i]));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return ar;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
var __values = this && this.__values || function (o) {
|
|
180
|
+
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
181
|
+
m = s && o[s],
|
|
182
|
+
i = 0;
|
|
183
|
+
if (m) return m.call(o);
|
|
184
|
+
if (o && typeof o.length === "number") return {
|
|
185
|
+
next: function next() {
|
|
186
|
+
if (o && i >= o.length) o = void 0;
|
|
187
|
+
return {
|
|
188
|
+
value: o && o[i++],
|
|
189
|
+
done: !o
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
import { GrpcPool } from './GrpcPool';
|
|
197
|
+
|
|
198
|
+
function createRpcPromise(fn, grpc) {
|
|
199
|
+
return function () {
|
|
200
|
+
var args = [];
|
|
201
|
+
|
|
202
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
203
|
+
args[_i] = arguments[_i];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return new Promise(function (resolve, reject) {
|
|
207
|
+
var client = grpc.client;
|
|
208
|
+
fn.call.apply(fn, __spread([client], args, [function (err, response) {
|
|
209
|
+
global.proto = grpc.proto;
|
|
210
|
+
|
|
211
|
+
if (err) {
|
|
212
|
+
reject(err);
|
|
213
|
+
} else {
|
|
214
|
+
resolve(response);
|
|
215
|
+
}
|
|
216
|
+
}]));
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
var GrpcService =
|
|
222
|
+
/** @class */
|
|
223
|
+
function () {
|
|
224
|
+
function GrpcService(conf) {
|
|
225
|
+
this.config = conf;
|
|
226
|
+
this.grpc = GrpcPool.getPool().getGrpc(this.config.client);
|
|
227
|
+
|
|
228
|
+
if (!this.grpc || !this.grpc.client[this.config.serviceName]) {
|
|
229
|
+
throw new Error("rpc service not found:" + this.config.serviceName);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
this.promise = createRpcPromise(this.grpc.client[this.config.serviceName], this.grpc);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
GrpcService.prototype.serializer = function (requestType, payload) {
|
|
236
|
+
var e_1, _a;
|
|
237
|
+
|
|
238
|
+
if (payload === void 0) {
|
|
239
|
+
payload = {};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!this.grpc) {
|
|
243
|
+
throw new Error("rpc client not found:" + this.config.client);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
global.proto = this.grpc.proto;
|
|
247
|
+
var request = new this.grpc.common[requestType]();
|
|
248
|
+
|
|
249
|
+
try {
|
|
250
|
+
for (var _b = __values(Object.keys(request.toObject())), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
251
|
+
var key = _c.value;
|
|
252
|
+
|
|
253
|
+
if (payload[key] !== undefined) {
|
|
254
|
+
request["set" + key[0].toUpperCase() + key.slice(1)](payload[key]);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
} catch (e_1_1) {
|
|
258
|
+
e_1 = {
|
|
259
|
+
error: e_1_1
|
|
260
|
+
};
|
|
261
|
+
} finally {
|
|
262
|
+
try {
|
|
263
|
+
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
|
|
264
|
+
} finally {
|
|
265
|
+
if (e_1) throw e_1.error;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return request;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
GrpcService.prototype.send = function (request) {
|
|
273
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
274
|
+
var res;
|
|
275
|
+
return __generator(this, function (_a) {
|
|
276
|
+
switch (_a.label) {
|
|
277
|
+
case 0:
|
|
278
|
+
return [4
|
|
279
|
+
/*yield*/
|
|
280
|
+
, this.promise(this.serializer(this.config.requestType, request))];
|
|
281
|
+
|
|
282
|
+
case 1:
|
|
283
|
+
res = _a.sent();
|
|
284
|
+
return [2
|
|
285
|
+
/*return*/
|
|
286
|
+
, res.toObject()];
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
return GrpcService;
|
|
293
|
+
}();
|
|
294
|
+
|
|
295
|
+
export { GrpcService };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GrpcService } from './GrpcService';
|
|
2
|
+
interface GrpcServiceOptions {
|
|
3
|
+
client: string;
|
|
4
|
+
requestType: string;
|
|
5
|
+
service?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const createGrpcService: import("pubo-utils/lib/factory").CreateFactory<GrpcServiceOptions, GrpcService>;
|
|
8
|
+
export {};
|
package/es/grpc/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
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
|
+
});
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { JsonStorage } from './storage/json';
|
|
2
|
-
export { initRtspVideos } from './rtsp-video';
|
|
3
2
|
export { FtpClient } from './ftp-client';
|
|
4
|
-
export { md5 } from './md5';
|
|
3
|
+
export { md5 } from './md5';
|
|
4
|
+
export { createGrpcService } from './grpc';
|
|
5
|
+
export { GrpcPool } from './grpc/GrpcPool';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface GrpcConfig {
|
|
2
|
+
root: string;
|
|
3
|
+
url: string;
|
|
4
|
+
options?: any;
|
|
5
|
+
}
|
|
6
|
+
export declare class Grpc {
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly options;
|
|
9
|
+
private instance;
|
|
10
|
+
private readonly RpcClient;
|
|
11
|
+
common: any;
|
|
12
|
+
proto: any;
|
|
13
|
+
constructor(conf: GrpcConfig);
|
|
14
|
+
get client(): any;
|
|
15
|
+
}
|
package/lib/grpc/Grpc.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
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 __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
Object.defineProperty(o, k2, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return m[k];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
} : function (o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
|
|
33
|
+
Object.defineProperty(o, "default", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
value: v
|
|
36
|
+
});
|
|
37
|
+
} : function (o, v) {
|
|
38
|
+
o["default"] = v;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
var __importStar = this && this.__importStar || function (mod) {
|
|
42
|
+
if (mod && mod.__esModule) return mod;
|
|
43
|
+
var result = {};
|
|
44
|
+
if (mod != null) for (var k in mod) {
|
|
45
|
+
if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
__setModuleDefault(result, mod);
|
|
49
|
+
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
Object.defineProperty(exports, "__esModule", {
|
|
54
|
+
value: true
|
|
55
|
+
});
|
|
56
|
+
exports.Grpc = void 0;
|
|
57
|
+
|
|
58
|
+
var grpc = __importStar(require("grpc"));
|
|
59
|
+
|
|
60
|
+
var Grpc =
|
|
61
|
+
/** @class */
|
|
62
|
+
function () {
|
|
63
|
+
function Grpc(conf) {
|
|
64
|
+
this.options = {
|
|
65
|
+
'grpc.max_send_message_length': -1,
|
|
66
|
+
'grpc.max_receive_message_length': -1
|
|
67
|
+
};
|
|
68
|
+
this.instance = null;
|
|
69
|
+
this.config = conf;
|
|
70
|
+
this.common = require(this.config.root + "/common_pb"); // eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
71
|
+
|
|
72
|
+
this.RpcClient = require(this.config.root + "/service_grpc_pb").RpcClient;
|
|
73
|
+
this.proto = global.proto;
|
|
74
|
+
global.proto = {};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Object.defineProperty(Grpc.prototype, "client", {
|
|
78
|
+
get: function get() {
|
|
79
|
+
if (!this.instance) {
|
|
80
|
+
var options = __assign(__assign({}, this.options), this.config.options || {});
|
|
81
|
+
|
|
82
|
+
this.instance = new this.RpcClient(this.config.url, grpc.credentials.createInsecure(), options);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return this.instance;
|
|
86
|
+
},
|
|
87
|
+
enumerable: false,
|
|
88
|
+
configurable: true
|
|
89
|
+
});
|
|
90
|
+
return Grpc;
|
|
91
|
+
}();
|
|
92
|
+
|
|
93
|
+
exports.Grpc = Grpc;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GrpcConfig } from './Grpc';
|
|
2
|
+
import { Grpc } from './Grpc';
|
|
3
|
+
export declare type GrpcPoolType = (GrpcConfig & {
|
|
4
|
+
id: any;
|
|
5
|
+
})[];
|
|
6
|
+
export declare class GrpcPool {
|
|
7
|
+
static pool: GrpcPoolType;
|
|
8
|
+
private static instance;
|
|
9
|
+
static getPool: () => GrpcPool;
|
|
10
|
+
static setPool: (pool: GrpcPoolType) => void;
|
|
11
|
+
private readonly list;
|
|
12
|
+
constructor(list: GrpcPoolType);
|
|
13
|
+
getGrpc(id: string): Grpc | undefined;
|
|
14
|
+
}
|