pubo-node 1.0.5-alpha.0 → 1.0.7
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/ftp-client/index.d.ts +38 -0
- package/es/ftp-client/index.js +313 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/es/rtsp-video/index.d.ts +2 -1
- package/es/rtsp-video/index.js +2 -2
- package/lib/ftp-client/index.d.ts +38 -0
- package/lib/ftp-client/index.js +320 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +10 -1
- package/lib/rtsp-video/index.d.ts +2 -1
- package/lib/rtsp-video/index.js +2 -37
- package/package.json +3 -5
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(
|
|
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=3)}([function(t,e){t.exports=require("pubo-utils")},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,"initRtspVideos",(function(){return y})),n.d(e,"md5",(function(){return p})),n.d(e,"FtpClient",(function(){return f}));var r=n(0),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)},i=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())}))},u=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])}}},c=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},s=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),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},a=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(s(arguments[e]));return t},f=function(){function t(t){var e=t.driver,n=c(t,["driver"]);this.queue=new r.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,a([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 i(e,void 0,void 0,(function(){var e;return u(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,a(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}(),l=n(2),p=function(t){return Object(l.createHash)("md5").update(t).digest("hex")},d=n(1),h=function(){function t(t){var e=this;this.eventEmitter=new r.Emitter,this.dog=new r.WatchDog({limit:10,onTimeout:function(){return e.connect()}}),this.url=t,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=["-rtsp_transport","tcp","-i",this.url,"-f","mpegts","-codec:v","mpeg1video","-"];this.s=Object(d.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}(),y=function(t){var e=t.app,n=t.server,r=t.videos,o=t.path,i=t.expressWs,u=r.map((function(t){return new h(t)}));return 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}}])}));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Stream } from 'stream';
|
|
3
|
+
interface FtpFile {
|
|
4
|
+
name: string;
|
|
5
|
+
owner: string;
|
|
6
|
+
group: string;
|
|
7
|
+
size: number;
|
|
8
|
+
date: Date;
|
|
9
|
+
type: string;
|
|
10
|
+
}
|
|
11
|
+
interface FtpConnectOptions {
|
|
12
|
+
user: string;
|
|
13
|
+
host: string;
|
|
14
|
+
password: string;
|
|
15
|
+
}
|
|
16
|
+
declare type GetFile = (path: string) => Promise<Stream>;
|
|
17
|
+
declare type PutFile = (input: string | Buffer | Stream, path: string) => Promise<string>;
|
|
18
|
+
declare type DeleteFile = (path: string) => Promise<string>;
|
|
19
|
+
declare type ListFiles = (path: string) => Promise<FtpFile[]>;
|
|
20
|
+
declare type RenameFile = (path: string, old: string) => Promise<string>;
|
|
21
|
+
export declare class FtpClient {
|
|
22
|
+
private readonly driver;
|
|
23
|
+
private readonly options;
|
|
24
|
+
private readonly queue;
|
|
25
|
+
constructor({ driver, ...options }: {
|
|
26
|
+
driver: any;
|
|
27
|
+
} & FtpConnectOptions);
|
|
28
|
+
get: GetFile;
|
|
29
|
+
put: PutFile;
|
|
30
|
+
delete: DeleteFile;
|
|
31
|
+
list: ListFiles;
|
|
32
|
+
rename: RenameFile;
|
|
33
|
+
private _push;
|
|
34
|
+
private _bind;
|
|
35
|
+
private _run;
|
|
36
|
+
private connect;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
var __assign = this && this.__assign || function () {
|
|
2
|
+
__assign = Object.assign || function (t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
|
|
6
|
+
for (var p in s) {
|
|
7
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return __assign.apply(this, arguments);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) {
|
|
19
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
20
|
+
resolve(value);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25
|
+
function fulfilled(value) {
|
|
26
|
+
try {
|
|
27
|
+
step(generator.next(value));
|
|
28
|
+
} catch (e) {
|
|
29
|
+
reject(e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function rejected(value) {
|
|
34
|
+
try {
|
|
35
|
+
step(generator["throw"](value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function step(result) {
|
|
42
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
50
|
+
var _ = {
|
|
51
|
+
label: 0,
|
|
52
|
+
sent: function sent() {
|
|
53
|
+
if (t[0] & 1) throw t[1];
|
|
54
|
+
return t[1];
|
|
55
|
+
},
|
|
56
|
+
trys: [],
|
|
57
|
+
ops: []
|
|
58
|
+
},
|
|
59
|
+
f,
|
|
60
|
+
y,
|
|
61
|
+
t,
|
|
62
|
+
g;
|
|
63
|
+
return g = {
|
|
64
|
+
next: verb(0),
|
|
65
|
+
"throw": verb(1),
|
|
66
|
+
"return": verb(2)
|
|
67
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
68
|
+
return this;
|
|
69
|
+
}), g;
|
|
70
|
+
|
|
71
|
+
function verb(n) {
|
|
72
|
+
return function (v) {
|
|
73
|
+
return step([n, v]);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function step(op) {
|
|
78
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
79
|
+
|
|
80
|
+
while (_) {
|
|
81
|
+
try {
|
|
82
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
83
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
84
|
+
|
|
85
|
+
switch (op[0]) {
|
|
86
|
+
case 0:
|
|
87
|
+
case 1:
|
|
88
|
+
t = op;
|
|
89
|
+
break;
|
|
90
|
+
|
|
91
|
+
case 4:
|
|
92
|
+
_.label++;
|
|
93
|
+
return {
|
|
94
|
+
value: op[1],
|
|
95
|
+
done: false
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
case 5:
|
|
99
|
+
_.label++;
|
|
100
|
+
y = op[1];
|
|
101
|
+
op = [0];
|
|
102
|
+
continue;
|
|
103
|
+
|
|
104
|
+
case 7:
|
|
105
|
+
op = _.ops.pop();
|
|
106
|
+
|
|
107
|
+
_.trys.pop();
|
|
108
|
+
|
|
109
|
+
continue;
|
|
110
|
+
|
|
111
|
+
default:
|
|
112
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
113
|
+
_ = 0;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
118
|
+
_.label = op[1];
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
123
|
+
_.label = t[1];
|
|
124
|
+
t = op;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (t && _.label < t[2]) {
|
|
129
|
+
_.label = t[2];
|
|
130
|
+
|
|
131
|
+
_.ops.push(op);
|
|
132
|
+
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (t[2]) _.ops.pop();
|
|
137
|
+
|
|
138
|
+
_.trys.pop();
|
|
139
|
+
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
op = body.call(thisArg, _);
|
|
144
|
+
} catch (e) {
|
|
145
|
+
op = [6, e];
|
|
146
|
+
y = 0;
|
|
147
|
+
} finally {
|
|
148
|
+
f = t = 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (op[0] & 5) throw op[1];
|
|
153
|
+
return {
|
|
154
|
+
value: op[0] ? op[1] : void 0,
|
|
155
|
+
done: true
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
161
|
+
var t = {};
|
|
162
|
+
|
|
163
|
+
for (var p in s) {
|
|
164
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
168
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
169
|
+
}
|
|
170
|
+
return t;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
var __read = this && this.__read || function (o, n) {
|
|
174
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
175
|
+
if (!m) return o;
|
|
176
|
+
var i = m.call(o),
|
|
177
|
+
r,
|
|
178
|
+
ar = [],
|
|
179
|
+
e;
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
183
|
+
ar.push(r.value);
|
|
184
|
+
}
|
|
185
|
+
} catch (error) {
|
|
186
|
+
e = {
|
|
187
|
+
error: error
|
|
188
|
+
};
|
|
189
|
+
} finally {
|
|
190
|
+
try {
|
|
191
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
192
|
+
} finally {
|
|
193
|
+
if (e) throw e.error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return ar;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
var __spread = this && this.__spread || function () {
|
|
201
|
+
for (var ar = [], i = 0; i < arguments.length; i++) {
|
|
202
|
+
ar = ar.concat(__read(arguments[i]));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return ar;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
import { SyncQueue } from 'pubo-utils';
|
|
209
|
+
|
|
210
|
+
var FtpClient =
|
|
211
|
+
/** @class */
|
|
212
|
+
function () {
|
|
213
|
+
function FtpClient(_a) {
|
|
214
|
+
var driver = _a.driver,
|
|
215
|
+
options = __rest(_a, ["driver"]);
|
|
216
|
+
|
|
217
|
+
this.queue = new SyncQueue();
|
|
218
|
+
this.get = this._bind('get');
|
|
219
|
+
this.put = this._bind('put');
|
|
220
|
+
this["delete"] = this._bind('delete');
|
|
221
|
+
this.list = this._bind('list');
|
|
222
|
+
this.rename = this._bind('rename');
|
|
223
|
+
this.driver = driver;
|
|
224
|
+
this.options = options;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
FtpClient.prototype._push = function (cb) {
|
|
228
|
+
var _this = this;
|
|
229
|
+
|
|
230
|
+
return function () {
|
|
231
|
+
var args = [];
|
|
232
|
+
|
|
233
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
234
|
+
args[_i] = arguments[_i];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return _this.queue.push(function () {
|
|
238
|
+
return cb.call.apply(cb, __spread([_this], args));
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
FtpClient.prototype._bind = function (fn) {
|
|
244
|
+
var _this = this;
|
|
245
|
+
|
|
246
|
+
return this._push(function () {
|
|
247
|
+
var args = [];
|
|
248
|
+
|
|
249
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
250
|
+
args[_i] = arguments[_i];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
254
|
+
var c;
|
|
255
|
+
return __generator(this, function (_a) {
|
|
256
|
+
switch (_a.label) {
|
|
257
|
+
case 0:
|
|
258
|
+
return [4
|
|
259
|
+
/*yield*/
|
|
260
|
+
, this.connect()];
|
|
261
|
+
|
|
262
|
+
case 1:
|
|
263
|
+
c = _a.sent();
|
|
264
|
+
return [2
|
|
265
|
+
/*return*/
|
|
266
|
+
, this._run(fn, c, args)];
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
FtpClient.prototype._run = function (fn, c, args) {
|
|
274
|
+
return new Promise(function (resolve, reject) {
|
|
275
|
+
c[fn].apply(c, __spread(args, [function (err, res) {
|
|
276
|
+
if (err) {
|
|
277
|
+
reject(err);
|
|
278
|
+
c.end();
|
|
279
|
+
} else {
|
|
280
|
+
resolve(res || 'operation successful.');
|
|
281
|
+
|
|
282
|
+
if (fn === 'get') {
|
|
283
|
+
res.once('close', function () {
|
|
284
|
+
return c.end();
|
|
285
|
+
});
|
|
286
|
+
} else {
|
|
287
|
+
c.end();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}]));
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
FtpClient.prototype.connect = function () {
|
|
295
|
+
var _this = this;
|
|
296
|
+
|
|
297
|
+
return new Promise(function (resolve, reject) {
|
|
298
|
+
var c = new _this.driver();
|
|
299
|
+
c.once('ready', function () {
|
|
300
|
+
resolve(c);
|
|
301
|
+
});
|
|
302
|
+
c.once('error', function (err) {
|
|
303
|
+
reject(err);
|
|
304
|
+
c.end();
|
|
305
|
+
});
|
|
306
|
+
c.connect(__assign({}, _this.options));
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
return FtpClient;
|
|
311
|
+
}();
|
|
312
|
+
|
|
313
|
+
export { FtpClient };
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
package/es/rtsp-video/index.d.ts
CHANGED
package/es/rtsp-video/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as expressWs from 'express-ws';
|
|
2
1
|
import { RTSP2Mpeg } from './rtsp2mpeg';
|
|
3
2
|
export var initRtspVideos = function initRtspVideos(_a) {
|
|
4
3
|
var app = _a.app,
|
|
5
4
|
server = _a.server,
|
|
6
5
|
videos = _a.videos,
|
|
7
|
-
path = _a.path
|
|
6
|
+
path = _a.path,
|
|
7
|
+
expressWs = _a.expressWs;
|
|
8
8
|
var mpegList = videos.map(function (url) {
|
|
9
9
|
return new RTSP2Mpeg(url);
|
|
10
10
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Stream } from 'stream';
|
|
3
|
+
interface FtpFile {
|
|
4
|
+
name: string;
|
|
5
|
+
owner: string;
|
|
6
|
+
group: string;
|
|
7
|
+
size: number;
|
|
8
|
+
date: Date;
|
|
9
|
+
type: string;
|
|
10
|
+
}
|
|
11
|
+
interface FtpConnectOptions {
|
|
12
|
+
user: string;
|
|
13
|
+
host: string;
|
|
14
|
+
password: string;
|
|
15
|
+
}
|
|
16
|
+
declare type GetFile = (path: string) => Promise<Stream>;
|
|
17
|
+
declare type PutFile = (input: string | Buffer | Stream, path: string) => Promise<string>;
|
|
18
|
+
declare type DeleteFile = (path: string) => Promise<string>;
|
|
19
|
+
declare type ListFiles = (path: string) => Promise<FtpFile[]>;
|
|
20
|
+
declare type RenameFile = (path: string, old: string) => Promise<string>;
|
|
21
|
+
export declare class FtpClient {
|
|
22
|
+
private readonly driver;
|
|
23
|
+
private readonly options;
|
|
24
|
+
private readonly queue;
|
|
25
|
+
constructor({ driver, ...options }: {
|
|
26
|
+
driver: any;
|
|
27
|
+
} & FtpConnectOptions);
|
|
28
|
+
get: GetFile;
|
|
29
|
+
put: PutFile;
|
|
30
|
+
delete: DeleteFile;
|
|
31
|
+
list: ListFiles;
|
|
32
|
+
rename: RenameFile;
|
|
33
|
+
private _push;
|
|
34
|
+
private _bind;
|
|
35
|
+
private _run;
|
|
36
|
+
private connect;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __assign = this && this.__assign || function () {
|
|
4
|
+
__assign = Object.assign || function (t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
|
|
8
|
+
for (var p in s) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return __assign.apply(this, arguments);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
20
|
+
function adopt(value) {
|
|
21
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
22
|
+
resolve(value);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
27
|
+
function fulfilled(value) {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.next(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function rejected(value) {
|
|
36
|
+
try {
|
|
37
|
+
step(generator["throw"](value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function step(result) {
|
|
44
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
52
|
+
var _ = {
|
|
53
|
+
label: 0,
|
|
54
|
+
sent: function sent() {
|
|
55
|
+
if (t[0] & 1) throw t[1];
|
|
56
|
+
return t[1];
|
|
57
|
+
},
|
|
58
|
+
trys: [],
|
|
59
|
+
ops: []
|
|
60
|
+
},
|
|
61
|
+
f,
|
|
62
|
+
y,
|
|
63
|
+
t,
|
|
64
|
+
g;
|
|
65
|
+
return g = {
|
|
66
|
+
next: verb(0),
|
|
67
|
+
"throw": verb(1),
|
|
68
|
+
"return": verb(2)
|
|
69
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
70
|
+
return this;
|
|
71
|
+
}), g;
|
|
72
|
+
|
|
73
|
+
function verb(n) {
|
|
74
|
+
return function (v) {
|
|
75
|
+
return step([n, v]);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function step(op) {
|
|
80
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
81
|
+
|
|
82
|
+
while (_) {
|
|
83
|
+
try {
|
|
84
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
85
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
86
|
+
|
|
87
|
+
switch (op[0]) {
|
|
88
|
+
case 0:
|
|
89
|
+
case 1:
|
|
90
|
+
t = op;
|
|
91
|
+
break;
|
|
92
|
+
|
|
93
|
+
case 4:
|
|
94
|
+
_.label++;
|
|
95
|
+
return {
|
|
96
|
+
value: op[1],
|
|
97
|
+
done: false
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
case 5:
|
|
101
|
+
_.label++;
|
|
102
|
+
y = op[1];
|
|
103
|
+
op = [0];
|
|
104
|
+
continue;
|
|
105
|
+
|
|
106
|
+
case 7:
|
|
107
|
+
op = _.ops.pop();
|
|
108
|
+
|
|
109
|
+
_.trys.pop();
|
|
110
|
+
|
|
111
|
+
continue;
|
|
112
|
+
|
|
113
|
+
default:
|
|
114
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
115
|
+
_ = 0;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
120
|
+
_.label = op[1];
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
125
|
+
_.label = t[1];
|
|
126
|
+
t = op;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (t && _.label < t[2]) {
|
|
131
|
+
_.label = t[2];
|
|
132
|
+
|
|
133
|
+
_.ops.push(op);
|
|
134
|
+
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (t[2]) _.ops.pop();
|
|
139
|
+
|
|
140
|
+
_.trys.pop();
|
|
141
|
+
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
op = body.call(thisArg, _);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
op = [6, e];
|
|
148
|
+
y = 0;
|
|
149
|
+
} finally {
|
|
150
|
+
f = t = 0;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (op[0] & 5) throw op[1];
|
|
155
|
+
return {
|
|
156
|
+
value: op[0] ? op[1] : void 0,
|
|
157
|
+
done: true
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
163
|
+
var t = {};
|
|
164
|
+
|
|
165
|
+
for (var p in s) {
|
|
166
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
170
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
171
|
+
}
|
|
172
|
+
return t;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
var __read = this && this.__read || function (o, n) {
|
|
176
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
177
|
+
if (!m) return o;
|
|
178
|
+
var i = m.call(o),
|
|
179
|
+
r,
|
|
180
|
+
ar = [],
|
|
181
|
+
e;
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
185
|
+
ar.push(r.value);
|
|
186
|
+
}
|
|
187
|
+
} catch (error) {
|
|
188
|
+
e = {
|
|
189
|
+
error: error
|
|
190
|
+
};
|
|
191
|
+
} finally {
|
|
192
|
+
try {
|
|
193
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
194
|
+
} finally {
|
|
195
|
+
if (e) throw e.error;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return ar;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
var __spread = this && this.__spread || function () {
|
|
203
|
+
for (var ar = [], i = 0; i < arguments.length; i++) {
|
|
204
|
+
ar = ar.concat(__read(arguments[i]));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return ar;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
Object.defineProperty(exports, "__esModule", {
|
|
211
|
+
value: true
|
|
212
|
+
});
|
|
213
|
+
exports.FtpClient = void 0;
|
|
214
|
+
|
|
215
|
+
var pubo_utils_1 = require("pubo-utils");
|
|
216
|
+
|
|
217
|
+
var FtpClient =
|
|
218
|
+
/** @class */
|
|
219
|
+
function () {
|
|
220
|
+
function FtpClient(_a) {
|
|
221
|
+
var driver = _a.driver,
|
|
222
|
+
options = __rest(_a, ["driver"]);
|
|
223
|
+
|
|
224
|
+
this.queue = new pubo_utils_1.SyncQueue();
|
|
225
|
+
this.get = this._bind('get');
|
|
226
|
+
this.put = this._bind('put');
|
|
227
|
+
this["delete"] = this._bind('delete');
|
|
228
|
+
this.list = this._bind('list');
|
|
229
|
+
this.rename = this._bind('rename');
|
|
230
|
+
this.driver = driver;
|
|
231
|
+
this.options = options;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
FtpClient.prototype._push = function (cb) {
|
|
235
|
+
var _this = this;
|
|
236
|
+
|
|
237
|
+
return function () {
|
|
238
|
+
var args = [];
|
|
239
|
+
|
|
240
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
241
|
+
args[_i] = arguments[_i];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return _this.queue.push(function () {
|
|
245
|
+
return cb.call.apply(cb, __spread([_this], args));
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
FtpClient.prototype._bind = function (fn) {
|
|
251
|
+
var _this = this;
|
|
252
|
+
|
|
253
|
+
return this._push(function () {
|
|
254
|
+
var args = [];
|
|
255
|
+
|
|
256
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
257
|
+
args[_i] = arguments[_i];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
261
|
+
var c;
|
|
262
|
+
return __generator(this, function (_a) {
|
|
263
|
+
switch (_a.label) {
|
|
264
|
+
case 0:
|
|
265
|
+
return [4
|
|
266
|
+
/*yield*/
|
|
267
|
+
, this.connect()];
|
|
268
|
+
|
|
269
|
+
case 1:
|
|
270
|
+
c = _a.sent();
|
|
271
|
+
return [2
|
|
272
|
+
/*return*/
|
|
273
|
+
, this._run(fn, c, args)];
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
FtpClient.prototype._run = function (fn, c, args) {
|
|
281
|
+
return new Promise(function (resolve, reject) {
|
|
282
|
+
c[fn].apply(c, __spread(args, [function (err, res) {
|
|
283
|
+
if (err) {
|
|
284
|
+
reject(err);
|
|
285
|
+
c.end();
|
|
286
|
+
} else {
|
|
287
|
+
resolve(res || 'operation successful.');
|
|
288
|
+
|
|
289
|
+
if (fn === 'get') {
|
|
290
|
+
res.once('close', function () {
|
|
291
|
+
return c.end();
|
|
292
|
+
});
|
|
293
|
+
} else {
|
|
294
|
+
c.end();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}]));
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
FtpClient.prototype.connect = function () {
|
|
302
|
+
var _this = this;
|
|
303
|
+
|
|
304
|
+
return new Promise(function (resolve, reject) {
|
|
305
|
+
var c = new _this.driver();
|
|
306
|
+
c.once('ready', function () {
|
|
307
|
+
resolve(c);
|
|
308
|
+
});
|
|
309
|
+
c.once('error', function (err) {
|
|
310
|
+
reject(err);
|
|
311
|
+
c.end();
|
|
312
|
+
});
|
|
313
|
+
c.connect(__assign({}, _this.options));
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
return FtpClient;
|
|
318
|
+
}();
|
|
319
|
+
|
|
320
|
+
exports.FtpClient = FtpClient;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -3,7 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.md5 = exports.initRtspVideos = void 0;
|
|
6
|
+
exports.FtpClient = exports.md5 = exports.initRtspVideos = void 0;
|
|
7
|
+
|
|
8
|
+
var ftp_client_1 = require("./ftp-client");
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, "FtpClient", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return ftp_client_1.FtpClient;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
7
16
|
|
|
8
17
|
var md5_1 = require("./md5");
|
|
9
18
|
|
package/lib/rtsp-video/index.js
CHANGED
|
@@ -1,53 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.defineProperty(o, k2, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function get() {
|
|
8
|
-
return m[k];
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
} : function (o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
o[k2] = m[k];
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
|
|
17
|
-
Object.defineProperty(o, "default", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
value: v
|
|
20
|
-
});
|
|
21
|
-
} : function (o, v) {
|
|
22
|
-
o["default"] = v;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
var __importStar = this && this.__importStar || function (mod) {
|
|
26
|
-
if (mod && mod.__esModule) return mod;
|
|
27
|
-
var result = {};
|
|
28
|
-
if (mod != null) for (var k in mod) {
|
|
29
|
-
if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
3
|
Object.defineProperty(exports, "__esModule", {
|
|
38
4
|
value: true
|
|
39
5
|
});
|
|
40
6
|
exports.initRtspVideos = void 0;
|
|
41
7
|
|
|
42
|
-
var expressWs = __importStar(require("express-ws"));
|
|
43
|
-
|
|
44
8
|
var rtsp2mpeg_1 = require("./rtsp2mpeg");
|
|
45
9
|
|
|
46
10
|
exports.initRtspVideos = function (_a) {
|
|
47
11
|
var app = _a.app,
|
|
48
12
|
server = _a.server,
|
|
49
13
|
videos = _a.videos,
|
|
50
|
-
path = _a.path
|
|
14
|
+
path = _a.path,
|
|
15
|
+
expressWs = _a.expressWs;
|
|
51
16
|
var mpegList = videos.map(function (url) {
|
|
52
17
|
return new rtsp2mpeg_1.RTSP2Mpeg(url);
|
|
53
18
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -20,9 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@types/node": "^17.0.25",
|
|
23
|
-
"
|
|
24
|
-
"express-ws": "^5.0.2",
|
|
25
|
-
"pubo-utils": "^1.0.5-alpha.0"
|
|
23
|
+
"pubo-utils": "^1.0.7"
|
|
26
24
|
},
|
|
27
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "3da950516770c3ba0e9fa03263f61cbf84d102e1"
|
|
28
26
|
}
|