diff --git a/server/static/client.js b/server/static/client.js index 7d491bd..fa1270a 100644 --- a/server/static/client.js +++ b/server/static/client.js @@ -595,16 +595,35 @@ class NeovimClient { } connectToNeovim(address) { - if (this.ws && this.ws.readyState === WebSocket.OPEN) { + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { + this.updateStatus("Reconnecting to server..."); + this.connect(); + + const checkConnection = setInterval(() => { + if (this.ws && this.ws.readyState === WebSocket.OPEN) { + clearInterval(checkConnection); + this.ws.send( + JSON.stringify({ + type: "connect", + address: address, + }), + ); + } + }, 100); + + setTimeout(() => { + clearInterval(checkConnection); + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { + this.updateStatus("Failed to reconnect to server"); + } + }, 5000); + } else { this.ws.send( JSON.stringify({ type: "connect", address: address, }), ); - } else { - console.error("WebSocket not ready"); - this.updateStatus("WebSocket not connected"); } }