Refactor chat configuration: update .env.example for Reverb settings, streamline Pusher configuration in SupportChatController, and enhance chat.js to dynamically determine websocket endpoint based on host. This improves flexibility for local and production environments.

This commit is contained in:
Mekan1206 committed 2026-08-15 20:50:09 +05:00
1 parent 3a415edb6e
commit f68db67465
4 files changed
+92 -13

No files matched your search

@@ -31,12 +31,7 @@ public function index(): View
$key ? $this->panelAsset('js/echo.iife.js') : null,
$this->panelAsset('js/chat.js'),
])),
'pusher' => [
'key' => $key,
'host' => config('broadcasting.connections.reverb.options.host'),
'port' => (int) config('broadcasting.connections.reverb.options.port', 8080),
'scheme' => config('broadcasting.connections.reverb.options.scheme', 'http'),
],
'pusher' => $this->chatPusherConfig($key),
]);
}
@@ -110,4 +105,36 @@ private function panelAsset(string $relative): string
return (string) file_get_contents($path);
}
/**
* Browser websocket host. Reverb itself stays on 127.0.0.1:8080;
* production browsers connect through nginx at wss://mm.com.tm/app.
*
* @return array{key: mixed, host: string, port: int, scheme: string}
*/
private function chatPusherConfig(mixed $key): array
{
$requestHost = request()->getHost();
$public = ! in_array($requestHost, ['127.0.0.1', 'localhost', '::1', '0.0.0.0'], true);
if ($public) {
$https = request()->secure()
|| request()->header('X-Forwarded-Proto') === 'https'
|| str_contains($requestHost, '.');
return [
'key' => $key,
'host' => $requestHost,
'port' => $https ? 443 : 80,
'scheme' => $https ? 'https' : 'http',
];
}
return [
'key' => $key,
'host' => (string) config('broadcasting.connections.reverb.options.host'),
'port' => (int) config('broadcasting.connections.reverb.options.port', 8080),
'scheme' => (string) config('broadcasting.connections.reverb.options.scheme', 'http'),
];
}
}