Вынес конфиг сокетов из env
This commit is contained in:
26
resources/js/bootstrap.js
vendored
26
resources/js/bootstrap.js
vendored
@@ -6,17 +6,33 @@ import {startGlobalLoading, stopGlobalLoading} from "./Composables/useGlobalLoad
|
|||||||
window.axios = axios;
|
window.axios = axios;
|
||||||
window.Pusher = Pusher;
|
window.Pusher = Pusher;
|
||||||
|
|
||||||
|
let reverbFailCount = 0;
|
||||||
|
const MAX_REVERB_FAILS = 3;
|
||||||
|
|
||||||
window.Echo = new Echo({
|
window.Echo = new Echo({
|
||||||
broadcaster: 'reverb',
|
broadcaster: 'reverb',
|
||||||
key: import.meta.env.VITE_REVERB_APP_KEY,
|
key: window.reverb.key,
|
||||||
wsHost: import.meta.env.VITE_REVERB_HOST,
|
wsHost: window.reverb.host,
|
||||||
wsPort: import.meta.env.VITE_REVERB_PORT ?? 8080,
|
wsPort: window.reverb.port ?? 8080,
|
||||||
wssPort: import.meta.env.VITE_REVERB_PORT ?? 8080,
|
wssPort: window.reverb.port ?? 8080,
|
||||||
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'http') === 'https',
|
forceTLS: (window.reverb.scheme ?? 'http') === 'https',
|
||||||
enabledTransports: ['ws', 'wss'],
|
enabledTransports: ['ws', 'wss'],
|
||||||
withCredentials: true,
|
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.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
||||||
window.axios.defaults.withCredentials = true
|
window.axios.defaults.withCredentials = true
|
||||||
window.axios.defaults.withXSRFToken = true;
|
window.axios.defaults.withXSRFToken = true;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<html>
|
<html lang="ru">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
@@ -6,6 +6,15 @@
|
|||||||
|
|
||||||
<title>{{ config('app.name', 'Laravel') }}</title>
|
<title>{{ config('app.name', 'Laravel') }}</title>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
window.reverb = {
|
||||||
|
key: "{{ env('REVERB_APP_KEY') }}",
|
||||||
|
host: "{{ env('REVERB_APP_HOST') }}",
|
||||||
|
port: "{{ env('REVERB_APP_PORT') }}",
|
||||||
|
scheme: "{{ env('REVERB_APP_SCHEME') }}",
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<!-- Styles / Scripts -->
|
<!-- Styles / Scripts -->
|
||||||
@if (file_exists(public_path('build/manifest.json')) || file_exists(public_path('hot')))
|
@if (file_exists(public_path('build/manifest.json')) || file_exists(public_path('hot')))
|
||||||
@vite(['resources/js/app.js'])
|
@vite(['resources/js/app.js'])
|
||||||
|
|||||||
Reference in New Issue
Block a user