Laravel Reverb Migration Guide

Overview

This project has been successfully migrated from beyondcode/laravel-websockets (which is abandoned) to Laravel Reverb - the official Laravel WebSocket solution.

Why Migrate?

What Changed

1. Package Migration

2. Broadcasting Configuration

Updated config/broadcasting.php: - Added reverb connection as the default driver - Configuration uses Reverb credentials instead of custom WebSocket ports

3. Events Created

Three new broadcast events were created to replace the custom WebSocket implementation:

NotificationUpdated Event

MeetingSynced Event

ProjectSynced Event

4. Services Updated

All WebSocket services now use Laravel’s broadcast system:

5. Commands Updated

Legacy commands have been updated with deprecation warnings:

6. Scheduled Tasks

Setup Instructions

1. Environment Configuration

Add these variables to your .env file:

# Broadcasting Driver
BROADCAST_DRIVER=reverb

# Laravel Reverb Configuration
REVERB_APP_ID=your-app-id
REVERB_APP_KEY=your-app-key
REVERB_APP_SECRET=your-app-secret
REVERB_HOST=localhost
REVERB_PORT=8080
REVERB_SCHEME=http
REVERB_SERVER_HOST=0.0.0.0
REVERB_SERVER_PORT=8080

Generate credentials: ```bash

Generate random credentials for Reverb

REVERB_APP_ID=$(openssl rand -hex 16) REVERB_APP_KEY=$(openssl rand -hex 32) REVERB_APP_SECRET=$(openssl rand -hex 32) ```

2. Start Reverb Server

Development: bash php artisan reverb:start

Production (with debug mode): bash php artisan reverb:start --debug

Production (as background service): Use a process manager like Supervisor:

[program:reverb]
command=php /path/to/artisan reverb:start
directory=/path/to/project
autostart=true
autorestart=true
user=www-data
redirect_stderr=true
stdout_logfile=/path/to/project/storage/logs/reverb.log

3. Frontend Integration

Update your frontend JavaScript to connect to Reverb instead of the legacy WebSocket server.

Before (Legacy): javascript const ws = new WebSocket('ws://localhost:9080'); ws.onmessage = (event) => { const data = JSON.parse(event.data); // Handle notification };

After (Reverb with Laravel Echo): ```javascript import Echo from ‘laravel-echo’; import Pusher from ‘pusher-js’;

window.Pusher = Pusher;

window.Echo = new Echo({ broadcaster: ‘reverb’, key: process.env.MIX_REVERB_APP_KEY, wsHost: process.env.MIX_REVERB_HOST || ‘localhost’, wsPort: process.env.MIX_REVERB_PORT || 8080, forceTLS: false, disableStats: true, });

// Listen to notifications window.Echo.channel(notification.${userId}) .listen(‘.notification.updated’, (data) => { console.log(‘Notification received:’, data); // Handle notification });

// Listen to meeting updates window.Echo.channel(meeting.${meetingId}) .listen(‘.meeting.synced’, (data) => { console.log(‘Meeting synced:’, data); // Handle meeting update });

// Listen to project updates window.Echo.channel(project.${projectId}) .listen(‘.project.synced’, (data) => { console.log(‘Project synced:’, data); // Handle project update }); ```

Install required npm packages: bash npm install --save-dev laravel-echo pusher-js

Channel & Event Reference

Notifications

Meetings

Projects

Testing

Test Reverb Server

# Start Reverb in debug mode
php artisan reverb:start --debug

# In another terminal, test broadcasting
php artisan tinker
>>> broadcast(new App\Events\NotificationUpdated($notification, $userId));

Monitor Connections

Reverb provides real-time connection monitoring when running with --debug flag.

Troubleshooting

Reverb won’t start

Events not broadcasting

Frontend not receiving events

Performance Tips

Redis Scaling (Production)

For high-traffic applications, enable Redis scaling:

REVERB_SCALING_ENABLED=true
REVERB_SCALING_CHANNEL=reverb
REDIS_HOST=127.0.0.1
REDIS_PORT=6379

Connection Limits

Configure in .env: env REVERB_APP_MAX_CONNECTIONS=10000 REVERB_APP_MAX_MESSAGE_SIZE=10000

Legacy Code Reference

The following files remain in the codebase for reference but are no longer used:

These can be safely removed after confirming the migration works correctly.

Migration Checklist

Support

For issues or questions: - Laravel Reverb Documentation: https://laravel.com/docs/11.x/reverb - Laravel Broadcasting: https://laravel.com/docs/11.x/broadcasting - Laravel Echo: https://github.com/laravel/echo


Migration completed by: Claude Code Date: $(date +%Y-%m-%d) Laravel Version: 11.x Reverb Version: 1.6.0