feat: Phase 2 - Laravel Reverb + real-time notifications
- Install laravel/reverb + laravel-echo + pusher-js - Configure broadcasting to reverb in .env.example + .env - Add Echo + Pusher client in resources/js/app.js - Update all 14 notifications to implement ShouldBroadcast + broadcastOn() - Update NotificationBell component to listen for real-time events - Add Livewire.emit in notification-bell blade for JS-to-Livewire bridge Tests: 101 passing (319 assertions)
This commit is contained in:
@@ -1,5 +1,19 @@
|
||||
import './bootstrap';
|
||||
|
||||
import Echo from 'laravel-echo';
|
||||
import Pusher from 'pusher-js';
|
||||
|
||||
window.Pusher = Pusher;
|
||||
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,
|
||||
wssPort: import.meta.env.VITE_REVERB_PORT,
|
||||
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
|
||||
enabledTransports: ['ws', 'wss'],
|
||||
});
|
||||
|
||||
import localforage from 'localforage';
|
||||
|
||||
// Generic function to queue any offline action
|
||||
|
||||
@@ -84,4 +84,18 @@
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
document.addEventListener('livewire:load', () => {
|
||||
const userId = {{ auth()->id() ?? 'null' }};
|
||||
if (userId && window.Echo) {
|
||||
window.Echo.private(`user.${userId}`)
|
||||
.notification((notification) => {
|
||||
Livewire.emit('notification-received', notification.data.message ?? 'Nueva notificación');
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user