Вынес конфиг сокетов из env

This commit is contained in:
brusnitsyn
2026-06-03 17:10:33 +09:00
parent 720ca1b39a
commit aa0cd0c449
2 changed files with 31 additions and 6 deletions

View File

@@ -6,17 +6,33 @@ import {startGlobalLoading, stopGlobalLoading} from "./Composables/useGlobalLoad
window.axios = axios;
window.Pusher = Pusher;
let reverbFailCount = 0;
const MAX_REVERB_FAILS = 3;
window.Echo = new Echo({
broadcaster: 'reverb',
key: import.meta.env.VITE_REVERB_APP_KEY,
wsHost: import.meta.env.VITE_REVERB_HOST,
wsPort: import.meta.env.VITE_REVERB_PORT ?? 8080,
wssPort: import.meta.env.VITE_REVERB_PORT ?? 8080,
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'http') === 'https',
key: window.reverb.key,
wsHost: window.reverb.host,
wsPort: window.reverb.port ?? 8080,
wssPort: window.reverb.port ?? 8080,
forceTLS: (window.reverb.scheme ?? 'http') === 'https',
enabledTransports: ['ws', 'wss'],
withCredentials: true,
});
window.Echo.connector.pusher.connection.bind('failed', () => {
reverbFailCount++;
if (reverbFailCount >= MAX_REVERB_FAILS) {
console.warn('Reverb недоступен, отключаем WebSocket');
window.Echo.disconnect();
}
});
window.Echo.connector.pusher.connection.bind('unavailable', () => {
console.warn('Reverb недоступен');
window.Echo.disconnect();
});
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
window.axios.defaults.withCredentials = true
window.axios.defaults.withXSRFToken = true;