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

+27 -6
View File
@@ -266,6 +266,28 @@
state.echo.private(`chat.${conversationId}`).listen(".message.sent", upsertIncoming);
}
function isLoopbackHost(host) {
return !host || host === "127.0.0.1" || host === "localhost" || host === "0.0.0.0" || host === "::1";
}
function echoEndpoint(pusher) {
const pageHost = window.location.hostname;
if (!isLoopbackHost(pageHost)) {
const https = window.location.protocol === "https:";
return {
host: pageHost,
port: https ? 443 : 80,
forceTLS: https,
};
}
return {
host: pusher.host || "127.0.0.1",
port: pusher.port || 8080,
forceTLS: (pusher.scheme || "http") === "https",
};
}
function bootEcho() {
const pusher = config.pusher || {};
const EchoClass = window.Echo;
@@ -273,17 +295,16 @@
return;
}
const scheme = pusher.scheme || "https";
const forceTLS = scheme === "https";
const endpoint = echoEndpoint(pusher);
try {
state.echo = new EchoClass({
broadcaster: "reverb",
key: pusher.key,
wsHost: pusher.host || undefined,
wsPort: pusher.port || undefined,
wssPort: pusher.port || undefined,
forceTLS,
wsHost: endpoint.host,
wsPort: endpoint.port,
wssPort: endpoint.port,
forceTLS: endpoint.forceTLS,
enabledTransports: ["ws", "wss"],
disableStats: true,
cluster: "mt1",