refactor: Improve SSH command generation in Terminal.php and terminal-server.js

This commit is contained in:
Andras Bacsai
2024-10-02 15:16:55 +02:00
parent 0ab432d5e6
commit e03e4f2e91
3 changed files with 64 additions and 9 deletions

View File

@@ -16,6 +16,7 @@ export function initializeTerminalComponent() {
paused: false,
MAX_PENDING_WRITES: 5,
keepAliveInterval: null,
reconnectInterval: null,
init() {
this.setupTerminal();
@@ -48,6 +49,9 @@ export function initializeTerminalComponent() {
document.addEventListener(event, () => {
this.checkIfProcessIsRunningAndKillIt();
clearInterval(this.keepAliveInterval);
if (this.reconnectInterval) {
clearInterval(this.reconnectInterval);
}
}, { once: true });
});
@@ -103,11 +107,27 @@ export function initializeTerminalComponent() {
};
this.socket.onclose = () => {
console.log('WebSocket connection closed');
this.reconnect();
};
}
},
reconnect() {
if (this.reconnectInterval) {
clearInterval(this.reconnectInterval);
}
this.reconnectInterval = setInterval(() => {
console.log('Attempting to reconnect...');
this.initializeWebSocket();
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
console.log('Reconnected successfully');
clearInterval(this.reconnectInterval);
this.reconnectInterval = null;
window.location.reload();
}
}, 5000);
},
handleSocketMessage(event) {
this.message = '(connection closed)';
if (event.data === 'pty-ready') {