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