Nov 24, 2024
0
Level 1
How to set Laravel 11 with Reverb and Valet
I have a project using Laravel 11. I installed broadcasting too with Reverb. When I open it with Valet, I see these on network/ws:
{"event":"pusher:connection_established","data":"{\"socket_id\":\"807491240.32280726\",\"activity_timeout\":30}"}
{"event":"pusher:subscribe","data":{"auth":"","channel":"messages"}}
{"event":"pusher_internal:subscription_succeeded","data":"{}","channel":"messages"}
and ping pong...
But when I send a message event, it does not displayed. What should do on my project?
BROADCAST_CONNECTION=reverb
QUEUE_CONNECTION=database
REVERB_APP_ID=123456
REVERB_APP_KEY=somethingreverbkey
REVERB_APP_SECRET=somethingreverbsecret
REVERB_HOST=${APP_DOMAIN}
REVERB_PORT=8080
REVERB_SCHEME=https
reverb.php
'servers' => [
'reverb' => [
'host' => env('REVERB_SERVER_HOST', '0.0.0.0'),
'port' => env('REVERB_SERVER_PORT', 8080),
'hostname' => env('REVERB_HOST'),
'options' => [
'tls' => [
'enabled' => true,
'cert_path' => '/Users/davee/.config/valet/Certificates/chat.test.crt',
'key_path' => '/Users/davee/.config/valet/Certificates/chat.test.key',
],
],
'max_request_size' => env('REVERB_MAX_REQUEST_SIZE', 10_000),
'scaling' => [
'enabled' => env('REVERB_SCALING_ENABLED', false),
'channel' => env('REVERB_SCALING_CHANNEL', 'reverb'),
'server' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'port' => env('REDIS_PORT', '6379'),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'database' => env('REDIS_DB', '0'),
],
],
'pulse_ingest_interval' => env('REVERB_PULSE_INGEST_INTERVAL', 15),
'telescope_ingest_interval' => env('REVERB_TELESCOPE_INGEST_INTERVAL', 15),
],
],
broadcasting.php
'connections' => [
'reverb' => [
'driver' => 'reverb',
'key' => env('REVERB_APP_KEY'),
'secret' => env('REVERB_APP_SECRET'),
'app_id' => env('REVERB_APP_ID'),
'options' => [
'host' => env('REVERB_HOST'),
'port' => env('REVERB_PORT', 443),
'scheme' => env('REVERB_SCHEME', 'https'),
'useTLS' => env('REVERB_SCHEME', 'https') === 'https',
],
'client_options' => [
'verify' => false
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
],
],
Events/MessageSent.php
class MessageSent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct(public string $txt)
{
//
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel
*/
public function broadcastOn(): Channel
{
return new Channel('messages');
}
}
echo.js
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 ?? 80,
wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
enabledTransports: ['ws', 'wss'],
});
window.Echo.channel('messages')
.listen('MessageSent', (e) => {
console.log(e);
});
Please or to participate in this conversation.