entexto-cli 2.2.0 → 2.2.1

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.
@@ -60,15 +60,18 @@ module.exports = async function tunnel(opts) {
60
60
  upgrade: false,
61
61
  reconnection: true,
62
62
  reconnectionDelay: 1000,
63
- reconnectionDelayMax: 3000,
63
+ reconnectionDelayMax: 5000,
64
64
  reconnectionAttempts: Infinity,
65
65
  timeout: 20000,
66
+ // Forzar reconexión incluso cuando el server cierra la conexión
67
+ forceNew: false,
66
68
  });
67
69
 
68
70
  // Mantener el mismo tunnelId entre reconexiones
69
71
  let currentTunnelId = null;
70
72
  let publicUrl = null;
71
73
  let heartbeatTimer = null;
74
+ let reconnectWatchdog = null;
72
75
 
73
76
  function startHeartbeat() {
74
77
  clearInterval(heartbeatTimer);
@@ -78,12 +81,25 @@ module.exports = async function tunnel(opts) {
78
81
  }, 25000);
79
82
  }
80
83
 
84
+ // Watchdog: si tras 15s no estamos conectados ni reconectando, forzar reconexión
85
+ function startWatchdog() {
86
+ clearInterval(reconnectWatchdog);
87
+ reconnectWatchdog = setInterval(() => {
88
+ if (!socket.connected && !socket.io._reconnecting) {
89
+ console.log(chalk.yellow(' ⟳ Watchdog: forzando reconexión...'));
90
+ try { socket.connect(); } catch (_) {}
91
+ }
92
+ }, 15000);
93
+ }
94
+
81
95
  socket.on('connect', () => {
82
96
  const meta = { target: targetUrl };
83
97
  if (currentTunnelId) meta.reclaimId = currentTunnelId; // intentar recuperar el mismo ID
84
98
  if (customLink) meta.link = customLink;
85
99
  if (token) meta.token = token;
86
100
 
101
+ startWatchdog();
102
+
87
103
  socket.emit('open-tunnel', meta, (res) => {
88
104
  if (!res || !res.ok) {
89
105
  spinner.fail('No se pudo abrir el túnel: ' + JSON.stringify(res));
@@ -257,31 +273,55 @@ module.exports = async function tunnel(opts) {
257
273
  localReq.end();
258
274
  });
259
275
 
276
+ let connectErrorCount = 0;
277
+
260
278
  socket.on('connect_error', (err) => {
279
+ connectErrorCount++;
261
280
  if (spinner.isSpinning) {
262
281
  spinner.fail('No se pudo conectar al servidor: ' + err.message);
263
- } else {
264
- console.error(chalk.red(' Conexión perdida: ' + err.message));
282
+ }
283
+ // Solo mostrar cada 10 errores para no llenar la terminal
284
+ if (connectErrorCount <= 3 || connectErrorCount % 10 === 0) {
285
+ console.error(chalk.yellow(` ⟳ Reintentando conexión... (intento ${connectErrorCount})`));
286
+ }
287
+ // Si socket.io dejó de intentar, forzar reconexión
288
+ if (!socket.io._reconnecting) {
289
+ setTimeout(() => {
290
+ try { socket.connect(); } catch (_) {}
291
+ }, 3000);
265
292
  }
266
293
  });
267
294
 
268
295
  socket.on('disconnect', (reason) => {
269
296
  clearInterval(heartbeatTimer);
270
- console.log(chalk.yellow('\n Desconectado: ' + reason));
297
+ connectErrorCount = 0;
271
298
  if (reason === 'io client disconnect') {
272
299
  // Cierre manual (Ctrl+C)
300
+ clearInterval(reconnectWatchdog);
273
301
  process.exit(0);
274
302
  }
303
+ console.log(chalk.yellow('\n Desconectado: ' + reason));
275
304
  if (publicUrl) {
276
305
  console.log(chalk.gray(' Reintentando... (la URL se mantendrá: ') + chalk.cyan(publicUrl) + chalk.gray(')'));
277
306
  } else {
278
307
  console.log(chalk.gray(' Reintentando...'));
279
308
  }
309
+ // Forzar reconexión si socket.io no lo hace automáticamente
310
+ if (reason === 'transport close' || reason === 'transport error' || reason === 'ping timeout') {
311
+ setTimeout(() => {
312
+ if (!socket.connected && !socket.io._reconnecting) {
313
+ console.log(chalk.yellow(' ⟳ Forzando reconexión...'));
314
+ try { socket.connect(); } catch (_) {}
315
+ }
316
+ }, 2000);
317
+ }
280
318
  });
281
319
 
282
320
  // Ctrl+C
283
321
  process.on('SIGINT', () => {
284
322
  console.log(chalk.gray('\n Cerrando túnel...'));
323
+ clearInterval(heartbeatTimer);
324
+ clearInterval(reconnectWatchdog);
285
325
  socket.disconnect();
286
326
  process.exit(0);
287
327
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "entexto-cli",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "CLI oficial de Entexto — Crea, deploya y gestiona proyectos, dominios, APIs y Live SDK desde tu terminal",
5
5
  "main": "lib/index.js",
6
6
  "bin": {