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