From 08e4afbbc42e5abda85f75c86c1a5ed9e3cbc515 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 16 Sep 2024 10:20:57 +0200 Subject: [PATCH] fix: keep-alive ws connections --- .../livewire/project/shared/terminal.blade.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/resources/views/livewire/project/shared/terminal.blade.php b/resources/views/livewire/project/shared/terminal.blade.php index d12360ce9..be6a1acef 100644 --- a/resources/views/livewire/project/shared/terminal.blade.php +++ b/resources/views/livewire/project/shared/terminal.blade.php @@ -32,6 +32,22 @@ let socket; let commandBuffer = ''; + + function keepAlive() { + if (socket && socket.readyState === WebSocket.OPEN) { + socket.send(JSON.stringify({ + ping: true + })); + } + } + + const keepAliveInterval = setInterval(keepAlive, 30000); + + // Clear the interval when the component is destroyed + document.addEventListener('livewire:navigating', () => { + clearInterval(keepAliveInterval); + }); + function initializeWebSocket() { if (!socket || socket.readyState === WebSocket.CLOSED) { // Only use port if Coolify is used with ip (so it has a port in the url)