entexto-cli 1.4.5 → 1.4.7

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.
@@ -46,27 +46,57 @@ module.exports = async function tunnel(opts) {
46
46
  }
47
47
 
48
48
  const socket = ioClient(wsUrl, {
49
- transports: ['websocket'],
49
+ // Polling primero → upgrade a WebSocket. Esto sobrevive a Cloudflare y
50
+ // otros proxies que cierran WebSockets agresivamente (como hace ngrok).
51
+ transports: ['polling', 'websocket'],
52
+ upgrade: true,
50
53
  reconnection: true,
51
- reconnectionDelay: 2000,
52
- reconnectionAttempts: 20,
54
+ reconnectionDelay: 1500,
55
+ reconnectionDelayMax: 5000,
56
+ reconnectionAttempts: Infinity,
57
+ timeout: 20000,
53
58
  });
54
59
 
60
+ // Mantener el mismo tunnelId entre reconexiones
61
+ let currentTunnelId = null;
62
+ let publicUrl = null;
63
+ let heartbeatTimer = null;
64
+
65
+ function startHeartbeat() {
66
+ clearInterval(heartbeatTimer);
67
+ // Ping cada 25s para evitar el timeout de 60s de Cloudflare/proxies
68
+ heartbeatTimer = setInterval(() => {
69
+ if (socket.connected) socket.emit('ping-tunnel');
70
+ }, 25000);
71
+ }
72
+
55
73
  socket.on('connect', () => {
56
- socket.emit('open-tunnel', { target: targetUrl }, (res) => {
74
+ const meta = { target: targetUrl };
75
+ if (currentTunnelId) meta.reclaimId = currentTunnelId; // intentar recuperar el mismo ID
76
+
77
+ socket.emit('open-tunnel', meta, (res) => {
57
78
  if (!res || !res.ok) {
58
79
  spinner.fail('No se pudo abrir el túnel: ' + JSON.stringify(res));
59
80
  process.exit(1);
60
81
  }
61
82
 
62
- const publicUrl = `${baseUrl}/t/${res.tunnelId}`;
63
- spinner.succeed('Túnel activo');
64
- console.log('');
65
- console.log(chalk.bold(' 🚇 URL pública:'), chalk.cyan.underline(publicUrl));
66
- console.log(chalk.gray(` → ${targetUrl}`));
67
- console.log('');
68
- console.log(chalk.gray(' Presiona Ctrl+C para cerrar'));
69
- console.log('');
83
+ const isNew = res.tunnelId !== currentTunnelId;
84
+ currentTunnelId = res.tunnelId;
85
+ publicUrl = `${baseUrl}/t/${currentTunnelId}`;
86
+
87
+ startHeartbeat();
88
+
89
+ if (isNew) {
90
+ spinner.succeed('Túnel activo');
91
+ console.log('');
92
+ console.log(chalk.bold(' 🚇 URL pública:'), chalk.cyan.underline(publicUrl));
93
+ console.log(chalk.gray(` → ${targetUrl}`));
94
+ console.log('');
95
+ console.log(chalk.gray(' Presiona Ctrl+C para cerrar'));
96
+ console.log('');
97
+ } else {
98
+ console.log(chalk.green(' ✔ Reconectado — misma URL: ') + chalk.cyan(publicUrl));
99
+ }
70
100
  });
71
101
  });
72
102
 
@@ -141,12 +171,17 @@ module.exports = async function tunnel(opts) {
141
171
  });
142
172
 
143
173
  socket.on('disconnect', (reason) => {
174
+ clearInterval(heartbeatTimer);
144
175
  console.log(chalk.yellow('\n Desconectado: ' + reason));
145
- if (reason === 'io server disconnect') {
146
- console.log(chalk.gray(' El servidor cerró la conexión.'));
176
+ if (reason === 'io client disconnect') {
177
+ // Cierre manual (Ctrl+C)
147
178
  process.exit(0);
148
179
  }
149
- console.log(chalk.gray(' Reintentando...'));
180
+ if (publicUrl) {
181
+ console.log(chalk.gray(' Reintentando... (la URL se mantendrá: ') + chalk.cyan(publicUrl) + chalk.gray(')'));
182
+ } else {
183
+ console.log(chalk.gray(' Reintentando...'));
184
+ }
150
185
  });
151
186
 
152
187
  // Ctrl+C
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "entexto-cli",
3
- "version": "1.4.5",
3
+ "version": "1.4.7",
4
4
  "description": "CLI oficial de Entexto — Deploy y gestión de proyectos desde tu terminal",
5
5
  "main": "lib/index.js",
6
6
  "bin": {