pubo-node 1.0.66 → 1.0.68

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