pubo-node 1.0.141 → 1.0.142
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/child-process/index.js +270 -340
- package/es/file-system/index.js +8 -41
- package/es/ftp-client/index.js +194 -345
- package/es/grpc/index.d.ts +4 -2
- package/es/grpc/index.js +149 -195
- package/es/ros/topic.js +11 -8
- package/es/storage/json.js +212 -358
- package/es/utils/network.js +33 -141
- package/lib/child-process/index.js +263 -334
- package/lib/file-system/index.js +8 -41
- package/lib/ftp-client/index.js +193 -342
- package/lib/grpc/index.d.ts +4 -2
- package/lib/grpc/index.js +149 -195
- package/lib/ros/topic.js +11 -7
- package/lib/storage/json.js +207 -353
- package/lib/utils/network.js +34 -142
- package/package.json +3 -3
package/es/grpc/index.js
CHANGED
|
@@ -1,141 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
6
|
-
}
|
|
7
|
-
return t;
|
|
8
|
-
};
|
|
9
|
-
return __assign.apply(this, arguments);
|
|
10
|
-
};
|
|
11
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
12
|
-
function adopt(value) {
|
|
13
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
14
|
-
resolve(value);
|
|
15
|
-
});
|
|
1
|
+
function _empty() {}
|
|
2
|
+
function _awaitIgnored(value, direct) {
|
|
3
|
+
if (!direct) {
|
|
4
|
+
return value && value.then ? value.then(_empty) : Promise.resolve();
|
|
16
5
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} catch (e) {
|
|
22
|
-
reject(e);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function rejected(value) {
|
|
26
|
-
try {
|
|
27
|
-
step(generator["throw"](value));
|
|
28
|
-
} catch (e) {
|
|
29
|
-
reject(e);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function step(result) {
|
|
33
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
34
|
-
}
|
|
35
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
var __generator = this && this.__generator || function (thisArg, body) {
|
|
39
|
-
var _ = {
|
|
40
|
-
label: 0,
|
|
41
|
-
sent: function sent() {
|
|
42
|
-
if (t[0] & 1) throw t[1];
|
|
43
|
-
return t[1];
|
|
44
|
-
},
|
|
45
|
-
trys: [],
|
|
46
|
-
ops: []
|
|
47
|
-
},
|
|
48
|
-
f,
|
|
49
|
-
y,
|
|
50
|
-
t,
|
|
51
|
-
g;
|
|
52
|
-
return g = {
|
|
53
|
-
next: verb(0),
|
|
54
|
-
"throw": verb(1),
|
|
55
|
-
"return": verb(2)
|
|
56
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
57
|
-
return this;
|
|
58
|
-
}), g;
|
|
59
|
-
function verb(n) {
|
|
60
|
-
return function (v) {
|
|
61
|
-
return step([n, v]);
|
|
62
|
-
};
|
|
6
|
+
}
|
|
7
|
+
function _await(value, then, direct) {
|
|
8
|
+
if (direct) {
|
|
9
|
+
return then ? then(value) : value;
|
|
63
10
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
99
|
-
_.label = t[1];
|
|
100
|
-
t = op;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
if (t && _.label < t[2]) {
|
|
104
|
-
_.label = t[2];
|
|
105
|
-
_.ops.push(op);
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
if (t[2]) _.ops.pop();
|
|
109
|
-
_.trys.pop();
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
op = body.call(thisArg, _);
|
|
11
|
+
if (!value || !value.then) {
|
|
12
|
+
value = Promise.resolve(value);
|
|
13
|
+
}
|
|
14
|
+
return then ? value.then(then) : value;
|
|
15
|
+
}
|
|
16
|
+
function _catch(body, recover) {
|
|
17
|
+
try {
|
|
18
|
+
var result = body();
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return recover(e);
|
|
21
|
+
}
|
|
22
|
+
if (result && result.then) {
|
|
23
|
+
return result.then(void 0, recover);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
function _continue(value, then) {
|
|
28
|
+
return value && value.then ? value.then(then) : then(value);
|
|
29
|
+
}
|
|
30
|
+
function _invoke(body, then) {
|
|
31
|
+
var result = body();
|
|
32
|
+
if (result && result.then) {
|
|
33
|
+
return result.then(then);
|
|
34
|
+
}
|
|
35
|
+
return then(result);
|
|
36
|
+
}
|
|
37
|
+
function _async(f) {
|
|
38
|
+
return function () {
|
|
39
|
+
for (var args = [], i = 0; i < arguments.length; i++) {
|
|
40
|
+
args[i] = arguments[i];
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
return Promise.resolve(f.apply(this, args));
|
|
113
44
|
} catch (e) {
|
|
114
|
-
|
|
115
|
-
y = 0;
|
|
116
|
-
} finally {
|
|
117
|
-
f = t = 0;
|
|
45
|
+
return Promise.reject(e);
|
|
118
46
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
};
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
50
|
+
import { sleep, waitFor } from 'pubo-utils';
|
|
126
51
|
function passThrough(argument) {
|
|
127
52
|
return argument;
|
|
128
53
|
}
|
|
129
|
-
var GrpcClient =
|
|
130
|
-
function GrpcClient(
|
|
131
|
-
var
|
|
132
|
-
|
|
133
|
-
options =
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
54
|
+
var GrpcClient = /*#__PURE__*/function () {
|
|
55
|
+
function GrpcClient(_ref) {
|
|
56
|
+
var _this$options$timeout;
|
|
57
|
+
var url = _ref.url,
|
|
58
|
+
_ref$options = _ref.options,
|
|
59
|
+
options = _ref$options === void 0 ? {} : _ref$options,
|
|
60
|
+
Grpc = _ref.Grpc,
|
|
61
|
+
cert = _ref.cert;
|
|
62
|
+
this.url = void 0;
|
|
63
|
+
this.options = void 0;
|
|
64
|
+
this.Grpc = void 0;
|
|
65
|
+
this.credentials = void 0;
|
|
66
|
+
this.client = void 0;
|
|
67
|
+
this._timeout = void 0;
|
|
137
68
|
this.connections = 0;
|
|
138
|
-
|
|
69
|
+
this.closing = false;
|
|
70
|
+
var opt = _extends({
|
|
139
71
|
'grpc.max_send_message_length': -1,
|
|
140
72
|
'grpc.max_receive_message_length': -1
|
|
141
73
|
}, options);
|
|
@@ -144,70 +76,76 @@ var GrpcClient = /** @class */function () {
|
|
|
144
76
|
this.Grpc = Grpc;
|
|
145
77
|
this.credentials = credentials;
|
|
146
78
|
this.options = opt;
|
|
147
|
-
this.options.timeout = (
|
|
79
|
+
this.options.timeout = (_this$options$timeout = this.options.timeout) != null ? _this$options$timeout : 60000;
|
|
148
80
|
}
|
|
149
|
-
GrpcClient.prototype
|
|
150
|
-
|
|
151
|
-
|
|
81
|
+
var _proto = GrpcClient.prototype;
|
|
82
|
+
_proto.request = function request(service, method, data) {
|
|
83
|
+
try {
|
|
152
84
|
var _this = this;
|
|
153
|
-
return
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
case 1:
|
|
162
|
-
_a.trys.push([1, 3,, 4]);
|
|
163
|
-
return [4 /*yield*/, this._request({
|
|
164
|
-
service: service,
|
|
165
|
-
method: method,
|
|
166
|
-
data: data
|
|
167
|
-
})];
|
|
168
|
-
case 2:
|
|
169
|
-
result = _a.sent();
|
|
170
|
-
return [3 /*break*/, 4];
|
|
171
|
-
case 3:
|
|
172
|
-
err_1 = _a.sent();
|
|
173
|
-
error = err_1;
|
|
174
|
-
return [3 /*break*/, 4];
|
|
175
|
-
case 4:
|
|
176
|
-
this.connections -= 1;
|
|
177
|
-
if (this.connections < 0) {
|
|
178
|
-
this.connections = 0;
|
|
179
|
-
}
|
|
180
|
-
if (this.connections < 1) {
|
|
181
|
-
if (this._timeout) {
|
|
182
|
-
clearTimeout(this._timeout);
|
|
183
|
-
this._timeout = null;
|
|
184
|
-
}
|
|
185
|
-
this._timeout = setTimeout(function () {
|
|
186
|
-
return _this.close();
|
|
187
|
-
}, 60000);
|
|
188
|
-
}
|
|
189
|
-
if (error) {
|
|
190
|
-
this.close();
|
|
191
|
-
throw new Error('grpc connection error.');
|
|
192
|
-
}
|
|
193
|
-
return [2 /*return*/, result];
|
|
85
|
+
return _await(_invoke(function () {
|
|
86
|
+
if (_this.closing) {
|
|
87
|
+
return _awaitIgnored(waitFor(_async(function () {
|
|
88
|
+
return !_this.closing;
|
|
89
|
+
}), {
|
|
90
|
+
checkTime: 100,
|
|
91
|
+
timeout: 20000
|
|
92
|
+
}));
|
|
194
93
|
}
|
|
195
|
-
})
|
|
196
|
-
|
|
94
|
+
}, function () {
|
|
95
|
+
_this.connections += 1;
|
|
96
|
+
if (!_this.client) {
|
|
97
|
+
_this.client = new _this.Grpc.Client(_this.url, _this.credentials, _this.options);
|
|
98
|
+
}
|
|
99
|
+
var error;
|
|
100
|
+
var result = Buffer.alloc(0);
|
|
101
|
+
return _continue(_catch(function () {
|
|
102
|
+
return _await(_this._request({
|
|
103
|
+
service: service,
|
|
104
|
+
method: method,
|
|
105
|
+
data: data
|
|
106
|
+
}), function (_this$_request) {
|
|
107
|
+
result = _this$_request;
|
|
108
|
+
});
|
|
109
|
+
}, function (err) {
|
|
110
|
+
error = err;
|
|
111
|
+
}), function () {
|
|
112
|
+
_this.connections -= 1;
|
|
113
|
+
if (_this.connections < 0) {
|
|
114
|
+
_this.connections = 0;
|
|
115
|
+
}
|
|
116
|
+
if (_this.connections < 1) {
|
|
117
|
+
if (_this._timeout) {
|
|
118
|
+
clearTimeout(_this._timeout);
|
|
119
|
+
_this._timeout = null;
|
|
120
|
+
}
|
|
121
|
+
_this._timeout = setTimeout(function () {
|
|
122
|
+
return _this.close();
|
|
123
|
+
}, 60000);
|
|
124
|
+
}
|
|
125
|
+
if (error) {
|
|
126
|
+
_this.restart();
|
|
127
|
+
throw new Error('grpc connection error.');
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
});
|
|
131
|
+
}));
|
|
132
|
+
} catch (e) {
|
|
133
|
+
return Promise.reject(e);
|
|
134
|
+
}
|
|
197
135
|
};
|
|
198
|
-
|
|
199
|
-
var
|
|
200
|
-
var service =
|
|
201
|
-
method =
|
|
202
|
-
data =
|
|
136
|
+
_proto._request = function _request(_ref2) {
|
|
137
|
+
var _this2 = this;
|
|
138
|
+
var service = _ref2.service,
|
|
139
|
+
method = _ref2.method,
|
|
140
|
+
data = _ref2.data;
|
|
203
141
|
return new Promise(function (resolve, reject) {
|
|
204
142
|
var _ended = false;
|
|
205
143
|
var _timeout = setTimeout(function () {
|
|
206
144
|
_ended = true;
|
|
207
|
-
|
|
145
|
+
_this2.restart();
|
|
208
146
|
console.log('rpc request timeout');
|
|
209
147
|
reject(new Error('timeout'));
|
|
210
|
-
},
|
|
148
|
+
}, _this2.options.timeout);
|
|
211
149
|
var _onResponse = function onResponse(err, res) {
|
|
212
150
|
if (_ended) {
|
|
213
151
|
return;
|
|
@@ -221,25 +159,41 @@ var GrpcClient = /** @class */function () {
|
|
|
221
159
|
}
|
|
222
160
|
_onResponse = null;
|
|
223
161
|
};
|
|
224
|
-
|
|
162
|
+
_this2.client.makeUnaryRequest("/" + service + "/" + method, passThrough, passThrough, data, _onResponse);
|
|
225
163
|
});
|
|
226
164
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
165
|
+
_proto.restart = function restart() {
|
|
166
|
+
try {
|
|
167
|
+
var _this3 = this;
|
|
168
|
+
if (_this3.closing) {
|
|
169
|
+
return _await();
|
|
170
|
+
}
|
|
171
|
+
console.log('rpc client restarting.');
|
|
172
|
+
_this3.closing = true;
|
|
173
|
+
_this3.close();
|
|
174
|
+
return _await(sleep(2000), function () {
|
|
175
|
+
_this3.closing = false;
|
|
176
|
+
});
|
|
177
|
+
} catch (e) {
|
|
178
|
+
return Promise.reject(e);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
_proto.close = function close() {
|
|
182
|
+
var _this$client;
|
|
183
|
+
(_this$client = this.client) == null ? void 0 : _this$client.close();
|
|
230
184
|
this.client = null;
|
|
231
185
|
delete this.client;
|
|
232
186
|
};
|
|
233
187
|
return GrpcClient;
|
|
234
188
|
}();
|
|
235
189
|
export var GrpcList = [];
|
|
236
|
-
export function createRpcClient(
|
|
237
|
-
var url =
|
|
238
|
-
|
|
239
|
-
options =
|
|
240
|
-
ServiceImp =
|
|
241
|
-
Grpc =
|
|
242
|
-
cert =
|
|
190
|
+
export function createRpcClient(_ref3) {
|
|
191
|
+
var url = _ref3.url,
|
|
192
|
+
_ref3$options = _ref3.options,
|
|
193
|
+
options = _ref3$options === void 0 ? {} : _ref3$options,
|
|
194
|
+
ServiceImp = _ref3.ServiceImp,
|
|
195
|
+
Grpc = _ref3.Grpc,
|
|
196
|
+
cert = _ref3.cert;
|
|
243
197
|
var client = new GrpcClient({
|
|
244
198
|
url: url,
|
|
245
199
|
options: options,
|
package/es/ros/topic.js
CHANGED
|
@@ -2,8 +2,10 @@ import { exec, spawn } from 'child_process';
|
|
|
2
2
|
import { Emitter, WatchDog, StringSplit } from 'pubo-utils';
|
|
3
3
|
import * as YAML from 'yaml';
|
|
4
4
|
import { SIGKILL } from '../child-process';
|
|
5
|
-
var RosTopic =
|
|
5
|
+
export var RosTopic = /*#__PURE__*/function () {
|
|
6
6
|
function RosTopic(topic, messageType) {
|
|
7
|
+
this.topic = void 0;
|
|
8
|
+
this.messageType = void 0;
|
|
7
9
|
this.emitter = new Emitter();
|
|
8
10
|
this.subscribed = false;
|
|
9
11
|
this.dog = new WatchDog({
|
|
@@ -11,19 +13,21 @@ var RosTopic = /** @class */function () {
|
|
|
11
13
|
onTimeout: this.onTimeout.bind(this)
|
|
12
14
|
});
|
|
13
15
|
this.strSplit = new StringSplit('---');
|
|
16
|
+
this.subscribeChildProcess = void 0;
|
|
14
17
|
this.topic = topic;
|
|
15
18
|
this.messageType = messageType;
|
|
16
19
|
this.subscribed = false;
|
|
17
20
|
this.emitter = new Emitter();
|
|
18
21
|
}
|
|
19
|
-
RosTopic.prototype
|
|
22
|
+
var _proto = RosTopic.prototype;
|
|
23
|
+
_proto.onTimeout = function onTimeout() {
|
|
20
24
|
if (!this.subscribed) {
|
|
21
25
|
return;
|
|
22
26
|
}
|
|
23
27
|
this.unsubscribe();
|
|
24
28
|
this.subscribe();
|
|
25
29
|
};
|
|
26
|
-
|
|
30
|
+
_proto.onData = function onData(data) {
|
|
27
31
|
var tmp = this.strSplit.split(data.toString()).slice(-1)[0];
|
|
28
32
|
if (!tmp) {
|
|
29
33
|
return;
|
|
@@ -31,7 +35,7 @@ var RosTopic = /** @class */function () {
|
|
|
31
35
|
var res = YAML.parse(tmp);
|
|
32
36
|
this.emitter.emit('message', res);
|
|
33
37
|
};
|
|
34
|
-
|
|
38
|
+
_proto.subscribe = function subscribe() {
|
|
35
39
|
if (this.subscribeChildProcess) {
|
|
36
40
|
return;
|
|
37
41
|
}
|
|
@@ -40,7 +44,7 @@ var RosTopic = /** @class */function () {
|
|
|
40
44
|
this.subscribeChildProcess.stdout.on('data', this.onData.bind(this));
|
|
41
45
|
this.dog.init();
|
|
42
46
|
};
|
|
43
|
-
|
|
47
|
+
_proto.unsubscribe = function unsubscribe() {
|
|
44
48
|
if (this.subscribeChildProcess) {
|
|
45
49
|
return;
|
|
46
50
|
}
|
|
@@ -49,11 +53,11 @@ var RosTopic = /** @class */function () {
|
|
|
49
53
|
SIGKILL(this.subscribeChildProcess.pid);
|
|
50
54
|
this.subscribeChildProcess = null;
|
|
51
55
|
};
|
|
52
|
-
|
|
56
|
+
_proto.publish = function publish(payload) {
|
|
53
57
|
var _this = this;
|
|
54
58
|
var data = YAML.stringify(payload);
|
|
55
59
|
return new Promise(function (resolve, reject) {
|
|
56
|
-
exec("rostopic pub -1 "
|
|
60
|
+
exec("rostopic pub -1 " + _this.topic + " " + _this.messageType + " \"" + data + "\"", function (err, stdout) {
|
|
57
61
|
if (err) {
|
|
58
62
|
reject(err);
|
|
59
63
|
} else {
|
|
@@ -64,7 +68,6 @@ var RosTopic = /** @class */function () {
|
|
|
64
68
|
};
|
|
65
69
|
return RosTopic;
|
|
66
70
|
}();
|
|
67
|
-
export { RosTopic };
|
|
68
71
|
export var RosTopicManager = {
|
|
69
72
|
cache: [],
|
|
70
73
|
getTopic: function getTopic(topic, messageType) {
|