import Echo from 'laravel-echo'; import Pusher from 'pusher-js'; window.Pusher = Pusher; // Private channel subscriptions POST to /broadcasting/auth, which sits // behind the app's normal CSRF middleware like any other POST route — // without this header every private-channel auth request 419s silently // (pusher-js swallows it as a subscription error), so nothing broadcast // ever reaches the browser even though the socket connection itself works. const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content'); 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 ?? 80, wssPort: import.meta.env.VITE_REVERB_PORT ?? 443, forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https', enabledTransports: ['ws', 'wss'], auth: { headers: { 'X-CSRF-TOKEN': csrfToken, }, }, }); /** * Bridges Reverb broadcast events into plain Livewire events rather than * using the `#[On('echo-private:...')]` attribute directly on components — * this indirection is deliberately version-agnostic and easy to verify from * the browser console regardless of Livewire's internals. * * This file is loaded via @vite as `type="module"`, which the HTML spec * defers until after the document is parsed — meaning any plain * (non-deferred)