pubo-node 1.0.67 → 1.0.69

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.
@@ -2,43 +2,29 @@ var __assign = this && this.__assign || function () {
2
2
  __assign = Object.assign || function (t) {
3
3
  for (var s, i = 1, n = arguments.length; i < n; i++) {
4
4
  s = arguments[i];
5
-
6
- for (var p in s) {
7
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
- }
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
9
6
  }
10
-
11
7
  return t;
12
8
  };
13
-
14
9
  return __assign.apply(this, arguments);
15
10
  };
16
-
17
11
  var __rest = this && this.__rest || function (s, e) {
18
12
  var t = {};
19
-
20
- for (var p in s) {
21
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
22
- }
23
-
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
24
14
  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
25
15
  if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
26
16
  }
27
17
  return t;
28
18
  };
29
-
30
19
  var __read = this && this.__read || function (o, n) {
31
20
  var m = typeof Symbol === "function" && o[Symbol.iterator];
32
21
  if (!m) return o;
33
22
  var i = m.call(o),
34
- r,
35
- ar = [],
36
- e;
37
-
23
+ r,
24
+ ar = [],
25
+ e;
38
26
  try {
39
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
40
- ar.push(r.value);
41
- }
27
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
42
28
  } catch (error) {
43
29
  e = {
44
30
  error: error
@@ -50,29 +36,24 @@ var __read = this && this.__read || function (o, n) {
50
36
  if (e) throw e.error;
51
37
  }
52
38
  }
53
-
54
39
  return ar;
55
40
  };
56
-
57
- var __spread = this && this.__spread || function () {
58
- for (var ar = [], i = 0; i < arguments.length; i++) {
59
- ar = ar.concat(__read(arguments[i]));
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
+ }
60
47
  }
61
-
62
- return ar;
48
+ return to.concat(ar || Array.prototype.slice.call(from));
63
49
  };
64
-
65
50
  import { readFileSync, writeFileSync } from 'fs';
66
51
  import { resolve } from 'path';
67
52
  import { RTSP2Mpeg } from './rtsp2mpeg';
