diff --git a/app/Filament/Server/Widgets/ServerConsole.php b/app/Filament/Server/Widgets/ServerConsole.php index c81d86b8c..a9c72591e 100644 --- a/app/Filament/Server/Widgets/ServerConsole.php +++ b/app/Filament/Server/Widgets/ServerConsole.php @@ -103,6 +103,12 @@ class ServerConsole extends Widget } } + #[On('token-request')] + public function tokenRequest(): void + { + $this->dispatch('sendAuthRequest', token: $this->getToken()); + } + #[On('store-stats')] public function storeStats(string $data): void { diff --git a/resources/views/filament/components/server-console.blade.php b/resources/views/filament/components/server-console.blade.php index 80b5e7096..b68e18f06 100644 --- a/resources/views/filament/components/server-console.blade.php +++ b/resources/views/filament/components/server-console.blade.php @@ -113,7 +113,6 @@ terminal.writeln(TERMINAL_PRELUDE + 'Server marked as ' + state + '...\u001b[0m'); const socket = new WebSocket("{{ $this->getSocket() }}"); - let token = '{{ $this->getToken() }}'; socket.onerror = (event) => { $wire.dispatchSelf('websocket-error'); @@ -149,21 +148,13 @@ break; case 'token expiring': case 'token expired': - token = '{{ $this->getToken() }}'; - - socket.send(JSON.stringify({ - 'event': 'auth', - 'args': [token] - })); + $wire.dispatchSelf('token-request'); break; } }; socket.onopen = (event) => { - socket.send(JSON.stringify({ - 'event': 'auth', - 'args': [token] - })); + $wire.dispatchSelf('token-request'); }; Livewire.on('setServerState', ({ state, uuid }) => { @@ -178,6 +169,13 @@ })); }); + $wire.on('sendAuthRequest', ({ token }) => { + socket.send(JSON.stringify({ + 'event': 'auth', + 'args': [token] + })); + }); + $wire.on('sendServerCommand', ({ command }) => { socket.send(JSON.stringify({ 'event': 'send command',