pubo-node 1.0.77 → 1.0.79
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/index.js +2 -0
- package/es/index.d.ts +1 -1
- package/es/index.js +2 -2
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +14 -0
- package/lib/grpc/index.js +2 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +8 -14
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +21 -0
- package/package.json +3 -3
- package/es/rtsp-video/index.d.ts +0 -27
- package/es/rtsp-video/index.js +0 -165
- package/es/rtsp-video/rtsp2mpeg.d.ts +0 -14
- package/es/rtsp-video/rtsp2mpeg.js +0 -106
- package/lib/rtsp-video/index.d.ts +0 -27
- package/lib/rtsp-video/index.js +0 -172
- package/lib/rtsp-video/rtsp2mpeg.d.ts +0 -14
- package/lib/rtsp-video/rtsp2mpeg.js +0 -112
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:()=>M,RtspVideosManager:()=>m,createChildProcess:()=>G,createRpcClient:()=>q,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},f=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))},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=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=f(f(f(f([],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 h(e,n)})),this.customer=this._customer.map((function(t){var e=t.url,n=y(t,["url"]);return new h(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 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}(),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")},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)};function q(t){var e=t.url,n=t.options,r=void 0===n?{}:n,o=t.ServiceImp,i=t.Grpc,s=t.cert,c=A({"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))}))}},M={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)},J=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},R=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(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=t.apply(void 0,R([],J(e),!1));return process.on("SIGTERM",(function(){return r.kill()})),r};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={808:t=>{t.exports=require("net")}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{n.r(r),n.d(r,{FtpClient:()=>p,FtpClientPool:()=>d,JsonStorage:()=>i,PuboFileSystem:()=>x,createChildProcess:()=>j,createRpcClient:()=>g,isPortAvailable:()=>_,md5:()=>v});const t=require("fs"),e=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 n(t){this._state={},this.path=t,this.init()}return n.prototype.init=function(){try{var n=(0,t.readFileSync)(this.path),r=e.inflate(n,{to:"string"});this._state=JSON.parse(r)}catch(t){this.state={}}},Object.defineProperty(n.prototype,"state",{get:function(){return this._state},set:function(n){var r=e.deflate(JSON.stringify(n)),o=Buffer.from(r);(0,t.writeFile)(this.path,o,(function(t){return t&&console.log(t)})),this._state=n},enumerable:!1,configurable:!0}),n.prototype.get=function(t){return t?this.state[t]:o({},this.state)},n.prototype.set=function(t,e){var n=o({},this.state);n[t]=e,this.state=n},n.prototype.merge=function(t){this.state=o(o({},this._state),t)},n}();const c=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)},s=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function c(t){try{s(r.next(t))}catch(t){i(t)}}function a(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(c,a)}s((r=r.apply(t,e||[])).next())}))},u=function(t,e){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return c.label++,{value:a[1],done:!1};case 5:c.label++,r=a[1],a=[0];continue;case 7:a=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){c=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){c.label=a[1];break}if(6===a[0]&&c.label<o[1]){c.label=o[1],o=a;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(a);break}o[2]&&c.ops.pop(),c.trys.pop();continue}a=e.call(t,c)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}},l=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},f=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),c=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)c.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 c},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))},p=function(){function t(t){var e=t.driver,n=l(t,["driver"]);this.state={running:!1,connected:!1,destroyed:!1,connecting:!1},this._len=0,this.id=(0,c.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 s(this,void 0,void 0,(function(){var t=this;return u(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,c.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(a({},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 s(this,void 0,void 0,(function(){var t=this;return u(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,c.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,h(h([],f(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 s(e,void 0,void 0,(function(){var e;return u(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 s(this,void 0,void 0,(function(){var e,n,r=this;return u(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}(),d=function(){function t(t){var e=t.maxConnection,n=void 0===e?5:e,r=l(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 p(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 s(e,void 0,void 0,(function(){var e,r,o;return u(this,(function(i){switch(i.label){case 0:return[4,(e=this.client)[t].apply(e,h([],f(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 y=require("crypto");var v=function(t){return(0,y.createHash)("md5").update(t).digest("hex")},b=function(){return b=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},b.apply(this,arguments)};function g(t){var e=t.url,n=t.options,r=void 0===n?{}:n,o=t.ServiceImp,i=t.Grpc,c=t.cert,a=b({"grpc.max_send_message_length":-1,"grpc.max_receive_message_length":-1},r),s=c?i.credentials.createSsl(c):i.credentials.createInsecure(),u=new i.Client(e,s,a);return new o({request:function(t,n,r){var o="/".concat(t,"/").concat(n);return new Promise((function(t,n){var c=function(t){return t};u.makeUnaryRequest(o,c,c,r,(function(r,o){r?(u.close(),u=new i.Client(e,s,a),n(r)):t(o)}))}))}})}var m=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),c=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)c.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 c},w=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))},O=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,w(w([],m(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(w([],m(e),!1))}],!1))}))}},x={read:O(t.read),readFile:O(t.readFile),writeFile:O(t.writeFile),readdir:O(t.readdir),open:O(t.open),close:O(t.close),write:O(t.write),stat:O(t.stat)},P=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),c=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)c.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 c},S=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))},j=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=t.apply(void 0,S([],P(e),!1));return process.on("SIGTERM",(function(){return r.kill()})),r},_=function(t){return new Promise((function(e){var r=n(808).createServer();r.listen(t,(function(){e(!0),r.close()})),r.on("error",(function(){e(!1),r.close()}))}))}})(),r})()));
|
package/es/grpc/index.js
CHANGED
|
@@ -26,6 +26,8 @@ export function createRpcClient(_a) {
|
|
|
26
26
|
return new Promise(function (resolve, reject) {
|
|
27
27
|
var resultCallback = function resultCallback(err, res) {
|
|
28
28
|
if (err) {
|
|
29
|
+
connection.close();
|
|
30
|
+
connection = new Grpc.Client(url, credentials, opt);
|
|
29
31
|
reject(err);
|
|
30
32
|
} else {
|
|
31
33
|
resolve(res);
|
package/es/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { JsonStorage } from './storage/json';
|
|
2
|
-
export { initRtspVideos, RtspVideosManager } from './rtsp-video';
|
|
3
2
|
export { FtpClient, FtpClientPool, FtpConnectOptions, FtpFile } from './ftp-client';
|
|
4
3
|
export { md5 } from './md5';
|
|
5
4
|
export { createRpcClient } from './grpc';
|
|
6
5
|
export { PuboFileSystem } from './file-system';
|
|
7
6
|
export { createChildProcess } from './child-process';
|
|
7
|
+
export { isPortAvailable } from './utils';
|
package/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { JsonStorage } from './storage/json';
|
|
2
|
-
export { initRtspVideos, RtspVideosManager } from './rtsp-video';
|
|
3
2
|
export { FtpClient, FtpClientPool } from './ftp-client';
|
|
4
3
|
export { md5 } from './md5';
|
|
5
4
|
export { createRpcClient } from './grpc';
|
|
6
5
|
export { PuboFileSystem } from './file-system';
|
|
7
|
-
export { createChildProcess } from './child-process';
|
|
6
|
+
export { createChildProcess } from './child-process';
|
|
7
|
+
export { isPortAvailable } from './utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isPortAvailable: (port: any) => Promise<unknown>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export var isPortAvailable = function isPortAvailable(port) {
|
|
2
|
+
return new Promise(function (resolve) {
|
|
3
|
+
var net = require('net');
|
|
4
|
+
var server = net.createServer();
|
|
5
|
+
server.listen(port, function () {
|
|
6
|
+
resolve(true);
|
|
7
|
+
server.close();
|
|
8
|
+
});
|
|
9
|
+
server.on('error', function () {
|
|
10
|
+
resolve(false);
|
|
11
|
+
server.close();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
};
|
package/lib/grpc/index.js
CHANGED
|
@@ -32,6 +32,8 @@ function createRpcClient(_a) {
|
|
|
32
32
|
return new Promise(function (resolve, reject) {
|
|
33
33
|
var resultCallback = function resultCallback(err, res) {
|
|
34
34
|
if (err) {
|
|
35
|
+
connection.close();
|
|
36
|
+
connection = new Grpc.Client(url, credentials, opt);
|
|
35
37
|
reject(err);
|
|
36
38
|
} else {
|
|
37
39
|
resolve(res);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { JsonStorage } from './storage/json';
|
|
2
|
-
export { initRtspVideos, RtspVideosManager } from './rtsp-video';
|
|
3
2
|
export { FtpClient, FtpClientPool, FtpConnectOptions, FtpFile } from './ftp-client';
|
|
4
3
|
export { md5 } from './md5';
|
|
5
4
|
export { createRpcClient } from './grpc';
|
|
6
5
|
export { PuboFileSystem } from './file-system';
|
|
7
6
|
export { createChildProcess } from './child-process';
|
|
7
|
+
export { isPortAvailable } from './utils';
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.createChildProcess = exports.PuboFileSystem = exports.createRpcClient = exports.md5 = exports.FtpClientPool = exports.FtpClient = exports.
|
|
6
|
+
exports.isPortAvailable = exports.createChildProcess = exports.PuboFileSystem = exports.createRpcClient = exports.md5 = exports.FtpClientPool = exports.FtpClient = exports.JsonStorage = void 0;
|
|
7
7
|
var json_1 = require("./storage/json");
|
|
8
8
|
Object.defineProperty(exports, "JsonStorage", {
|
|
9
9
|
enumerable: true,
|
|
@@ -11,19 +11,6 @@ Object.defineProperty(exports, "JsonStorage", {
|
|
|
11
11
|
return json_1.JsonStorage;
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
var rtsp_video_1 = require("./rtsp-video");
|
|
15
|
-
Object.defineProperty(exports, "initRtspVideos", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function get() {
|
|
18
|
-
return rtsp_video_1.initRtspVideos;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(exports, "RtspVideosManager", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function get() {
|
|
24
|
-
return rtsp_video_1.RtspVideosManager;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
14
|
var ftp_client_1 = require("./ftp-client");
|
|
28
15
|
Object.defineProperty(exports, "FtpClient", {
|
|
29
16
|
enumerable: true,
|
|
@@ -64,4 +51,11 @@ Object.defineProperty(exports, "createChildProcess", {
|
|
|
64
51
|
get: function get() {
|
|
65
52
|
return child_process_1.createChildProcess;
|
|
66
53
|
}
|
|
54
|
+
});
|
|
55
|
+
var utils_1 = require("./utils");
|
|
56
|
+
Object.defineProperty(exports, "isPortAvailable", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function get() {
|
|
59
|
+
return utils_1.isPortAvailable;
|
|
60
|
+
}
|
|
67
61
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isPortAvailable: (port: any) => Promise<unknown>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isPortAvailable = void 0;
|
|
7
|
+
var isPortAvailable = function isPortAvailable(port) {
|
|
8
|
+
return new Promise(function (resolve) {
|
|
9
|
+
var net = require('net');
|
|
10
|
+
var server = net.createServer();
|
|
11
|
+
server.listen(port, function () {
|
|
12
|
+
resolve(true);
|
|
13
|
+
server.close();
|
|
14
|
+
});
|
|
15
|
+
server.on('error', function () {
|
|
16
|
+
resolve(false);
|
|
17
|
+
server.close();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.isPortAvailable = isPortAvailable;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.79",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@types/node": "^17.0.25",
|
|
23
23
|
"pako": "^2.0.4",
|
|
24
|
-
"pubo-utils": "^1.0.
|
|
24
|
+
"pubo-utils": "^1.0.79"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "db21482116d630531b8388adf622a5709ab780d8"
|
|
27
27
|
}
|
package/es/rtsp-video/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { RTSP2Mpeg } from './rtsp2mpeg';
|
|
2
|
-
interface VideoConfig {
|
|
3
|
-
url: string;
|
|
4
|
-
input?: string[];
|
|
5
|
-
output?: string[];
|
|
6
|
-
}
|
|
7
|
-
interface Props {
|
|
8
|
-
app: any;
|
|
9
|
-
server?: any;
|
|
10
|
-
videos: VideoConfig[];
|
|
11
|
-
path: string;
|
|
12
|
-
expressWs?: any;
|
|
13
|
-
}
|
|
14
|
-
export declare 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;
|
|
27
|
-
export {};
|
package/es/rtsp-video/index.js
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
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
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
6
|
-
}
|
|
7
|
-
return t;
|
|
8
|
-
};
|
|
9
|
-
return __assign.apply(this, arguments);
|
|
10
|
-
};
|
|
11
|
-
var __rest = this && this.__rest || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
14
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
15
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
16
|
-
}
|
|
17
|
-
return t;
|
|
18
|
-
};
|
|
19
|
-
var __read = this && this.__read || function (o, n) {
|
|
20
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
21
|
-
if (!m) return o;
|
|
22
|
-
var i = m.call(o),
|
|
23
|
-
r,
|
|
24
|
-
ar = [],
|
|
25
|
-
e;
|
|
26
|
-
try {
|
|
27
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
28
|
-
} catch (error) {
|
|
29
|
-
e = {
|
|
30
|
-
error: error
|
|
31
|
-
};
|
|
32
|
-
} finally {
|
|
33
|
-
try {
|
|
34
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
35
|
-
} finally {
|
|
36
|
-
if (e) throw e.error;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return ar;
|
|
40
|
-
};
|
|
41
|
-
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
42
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
43
|
-
if (ar || !(i in from)) {
|
|
44
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
45
|
-
ar[i] = from[i];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
49
|
-
};
|
|
50
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
51
|
-
import { resolve } from 'path';
|
|
52
|
-
import { RTSP2Mpeg } from './rtsp2mpeg';
|
|
53
|
-
var VideoStorage = /** @class */function () {
|
|
54
|
-
function VideoStorage() {
|
|
55
|
-
this.path = resolve('resources/temp/videos.json');
|
|
56
|
-
}
|
|
57
|
-
VideoStorage.prototype.async = function (data) {
|
|
58
|
-
try {
|
|
59
|
-
writeFileSync(this.path, JSON.stringify(data));
|
|
60
|
-
} catch (err) {
|
|
61
|
-
console.log(err);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
Object.defineProperty(VideoStorage.prototype, "data", {
|
|
65
|
-
get: function get() {
|
|
66
|
-
try {
|
|
67
|
-
var buffer = readFileSync(this.path);
|
|
68
|
-
console.log(buffer.toString());
|
|
69
|
-
return JSON.parse(buffer.toString());
|
|
70
|
-
} catch (err) {
|
|
71
|
-
console.log(err);
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
enumerable: false,
|
|
76
|
-
configurable: true
|
|
77
|
-
});
|
|
78
|
-
return VideoStorage;
|
|
79
|
-
}();
|
|
80
|
-
var RtspVideosManager = /** @class */function () {
|
|
81
|
-
function RtspVideosManager(videos) {
|
|
82
|
-
this._system = [];
|
|
83
|
-
this._customer = [];
|
|
84
|
-
this.system = [];
|
|
85
|
-
this.customer = [];
|
|
86
|
-
this.storage = new VideoStorage();
|
|
87
|
-
this._system = videos.map(function (item) {
|
|
88
|
-
return __assign(__assign({}, item), {
|
|
89
|
-
system: true
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
this._customer = this.storage.data || [];
|
|
93
|
-
this.system = videos.map(function (_a) {
|
|
94
|
-
var url = _a.url,
|
|
95
|
-
options = __rest(_a, ["url"]);
|
|
96
|
-
return new RTSP2Mpeg(url, options);
|
|
97
|
-
});
|
|
98
|
-
this.customer = this._customer.map(function (_a) {
|
|
99
|
-
var url = _a.url,
|
|
100
|
-
options = __rest(_a, ["url"]);
|
|
101
|
-
return new RTSP2Mpeg(url, options);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
Object.defineProperty(RtspVideosManager.prototype, "list", {
|
|
105
|
-
get: function get() {
|
|
106
|
-
return __spreadArray(__spreadArray([], __read(this.system), false), __read(this.customer), false);
|
|
107
|
-
},
|
|
108
|
-
enumerable: false,
|
|
109
|
-
configurable: true
|
|
110
|
-
});
|
|
111
|
-
RtspVideosManager.prototype.getVideos = function () {
|
|
112
|
-
return __spreadArray(__spreadArray([], __read(this._system), false), __read(this._customer), false);
|
|
113
|
-
};
|
|
114
|
-
RtspVideosManager.prototype.create = function (conf) {
|
|
115
|
-
if (this._customer.some(function (item) {
|
|
116
|
-
return item.url === conf.url;
|
|
117
|
-
})) {
|
|
118
|
-
throw new Error('该地址已存在');
|
|
119
|
-
}
|
|
120
|
-
var video = new RTSP2Mpeg(conf.url, conf);
|
|
121
|
-
this._customer.push(conf);
|
|
122
|
-
this.customer.push(video);
|
|
123
|
-
this.storage.async(this._customer);
|
|
124
|
-
};
|
|
125
|
-
RtspVideosManager.prototype.remove = function (index) {
|
|
126
|
-
if (index < this.system.length) {
|
|
127
|
-
throw new Error('系统配置不可删除');
|
|
128
|
-
} else if (index > this.system.length + this.customer.length - 1) {
|
|
129
|
-
throw new Error('超限');
|
|
130
|
-
}
|
|
131
|
-
this._customer.splice(index - this.system.length - 1, 1);
|
|
132
|
-
var video = this.customer.splice(index - this.system.length - 1, 1);
|
|
133
|
-
video[0].destroy();
|
|
134
|
-
this.storage.async(this._customer);
|
|
135
|
-
};
|
|
136
|
-
return RtspVideosManager;
|
|
137
|
-
}();
|
|
138
|
-
export { RtspVideosManager };
|
|
139
|
-
export var initRtspVideos = function initRtspVideos(_a) {
|
|
140
|
-
var app = _a.app,
|
|
141
|
-
server = _a.server,
|
|
142
|
-
videos = _a.videos,
|
|
143
|
-
path = _a.path,
|
|
144
|
-
expressWs = _a.expressWs;
|
|
145
|
-
var manager = new RtspVideosManager(videos);
|
|
146
|
-
if (!app.ws) {
|
|
147
|
-
expressWs(app, server);
|
|
148
|
-
}
|
|
149
|
-
app.ws(path, function (ws, req) {
|
|
150
|
-
var _a = req.query.channel,
|
|
151
|
-
channel = _a === void 0 ? 0 : _a;
|
|
152
|
-
var listener = null;
|
|
153
|
-
if (manager.list[channel]) {
|
|
154
|
-
listener = manager.list[channel].on('data', function (chunk) {
|
|
155
|
-
ws.send(chunk);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
ws.on('close', function () {
|
|
159
|
-
if (listener && manager.list[channel]) {
|
|
160
|
-
manager.list[channel].cancel(listener);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
return manager;
|
|
165
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare class RTSP2Mpeg {
|
|
2
|
-
private readonly eventEmitter;
|
|
3
|
-
private readonly dog;
|
|
4
|
-
private readonly url;
|
|
5
|
-
private s;
|
|
6
|
-
private readonly options;
|
|
7
|
-
constructor(url: string, options: any);
|
|
8
|
-
private onMessage;
|
|
9
|
-
private closeOld;
|
|
10
|
-
private connect;
|
|
11
|
-
on(event: string, cb: (data: any) => void): string;
|
|
12
|
-
cancel(id: any): void;
|
|
13
|
-
destroy(): void;
|
|
14
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
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
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
6
|
-
}
|
|
7
|
-
return t;
|
|
8
|
-
};
|
|
9
|
-
return __assign.apply(this, arguments);
|
|
10
|
-
};
|
|
11
|
-
var __read = this && this.__read || function (o, n) {
|
|
12
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
13
|
-
if (!m) return o;
|
|
14
|
-
var i = m.call(o),
|
|
15
|
-
r,
|
|
16
|
-
ar = [],
|
|
17
|
-
e;
|
|
18
|
-
try {
|
|
19
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
20
|
-
} catch (error) {
|
|
21
|
-
e = {
|
|
22
|
-
error: error
|
|
23
|
-
};
|
|
24
|
-
} finally {
|
|
25
|
-
try {
|
|
26
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
27
|
-
} finally {
|
|
28
|
-
if (e) throw e.error;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
|
-
import { spawn } from 'child_process';
|
|
43
|
-
import { Emitter, WatchDog } from 'pubo-utils';
|
|
44
|
-
var RTSP2Mpeg = /** @class */function () {
|
|
45
|
-
function RTSP2Mpeg(url, options) {
|
|
46
|
-
var _this = this;
|
|
47
|
-
this.eventEmitter = new Emitter();
|
|
48
|
-
this.dog = new WatchDog({
|
|
49
|
-
limit: 10,
|
|
50
|
-
onTimeout: function onTimeout() {
|
|
51
|
-
return _this.connect();
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
this.url = url;
|
|
55
|
-
this.options = __assign({}, options);
|
|
56
|
-
if (!this.options.input) {
|
|
57
|
-
this.options.input = ['-rtsp_transport', 'tcp', '-i'];
|
|
58
|
-
}
|
|
59
|
-
if (!this.options.output) {
|
|
60
|
-
this.options.output = ['-f', 'mpegts', '-codec:v', 'mpeg1video'];
|
|
61
|
-
}
|
|
62
|
-
this.connect();
|
|
63
|
-
this.dog.init();
|
|
64
|
-
}
|
|
65
|
-
RTSP2Mpeg.prototype.onMessage = function (msg) {
|
|
66
|
-
this.dog.feed();
|
|
67
|
-
this.eventEmitter.emit('message', msg.toString());
|
|
68
|
-
};
|
|
69
|
-
RTSP2Mpeg.prototype.closeOld = function () {
|
|
70
|
-
if (this.s) {
|
|
71
|
-
console.log("LOG Video-Server: ".concat(this.url, " try to reconnect;"));
|
|
72
|
-
this.s.kill();
|
|
73
|
-
this.s = null;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
RTSP2Mpeg.prototype.connect = function () {
|
|
77
|
-
var _this = this;
|
|
78
|
-
this.closeOld();
|
|
79
|
-
var options = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(this.options.input), false), [this.url], false), __read(this.options.output), false), ['-'], false);
|
|
80
|
-
this.s = spawn('ffmpeg', options, {
|
|
81
|
-
detached: false
|
|
82
|
-
});
|
|
83
|
-
this.s.stderr.on('data', function (buffer) {
|
|
84
|
-
return _this.onMessage(buffer);
|
|
85
|
-
});
|
|
86
|
-
this.s.stdout.on('data', function (buffer) {
|
|
87
|
-
return _this.eventEmitter.emit('data', buffer);
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
RTSP2Mpeg.prototype.on = function (event, cb) {
|
|
91
|
-
return this.eventEmitter.on(event, cb);
|
|
92
|
-
};
|
|
93
|
-
RTSP2Mpeg.prototype.cancel = function (id) {
|
|
94
|
-
this.eventEmitter.cancel(id);
|
|
95
|
-
};
|
|
96
|
-
RTSP2Mpeg.prototype.destroy = function () {
|
|
97
|
-
this.eventEmitter.clear();
|
|
98
|
-
this.dog.stop();
|
|
99
|
-
if (this.s) {
|
|
100
|
-
this.s.kill();
|
|
101
|
-
this.s = null;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
return RTSP2Mpeg;
|
|
105
|
-
}();
|
|
106
|
-
export { RTSP2Mpeg };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { RTSP2Mpeg } from './rtsp2mpeg';
|
|
2
|
-
interface VideoConfig {
|
|
3
|
-
url: string;
|
|
4
|
-
input?: string[];
|
|
5
|
-
output?: string[];
|
|
6
|
-
}
|
|
7
|
-
interface Props {
|
|
8
|
-
app: any;
|
|
9
|
-
server?: any;
|
|
10
|
-
videos: VideoConfig[];
|
|
11
|
-
path: string;
|
|
12
|
-
expressWs?: any;
|
|
13
|
-
}
|
|
14
|
-
export declare 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;
|
|
27
|
-
export {};
|
package/lib/rtsp-video/index.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
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
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = this && this.__rest || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
18
|
-
}
|
|
19
|
-
return t;
|
|
20
|
-
};
|
|
21
|
-
var __read = this && this.__read || function (o, n) {
|
|
22
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
23
|
-
if (!m) return o;
|
|
24
|
-
var i = m.call(o),
|
|
25
|
-
r,
|
|
26
|
-
ar = [],
|
|
27
|
-
e;
|
|
28
|
-
try {
|
|
29
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
|
-
} catch (error) {
|
|
31
|
-
e = {
|
|
32
|
-
error: error
|
|
33
|
-
};
|
|
34
|
-
} finally {
|
|
35
|
-
try {
|
|
36
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
37
|
-
} finally {
|
|
38
|
-
if (e) throw e.error;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return ar;
|
|
42
|
-
};
|
|
43
|
-
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
44
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
45
|
-
if (ar || !(i in from)) {
|
|
46
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
47
|
-
ar[i] = from[i];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", {
|
|
53
|
-
value: true
|
|
54
|
-
});
|
|
55
|
-
exports.initRtspVideos = exports.RtspVideosManager = void 0;
|
|
56
|
-
var fs_1 = require("fs");
|
|
57
|
-
var path_1 = require("path");
|
|
58
|
-
var rtsp2mpeg_1 = require("./rtsp2mpeg");
|
|
59
|
-
var VideoStorage = /** @class */function () {
|
|
60
|
-
function VideoStorage() {
|
|
61
|
-
this.path = (0, path_1.resolve)('resources/temp/videos.json');
|
|
62
|
-
}
|
|
63
|
-
VideoStorage.prototype.async = function (data) {
|
|
64
|
-
try {
|
|
65
|
-
(0, fs_1.writeFileSync)(this.path, JSON.stringify(data));
|
|
66
|
-
} catch (err) {
|
|
67
|
-
console.log(err);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
Object.defineProperty(VideoStorage.prototype, "data", {
|
|
71
|
-
get: function get() {
|
|
72
|
-
try {
|
|
73
|
-
var buffer = (0, fs_1.readFileSync)(this.path);
|
|
74
|
-
console.log(buffer.toString());
|
|
75
|
-
return JSON.parse(buffer.toString());
|
|
76
|
-
} catch (err) {
|
|
77
|
-
console.log(err);
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
enumerable: false,
|
|
82
|
-
configurable: true
|
|
83
|
-
});
|
|
84
|
-
return VideoStorage;
|
|
85
|
-
}();
|
|
86
|
-
var RtspVideosManager = /** @class */function () {
|
|
87
|
-
function RtspVideosManager(videos) {
|
|
88
|
-
this._system = [];
|
|
89
|
-
this._customer = [];
|
|
90
|
-
this.system = [];
|
|
91
|
-
this.customer = [];
|
|
92
|
-
this.storage = new VideoStorage();
|
|
93
|
-
this._system = videos.map(function (item) {
|
|
94
|
-
return __assign(__assign({}, item), {
|
|
95
|
-
system: true
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
this._customer = this.storage.data || [];
|
|
99
|
-
this.system = videos.map(function (_a) {
|
|
100
|
-
var url = _a.url,
|
|
101
|
-
options = __rest(_a, ["url"]);
|
|
102
|
-
return new rtsp2mpeg_1.RTSP2Mpeg(url, options);
|
|
103
|
-
});
|
|
104
|
-
this.customer = this._customer.map(function (_a) {
|
|
105
|
-
var url = _a.url,
|
|
106
|
-
options = __rest(_a, ["url"]);
|
|
107
|
-
return new rtsp2mpeg_1.RTSP2Mpeg(url, options);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
Object.defineProperty(RtspVideosManager.prototype, "list", {
|
|
111
|
-
get: function get() {
|
|
112
|
-
return __spreadArray(__spreadArray([], __read(this.system), false), __read(this.customer), false);
|
|
113
|
-
},
|
|
114
|
-
enumerable: false,
|
|
115
|
-
configurable: true
|
|
116
|
-
});
|
|
117
|
-
RtspVideosManager.prototype.getVideos = function () {
|
|
118
|
-
return __spreadArray(__spreadArray([], __read(this._system), false), __read(this._customer), false);
|
|
119
|
-
};
|
|
120
|
-
RtspVideosManager.prototype.create = function (conf) {
|
|
121
|
-
if (this._customer.some(function (item) {
|
|
122
|
-
return item.url === conf.url;
|
|
123
|
-
})) {
|
|
124
|
-
throw new Error('该地址已存在');
|
|
125
|
-
}
|
|
126
|
-
var video = new rtsp2mpeg_1.RTSP2Mpeg(conf.url, conf);
|
|
127
|
-
this._customer.push(conf);
|
|
128
|
-
this.customer.push(video);
|
|
129
|
-
this.storage.async(this._customer);
|
|
130
|
-
};
|
|
131
|
-
RtspVideosManager.prototype.remove = function (index) {
|
|
132
|
-
if (index < this.system.length) {
|
|
133
|
-
throw new Error('系统配置不可删除');
|
|
134
|
-
} else if (index > this.system.length + this.customer.length - 1) {
|
|
135
|
-
throw new Error('超限');
|
|
136
|
-
}
|
|
137
|
-
this._customer.splice(index - this.system.length - 1, 1);
|
|
138
|
-
var video = this.customer.splice(index - this.system.length - 1, 1);
|
|
139
|
-
video[0].destroy();
|
|
140
|
-
this.storage.async(this._customer);
|
|
141
|
-
};
|
|
142
|
-
return RtspVideosManager;
|
|
143
|
-
}();
|
|
144
|
-
exports.RtspVideosManager = RtspVideosManager;
|
|
145
|
-
var initRtspVideos = function initRtspVideos(_a) {
|
|
146
|
-
var app = _a.app,
|
|
147
|
-
server = _a.server,
|
|
148
|
-
videos = _a.videos,
|
|
149
|
-
path = _a.path,
|
|
150
|
-
expressWs = _a.expressWs;
|
|
151
|
-
var manager = new RtspVideosManager(videos);
|
|
152
|
-
if (!app.ws) {
|
|
153
|
-
expressWs(app, server);
|
|
154
|
-
}
|
|
155
|
-
app.ws(path, function (ws, req) {
|
|
156
|
-
var _a = req.query.channel,
|
|
157
|
-
channel = _a === void 0 ? 0 : _a;
|
|
158
|
-
var listener = null;
|
|
159
|
-
if (manager.list[channel]) {
|
|
160
|
-
listener = manager.list[channel].on('data', function (chunk) {
|
|
161
|
-
ws.send(chunk);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
ws.on('close', function () {
|
|
165
|
-
if (listener && manager.list[channel]) {
|
|
166
|
-
manager.list[channel].cancel(listener);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
return manager;
|
|
171
|
-
};
|
|
172
|
-
exports.initRtspVideos = initRtspVideos;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare class RTSP2Mpeg {
|
|
2
|
-
private readonly eventEmitter;
|
|
3
|
-
private readonly dog;
|
|
4
|
-
private readonly url;
|
|
5
|
-
private s;
|
|
6
|
-
private readonly options;
|
|
7
|
-
constructor(url: string, options: any);
|
|
8
|
-
private onMessage;
|
|
9
|
-
private closeOld;
|
|
10
|
-
private connect;
|
|
11
|
-
on(event: string, cb: (data: any) => void): string;
|
|
12
|
-
cancel(id: any): void;
|
|
13
|
-
destroy(): void;
|
|
14
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
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
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __read = this && this.__read || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o),
|
|
17
|
-
r,
|
|
18
|
-
ar = [],
|
|
19
|
-
e;
|
|
20
|
-
try {
|
|
21
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
e = {
|
|
24
|
-
error: error
|
|
25
|
-
};
|
|
26
|
-
} finally {
|
|
27
|
-
try {
|
|
28
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
29
|
-
} finally {
|
|
30
|
-
if (e) throw e.error;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return ar;
|
|
34
|
-
};
|
|
35
|
-
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
36
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
37
|
-
if (ar || !(i in from)) {
|
|
38
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
39
|
-
ar[i] = from[i];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", {
|
|
45
|
-
value: true
|
|
46
|
-
});
|
|
47
|
-
exports.RTSP2Mpeg = void 0;
|
|
48
|
-
var child_process_1 = require("child_process");
|
|
49
|
-
var pubo_utils_1 = require("pubo-utils");
|
|
50
|
-
var RTSP2Mpeg = /** @class */function () {
|
|
51
|
-
function RTSP2Mpeg(url, options) {
|
|
52
|
-
var _this = this;
|
|
53
|
-
this.eventEmitter = new pubo_utils_1.Emitter();
|
|
54
|
-
this.dog = new pubo_utils_1.WatchDog({
|
|
55
|
-
limit: 10,
|
|
56
|
-
onTimeout: function onTimeout() {
|
|
57
|
-
return _this.connect();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
this.url = url;
|
|
61
|
-
this.options = __assign({}, options);
|
|
62
|
-
if (!this.options.input) {
|
|
63
|
-
this.options.input = ['-rtsp_transport', 'tcp', '-i'];
|
|
64
|
-
}
|
|
65
|
-
if (!this.options.output) {
|
|
66
|
-
this.options.output = ['-f', 'mpegts', '-codec:v', 'mpeg1video'];
|
|
67
|
-
}
|
|
68
|
-
this.connect();
|
|
69
|
-
this.dog.init();
|
|
70
|
-
}
|
|
71
|
-
RTSP2Mpeg.prototype.onMessage = function (msg) {
|
|
72
|
-
this.dog.feed();
|
|
73
|
-
this.eventEmitter.emit('message', msg.toString());
|
|
74
|
-
};
|
|
75
|
-
RTSP2Mpeg.prototype.closeOld = function () {
|
|
76
|
-
if (this.s) {
|
|
77
|
-
console.log("LOG Video-Server: ".concat(this.url, " try to reconnect;"));
|
|
78
|
-
this.s.kill();
|
|
79
|
-
this.s = null;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
RTSP2Mpeg.prototype.connect = function () {
|
|
83
|
-
var _this = this;
|
|
84
|
-
this.closeOld();
|
|
85
|
-
var options = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(this.options.input), false), [this.url], false), __read(this.options.output), false), ['-'], false);
|
|
86
|
-
this.s = (0, child_process_1.spawn)('ffmpeg', options, {
|
|
87
|
-
detached: false
|
|
88
|
-
});
|
|
89
|
-
this.s.stderr.on('data', function (buffer) {
|
|
90
|
-
return _this.onMessage(buffer);
|
|
91
|
-
});
|
|
92
|
-
this.s.stdout.on('data', function (buffer) {
|
|
93
|
-
return _this.eventEmitter.emit('data', buffer);
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
RTSP2Mpeg.prototype.on = function (event, cb) {
|
|
97
|
-
return this.eventEmitter.on(event, cb);
|
|
98
|
-
};
|
|
99
|
-
RTSP2Mpeg.prototype.cancel = function (id) {
|
|
100
|
-
this.eventEmitter.cancel(id);
|
|
101
|
-
};
|
|
102
|
-
RTSP2Mpeg.prototype.destroy = function () {
|
|
103
|
-
this.eventEmitter.clear();
|
|
104
|
-
this.dog.stop();
|
|
105
|
-
if (this.s) {
|
|
106
|
-
this.s.kill();
|
|
107
|
-
this.s = null;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
return RTSP2Mpeg;
|
|
111
|
-
}();
|
|
112
|
-
exports.RTSP2Mpeg = RTSP2Mpeg;
|