68
-
69
- var VideoStorage =
70
- /** @class */
71
- function () {
53
+ var VideoStorage = /** @class */function () {
72
54
  function VideoStorage() {
73
55
  this.path = resolve('resources/temp/videos.json');
74
56
  }
75
-
76
57
  VideoStorage.prototype.async = function (data) {
77
58
  try {
78
59
  writeFileSync(this.path, JSON.stringify(data));
@@ -80,7 +61,6 @@ function () {
80
61
  console.log(err);
81
62
  }
82
63
  };
83
-
84
64
  Object.defineProperty(VideoStorage.prototype, "data", {
85
65
  get: function get() {
86
66
  try {
@@ -97,10 +77,7 @@ function () {
97
77
  });
98
78
  return VideoStorage;
99
79
  }();
100
-
101
- var RtspVideosManager =
102
- /** @class */
103
- function () {
80
+ var RtspVideosManager = /** @class */function () {
104
81
  function RtspVideosManager(videos) {
105
82
  this._system = [];
106
83
  this._customer = [];
@@ -115,86 +92,69 @@ function () {
115
92
  this._customer = this.storage.data || [];
116
93
  this.system = videos.map(function (_a) {
117
94
  var url = _a.url,
118
- options = __rest(_a, ["url"]);
119
-
95
+ options = __rest(_a, ["url"]);
120
96
  return new RTSP2Mpeg(url, options);
121
97
  });
122
98
  this.customer = this._customer.map(function (_a) {
123
99
  var url = _a.url,
124
- options = __rest(_a, ["url"]);
125
-
100
+ options = __rest(_a, ["url"]);
126
101
  return new RTSP2Mpeg(url, options);
127
102
  });
128
103
  }
129
-
130
104
  Object.defineProperty(RtspVideosManager.prototype, "list", {
131
105
  get: function get() {
132
- return __spread(this.system, this.customer);
106
+ return __spreadArray(__spreadArray([], __read(this.system), false), __read(this.customer), false);
133
107
  },
134
108
  enumerable: false,
135
109
  configurable: true
136
110
  });
137
-
138
111
  RtspVideosManager.prototype.getVideos = function () {
139
- return __spread(this._system, this._customer);
112
+ return __spreadArray(__spreadArray([], __read(this._system), false), __read(this._customer), false);
140
113
  };
141
-
142
114
  RtspVideosManager.prototype.create = function (conf) {
143
115
  if (this._customer.some(function (item) {
144
116
  return item.url === conf.url;
145
117
  })) {
146
118
  throw new Error('该地址已存在');
147
119
  }
148
-
149
120
  var video = new RTSP2Mpeg(conf.url, conf);
150
-
151
121
  this._customer.push(conf);
152
-
153
122
  this.customer.push(video);
154
123
  this.storage.async(this._customer);
155
124
  };
156
-
157
125
  RtspVideosManager.prototype.remove = function (index) {
158
126
  if (index < this.system.length) {
159
127
  throw new Error('系统配置不可删除');
160
128
  } else if (index > this.system.length + this.customer.length - 1) {
161
129
  throw new Error('超限');
162
130
  }
163
-
164
131
  this._customer.splice(index - this.system.length - 1, 1);
165
-
166
132
  var video = this.customer.splice(index - this.system.length - 1, 1);
167
133
  video[0].destroy();
168
134
  this.storage.async(this._customer);
169
135
  };
170
-
171
136
  return RtspVideosManager;
172
137
  }();
173
-
174
138
  export { RtspVideosManager };
175
139
  export var initRtspVideos = function initRtspVideos(_a) {
176
140
  var app = _a.app,
177
- server = _a.server,
178
- videos = _a.videos,
179
- path = _a.path,
180
- expressWs = _a.expressWs;
141
+ server = _a.server,
142
+ videos = _a.videos,
143
+ path = _a.path,
144
+ expressWs = _a.expressWs;
181
145
  var manager = new RtspVideosManager(videos);
182
-
183
146
  if (!app.ws) {
184
147
  expressWs(app, server);
185
148
  }
186
-
187
149
  app.ws(path, function (ws, req) {
188
150
  var _a = req.query.channel,
189
- channel = _a === void 0 ? 0 : _a;
151
+ channel = _a === void 0 ? 0 : _a;
190
152
  var listener = null;
191
-
192
153
  if (manager.list[channel]) {
193
154
  listener = manager.list[channel].on('data', function (chunk) {
194
155
  ws.send(chunk);
195
156
  });
196
157
  }
197
-
198
158
  ws.on('close', function () {
199
159
  if (listener && manager.list[channel]) {
200
160
  manager.list[channel].cancel(listener);
@@ -2,30 +2,21 @@ var __assign = this && this.__assign || function () {
2
2
  __assign = Object.assign || function (t) {
3
3
  for (var s, i = 1, n = arguments.length; i < n; i++) {
4
4
  s = arguments[i];
5
-
6
- for (var p in s) {
7
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
- }
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
9
6
  }
10
-
11
7
  return t;
12
8
  };
13
-
14
9
  return __assign.apply(this, arguments);
15
10
  };
16
-
17
11
  var __read = this && this.__read || function (o, n) {
18
12
  var m = typeof Symbol === "function" && o[Symbol.iterator];
19
13
  if (!m) return o;
20
14
  var i = m.call(o),
21
- r,
22
- ar = [],
23
- e;
24
-
15
+ r,
16
+ ar = [],
17
+ e;
25
18
  try {
26
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
27
- ar.push(r.value);
28
- }
19
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
29
20
  } catch (error) {
30
21
  e = {
31
22
  error: error
@@ -37,27 +28,22 @@ var __read = this && this.__read || function (o, n) {
37
28
  if (e) throw e.error;
38
29
  }
39
30
  }
40
-
41
31
  return ar;
42
32
  };
43
-
44
- var __spread = this && this.__spread || function () {
45
- for (var ar = [], i = 0; i < arguments.length; i++) {
46
- ar = ar.concat(__read(arguments[i]));
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
+ }
47
39
  }
48
-
49
- return ar;
40
+ return to.concat(ar || Array.prototype.slice.call(from));
50
41
  };
51
-
52
42
  import { spawn } from 'child_process';
53
43
  import { Emitter, WatchDog } from 'pubo-utils';
54
-
55
- var RTSP2Mpeg =
56
- /** @class */
57
- function () {
44
+ var RTSP2Mpeg = /** @class */function () {
58
45
  function RTSP2Mpeg(url, options) {
59
46
  var _this = this;
60
-
61
47
  this.eventEmitter = new Emitter();
62
48
  this.dog = new WatchDog({
63
49
  limit: 10,
@@ -67,39 +53,30 @@ function () {
67
53
  });
68
54
  this.url = url;
69
55
  this.options = __assign({}, options);
70
-
71
56
  if (!this.options.input) {
72
57
  this.options.input = ['-rtsp_transport', 'tcp', '-i'];
73
58
  }
74
-
75
59
  if (!this.options.output) {
76
60
  this.options.output = ['-f', 'mpegts', '-codec:v', 'mpeg1video'];
77
61
  }
78
-
79
62
  this.connect();
80
63
  this.dog.init();
81
64
  }
82
-
83
65
  RTSP2Mpeg.prototype.onMessage = function (msg) {
84
66
  this.dog.feed();
85
67
  this.eventEmitter.emit('message', msg.toString());
86
68
  };
87
-
88
69
  RTSP2Mpeg.prototype.closeOld = function () {
89
70
  if (this.s) {
90
- console.log("LOG Video-Server: " + this.url + " try to reconnect;");
71
+ console.log("LOG Video-Server: ".concat(this.url, " try to reconnect;"));
91
72
  this.s.kill();
92
73
  this.s = null;
93
74
  }
94
75
  };
95
-
96
76
  RTSP2Mpeg.prototype.connect = function () {
97
77
  var _this = this;
98
-
99
78
  this.closeOld();
100
-
101
- var options = __spread(this.options.input, [this.url], this.options.output, ['-']);
102
-
79
+ var options = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(this.options.input), false), [this.url], false), __read(this.options.output), false), ['-'], false);
103
80
  this.s = spawn('ffmpeg', options, {
104
81
  detached: false
105
82
  });
@@ -110,26 +87,20 @@ function () {
110
87
  return _this.eventEmitter.emit('data', buffer);
111
88
  });
112
89
  };
113
-
114
90
  RTSP2Mpeg.prototype.on = function (event, cb) {
115
91
  return this.eventEmitter.on(event, cb);
116
92
  };
117
-
118
93
  RTSP2Mpeg.prototype.cancel = function (id) {
119
94
  this.eventEmitter.cancel(id);
120
95
  };
121
-
122
96
  RTSP2Mpeg.prototype.destroy = function () {
123
97
  this.eventEmitter.clear();
124
98
  this.dog.stop();
125
-
126
99
  if (this.s) {
127
100
  this.s.kill();
128
101
  this.s = null;
129
102
  }
130
103
  };
131
-
132
104
  return RTSP2Mpeg;
133
105
  }();
134
-
135
106
  export { RTSP2Mpeg };
@@ -2,30 +2,20 @@ var __assign = this && this.__assign || function () {
2
2
  __assign = Object.assign || function (t) {
3
3
  for (var s, i = 1, n = arguments.length; i < n; i++) {
4
4
  s = arguments[i];
5
-
6
- for (var p in s) {
7
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
- }
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
9
6
  }
10
-
11
7
  return t;
12
8
  };
13
-
14
9
  return __assign.apply(this, arguments);
15
10
  };
16
-
17
11
  import { readFileSync, writeFile } from 'fs';
18
12
  import * as pako from 'pako';
19
-
20
- var JsonStorage =
21
- /** @class */
22
- function () {
13
+ var JsonStorage = /** @class */function () {
23
14
  function JsonStorage(path) {
24
15
  this._state = {};
25
16
  this.path = path;
26
17
  this.init();
27
18
  }
28
-
29
19
  JsonStorage.prototype.init = function () {
30
20
  try {
31
21
  var buf = readFileSync(this.path);
@@ -37,7 +27,6 @@ function () {
37
27
  this.state = {};
38
28
  }
39
29
  };
40
-
41
30
  Object.defineProperty(JsonStorage.prototype, "state", {
42
31
  get: function get() {
43
32
  return this._state;
@@ -53,7 +42,6 @@ function () {
53
42
  enumerable: false,
54
43
  configurable: true
55
44
  });
56
-
57
45
  JsonStorage.prototype.get = function (key) {
58
46
  if (!key) {
59
47
  return __assign({}, this.state);
@@ -61,19 +49,14 @@ function () {
61
49
  return this.state[key];
62
50
  }
63
51
  };
64
-
65
52
  JsonStorage.prototype.set = function (key, values) {
66
53
  var temp = __assign({}, this.state);
67
-
68
54
  temp[key] = values;
69
55
  this.state = temp;
70
56
  };
71
-
72
57
  JsonStorage.prototype.merge = function (values) {
73
58
  this.state = __assign(__assign({}, this._state), values);
74
59
  };
75
-
76
60
  return JsonStorage;
77
61
  }();
78
-
79
62
  export { JsonStorage };
@@ -1,4 +1,7 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
2
5
  import type EventEmitter from 'events';
3
6
  import * as fs from 'fs';
4
7
  interface PuboFileSystemInterface {
@@ -2,17 +2,20 @@
2
2
 
3
3
  var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, {
6
- enumerable: true,
7
- get: function get() {
8
- return m[k];
9
- }
10
- });
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function get() {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
11
15
  } : function (o, m, k, k2) {
12
16
  if (k2 === undefined) k2 = k;
13
17
  o[k2] = m[k];
14
18
  });
15
-
16
19
  var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
17
20
  Object.defineProperty(o, "default", {
18
21
  enumerable: true,
@@ -21,31 +24,22 @@ var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? fun
21
24
  } : function (o, v) {
22
25
  o["default"] = v;
23
26
  });
24
-
25
27
  var __importStar = this && this.__importStar || function (mod) {
26
28
  if (mod && mod.__esModule) return mod;
27
29
  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
-
30
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
32
31
  __setModuleDefault(result, mod);
33
-
34
32
  return result;
35
33
  };
36
-
37
34
  var __read = this && this.__read || function (o, n) {
38
35
  var m = typeof Symbol === "function" && o[Symbol.iterator];
39
36
  if (!m) return o;
40
37
  var i = m.call(o),
41
- r,
42
- ar = [],
43
- e;
44
-
38
+ r,
39
+ ar = [],
40
+ e;
45
41
  try {
46
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
47
- ar.push(r.value);
48
- }
42
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
49
43
  } catch (error) {
50
44
  e = {
51
45
  error: error
@@ -57,55 +51,46 @@ var __read = this && this.__read || function (o, n) {
57
51
  if (e) throw e.error;
58
52
  }
59
53
  }
60
-
61
54
  return ar;
62
55
  };
63
-
64
- var __spread = this && this.__spread || function () {
65
- for (var ar = [], i = 0; i < arguments.length; i++) {
66
- ar = ar.concat(__read(arguments[i]));
56
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
57
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
58
+ if (ar || !(i in from)) {
59
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
60
+ ar[i] = from[i];
61
+ }
67
62
  }
68
-
69
- return ar;
63
+ return to.concat(ar || Array.prototype.slice.call(from));
70
64
  };
71
-
72
65
  Object.defineProperty(exports, "__esModule", {
73
66
  value: true
74
67
  });
75
68
  exports.PuboFileSystem = void 0;
76
-
77
69
  var fs = __importStar(require("fs"));
78
-
79
70
  var callbackToPromise = function callbackToPromise(fn) {
80
71
  return function () {
81
72
  var args = [];
82
-
83
73
  for (var _i = 0; _i < arguments.length; _i++) {
84
74
  args[_i] = arguments[_i];
85
75
  }
86
-
87
76
  return new Promise(function (resolve, reject) {
88
- fn.apply(void 0, __spread(args, [function (err) {
77
+ fn.apply(void 0, __spreadArray(__spreadArray([], __read(args), false), [function (err) {
89
78
  var rest = [];
90
-
91
79
  for (var _i = 1; _i < arguments.length; _i++) {
92
80
  rest[_i - 1] = arguments[_i];
93
81
  }
94
-
95
82
  if (err) {
96
83
  reject(err);
97
84
  }
98
-
99
85
  if (rest.length < 2) {
100
86
  resolve(rest[0]);
101
87
  } else {
102
- resolve(__spread(rest));
88
+ resolve(__spreadArray([], __read(rest), false));
103
89
  }
104
- }]));
90
+ }], false));
105
91
  });
106
92
  };
107
93
  };
108
-
109
94
  exports.PuboFileSystem = {
110
95
  read: callbackToPromise(fs.read),
111
96
  readFile: callbackToPromise(fs.readFile),
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import type { Stream } from 'stream';
3
4
  interface FtpFile {
4
5
  name: string;
@@ -13,11 +14,11 @@ interface FtpConnectOptions {
13
14
  host: string;
14
15
  password: string;
15
16
  }
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>;
17
+ type GetFile = (path: string) => Promise<Stream>;
18
+ type PutFile = (input: string | Buffer | Stream, path: string) => Promise<string>;
19
+ type DeleteFile = (path: string) => Promise<string>;
20
+ type ListFiles = (path: string) => Promise<FtpFile[]>;
21
+ type RenameFile = (path: string, old: string) => Promise<string>;
21
22
  export declare class FtpClient {
22
23
  private readonly driver;
23
24
  private readonly options;