bdy 1.9.2-dev → 1.9.4-beta
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/distTs/package.json
CHANGED
package/distTs/src/agent.js
CHANGED
|
@@ -19,6 +19,7 @@ class Agent extends events_1.default {
|
|
|
19
19
|
this.service = service;
|
|
20
20
|
this.target = target;
|
|
21
21
|
this.tunnels = [];
|
|
22
|
+
this.tunnelsUpdating = false;
|
|
22
23
|
this.started = false;
|
|
23
24
|
this.api = api;
|
|
24
25
|
this.manager = null;
|
|
@@ -31,6 +32,18 @@ class Agent extends events_1.default {
|
|
|
31
32
|
this.socket.on(utils_js_1.SOCKET_IO_EVENT_TUNNEL, (tunnel, action) => this._onSocketTunnel(tunnel, action));
|
|
32
33
|
this.socket.on(utils_js_1.SOCKET_IO_EVENT_AGENT, (agent, action) => this._onSocketAgent(agent, action));
|
|
33
34
|
}
|
|
35
|
+
destroy() {
|
|
36
|
+
if (this.socket) {
|
|
37
|
+
this.socket.removeAllListeners();
|
|
38
|
+
this.socket.destroy();
|
|
39
|
+
this.socket = null;
|
|
40
|
+
}
|
|
41
|
+
this.manager = null;
|
|
42
|
+
this.onRefresh = null;
|
|
43
|
+
this.api = null;
|
|
44
|
+
// musza byc manualnie wczesniej zniszczone to tylko czysci obiekt
|
|
45
|
+
this.tunnels = null;
|
|
46
|
+
}
|
|
34
47
|
_onSocketTunnel(data, action) {
|
|
35
48
|
if (action === 'DEL') {
|
|
36
49
|
this.destroyTunnel(data.id);
|
|
@@ -173,33 +186,44 @@ class Agent extends events_1.default {
|
|
|
173
186
|
}
|
|
174
187
|
}
|
|
175
188
|
refreshTunnels(tunnels) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
189
|
+
if (this.tunnelsUpdating)
|
|
190
|
+
return;
|
|
191
|
+
this.tunnelsUpdating = true;
|
|
192
|
+
let hasTunnels = false;
|
|
193
|
+
let haveTunnels = false;
|
|
194
|
+
try {
|
|
195
|
+
const tt = [...this.tunnels];
|
|
196
|
+
hasTunnels = tt.length > 0;
|
|
197
|
+
haveTunnels = tunnels.length > 0;
|
|
198
|
+
if (hasTunnels) {
|
|
199
|
+
tt.forEach((tunnel) => {
|
|
200
|
+
if (!tunnels.find((t) => t.id === tunnel.id)) {
|
|
201
|
+
this.destroyTunnel(tunnel.id);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (haveTunnels) {
|
|
206
|
+
tunnels.forEach((data) => {
|
|
207
|
+
let sshHostKey;
|
|
208
|
+
if (this.manager)
|
|
209
|
+
sshHostKey = this.manager.sshHostKey;
|
|
210
|
+
const tunnel = tt.find((tunnel) => data.id === tunnel.id);
|
|
211
|
+
if (!tunnel) {
|
|
212
|
+
this.addTunnel(new tunnel_js_1.default({
|
|
213
|
+
...data,
|
|
214
|
+
sshHostKey,
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
else if (tunnel.hasChanged(data)) {
|
|
218
|
+
tunnel.recreate(data);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
185
222
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
let sshHostKey;
|
|
189
|
-
if (this.manager)
|
|
190
|
-
sshHostKey = this.manager.sshHostKey;
|
|
191
|
-
const tunnel = tt.find((tunnel) => data.id === tunnel.id);
|
|
192
|
-
if (!tunnel) {
|
|
193
|
-
this.addTunnel(new tunnel_js_1.default({
|
|
194
|
-
...data,
|
|
195
|
-
sshHostKey,
|
|
196
|
-
}));
|
|
197
|
-
}
|
|
198
|
-
else if (tunnel.hasChanged(data)) {
|
|
199
|
-
tunnel.recreate(data);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
223
|
+
catch {
|
|
224
|
+
// do nothing
|
|
202
225
|
}
|
|
226
|
+
this.tunnelsUpdating = false;
|
|
203
227
|
if (!this.service && hasTunnels && !haveTunnels) {
|
|
204
228
|
output_js_1.default.exitError(texts_js_1.ERR_TUNNEL_REMOVED);
|
|
205
229
|
}
|
package/distTs/src/api/socket.js
CHANGED
|
@@ -76,6 +76,25 @@ class ApiSocketClass extends events_1.default {
|
|
|
76
76
|
// do nothing
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
+
connect(atOnce) {
|
|
80
|
+
logger_js_1.default.debug('socket connect');
|
|
81
|
+
if (atOnce && this.socket && !this.socket.connected) {
|
|
82
|
+
this.socket.connect();
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
if (this.socket && !this.socket.connected)
|
|
87
|
+
this.socket.connect();
|
|
88
|
+
}, 3000);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
destroy() {
|
|
92
|
+
if (this.socket) {
|
|
93
|
+
this.socket.removeAllListeners();
|
|
94
|
+
this.socket.disconnect();
|
|
95
|
+
this.socket = null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
79
98
|
constructor(host, id, token) {
|
|
80
99
|
super();
|
|
81
100
|
this.id = id;
|
|
@@ -91,11 +110,11 @@ class ApiSocketClass extends events_1.default {
|
|
|
91
110
|
}, MAX_REQUESTS_SYNC_WINDOW);
|
|
92
111
|
this.socket = (0, socket_io_client_1.io)(host, {
|
|
93
112
|
forceNew: true,
|
|
94
|
-
autoConnect:
|
|
113
|
+
autoConnect: false,
|
|
95
114
|
autoUnref: true,
|
|
96
115
|
forceBase64: true,
|
|
97
116
|
transports: ['websocket'],
|
|
98
|
-
reconnection:
|
|
117
|
+
reconnection: false,
|
|
99
118
|
rejectUnauthorized: false,
|
|
100
119
|
agent: new https_1.Agent({
|
|
101
120
|
rejectUnauthorized: false,
|
|
@@ -118,6 +137,11 @@ class ApiSocketClass extends events_1.default {
|
|
|
118
137
|
this.connected = false;
|
|
119
138
|
logger_js_1.default.info(texts_1.LOG_SOCKET_DISCONNECTED);
|
|
120
139
|
this.emit(utils_1.SOCKET_IO_EVENT_DISCONNECTED);
|
|
140
|
+
this.connect();
|
|
141
|
+
});
|
|
142
|
+
this.socket.on('connect_error', () => {
|
|
143
|
+
logger_js_1.default.debug('socket error');
|
|
144
|
+
this.connect();
|
|
121
145
|
});
|
|
122
146
|
this.socket.on('fetchTunnelAgentSuccess', (data) => {
|
|
123
147
|
logger_js_1.default.debug('Socket fetch success');
|
|
@@ -128,6 +152,7 @@ class ApiSocketClass extends events_1.default {
|
|
|
128
152
|
this.emit(utils_1.SOCKET_IO_EVENT_FETCH_FAILED, (0, utils_1.apiErrorCodeToClass)(code, host));
|
|
129
153
|
});
|
|
130
154
|
this.socket.on('sync', (data) => this.onSync(data));
|
|
155
|
+
this.connect(true);
|
|
131
156
|
}
|
|
132
157
|
}
|
|
133
158
|
exports.default = ApiSocketClass;
|
package/distTs/src/logger.js
CHANGED