This project integrates WebRTC with Laravel Reverb and Laravel Echo, enabling real-time peer-to-peer communication using Laravel's native WebSocket capabilities.
- Real-Time Communication: Uses WebRTC for live audio and video calls.
- WebSockets with Laravel Reverb: Provides scalable and low-latency signaling for WebRTC.
- Laravel Echo Integration: Handles WebSocket events seamlessly.
- Vue.js Frontend: A dynamic and interactive UI built with Vue.js.
- Self-Hosted WebSocket Server: No need for third-party WebSocket services.
- PHP 8+
- Laravel 10+
- Composer
- Node.js & npm
- SQLite, MySQL, or PostgreSQL
-
Clone the Repository:
git clone https://github.com/mastashake08/laravel-webrtc.git cd laravel-webrtc
-
Install Dependencies:
composer install npm install
-
Environment Configuration:
-
Duplicate
.env.example
and rename it to.env
. -
Update your database settings.
-
Set the WebSockets connection driver:
BROADCAST_DRIVER=pusher PUSHER_APP_ID=reverb PUSHER_APP_KEY=reverb PUSHER_APP_SECRET=reverb
-
Generate an application key:
php artisan key:generate
-
-
Run Database Migrations:
php artisan migrate
-
Start Laravel Reverb (WebSocket Server):
php artisan reverb:start
-
Start the Laravel Application:
php artisan serve
-
Compile Frontend Assets:
npm run dev
Or for production:
npm run build
- User joins a call → Laravel Echo broadcasts an event via Reverb.
- New peer detected → WebRTC initiates a peer-to-peer connection.
- ICE Candidates exchanged → STUN/TURN servers handle NAT traversal.
- Media streams established → Users can see and hear each other.
Your resources/js/bootstrap.js
should have the following:
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'reverb',
wsHost: window.location.hostname,
wsPort: 6001,
forceTLS: false,
disableStats: true,
});
- Open two different browser windows (or devices).
- Start a call and invite the other participant.
- Laravel Reverb will handle WebSocket signaling.
- WebRTC will establish the peer-to-peer connection.
Contributions are welcome! Please fork the repo and submit a pull request.
This project is open-source under the MIT License.