entexto-cli 1.4.5 → 1.4.6
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/lib/commands/tunnel.js +43 -13
- package/package.json +1 -1
package/lib/commands/tunnel.js
CHANGED
|
@@ -49,24 +49,49 @@ module.exports = async function tunnel(opts) {
|
|
|
49
49
|
transports: ['websocket'],
|
|
50
50
|
reconnection: true,
|
|
51
51
|
reconnectionDelay: 2000,
|
|
52
|
-
reconnectionAttempts:
|
|
52
|
+
reconnectionAttempts: Infinity, // reintentar indefinidamente
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
+
// Mantener el mismo tunnelId entre reconexiones
|
|
56
|
+
let currentTunnelId = null;
|
|
57
|
+
let publicUrl = null;
|
|
58
|
+
let heartbeatTimer = null;
|
|
59
|
+
|
|
60
|
+
function startHeartbeat() {
|
|
61
|
+
clearInterval(heartbeatTimer);
|
|
62
|
+
// Ping cada 25s para evitar el timeout de 60s de Cloudflare/proxies
|
|
63
|
+
heartbeatTimer = setInterval(() => {
|
|
64
|
+
if (socket.connected) socket.emit('ping-tunnel');
|
|
65
|
+
}, 25000);
|
|
66
|
+
}
|
|
67
|
+
|
|
55
68
|
socket.on('connect', () => {
|
|
56
|
-
|
|
69
|
+
const meta = { target: targetUrl };
|
|
70
|
+
if (currentTunnelId) meta.reclaimId = currentTunnelId; // intentar recuperar el mismo ID
|
|
71
|
+
|
|
72
|
+
socket.emit('open-tunnel', meta, (res) => {
|
|
57
73
|
if (!res || !res.ok) {
|
|
58
74
|
spinner.fail('No se pudo abrir el túnel: ' + JSON.stringify(res));
|
|
59
75
|
process.exit(1);
|
|
60
76
|
}
|
|
61
77
|
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
const isNew = res.tunnelId !== currentTunnelId;
|
|
79
|
+
currentTunnelId = res.tunnelId;
|
|
80
|
+
publicUrl = `${baseUrl}/t/${currentTunnelId}`;
|
|
81
|
+
|
|
82
|
+
startHeartbeat();
|
|
83
|
+
|
|
84
|
+
if (isNew) {
|
|
85
|
+
spinner.succeed('Túnel activo');
|
|
86
|
+
console.log('');
|
|
87
|
+
console.log(chalk.bold(' 🚇 URL pública:'), chalk.cyan.underline(publicUrl));
|
|
88
|
+
console.log(chalk.gray(` → ${targetUrl}`));
|
|
89
|
+
console.log('');
|
|
90
|
+
console.log(chalk.gray(' Presiona Ctrl+C para cerrar'));
|
|
91
|
+
console.log('');
|
|
92
|
+
} else {
|
|
93
|
+
console.log(chalk.green(' ✔ Reconectado — misma URL: ') + chalk.cyan(publicUrl));
|
|
94
|
+
}
|
|
70
95
|
});
|
|
71
96
|
});
|
|
72
97
|
|
|
@@ -141,12 +166,17 @@ module.exports = async function tunnel(opts) {
|
|
|
141
166
|
});
|
|
142
167
|
|
|
143
168
|
socket.on('disconnect', (reason) => {
|
|
169
|
+
clearInterval(heartbeatTimer);
|
|
144
170
|
console.log(chalk.yellow('\n Desconectado: ' + reason));
|
|
145
|
-
if (reason === 'io
|
|
146
|
-
|
|
171
|
+
if (reason === 'io client disconnect') {
|
|
172
|
+
// Cierre manual (Ctrl+C)
|
|
147
173
|
process.exit(0);
|
|
148
174
|
}
|
|
149
|
-
|
|
175
|
+
if (publicUrl) {
|
|
176
|
+
console.log(chalk.gray(' Reintentando... (la URL se mantendrá: ') + chalk.cyan(publicUrl) + chalk.gray(')'));
|
|
177
|
+
} else {
|
|
178
|
+
console.log(chalk.gray(' Reintentando...'));
|
|
179
|
+
}
|
|
150
180
|
});
|
|
151
181
|
|
|
152
182
|
// Ctrl+C
|