So, it seems that when you use:
public function broadcastAs(): string
{
return 'chat_message.sent';
}
You then have to Echo.listen to .chat_message.sent and not chat_message.sent.
Without the extra dot at the begining it doesnt listen.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using Laravel 11 and Reverb.
On my .env:
BROADCAST_CONNECTION=reverb
REVERB_APP_ID=//the id was put here on broadcast install
REVERB_APP_KEY=//the app key was put here on broadcast install
REVERB_APP_SECRET=//the app secret was put here on broadcast install
REVERB_HOST="localhost"
REVERB_PORT=6001
REVERB_SERVER_HOST=0.0.0.0
REVERB_SERVER_PORT=6001
REVERB_SCHEME=http
On my docker-compose:
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
- '${REVERB_SERVER_PORT:-6001}:${REVERB_SERVER_PORT:-6001}'
I ran sail build --no-cache, all good.
Then I run artisan reverb:start --debug, and it logs:
Starting server on 0.0.0.0:6001 (localhost).
And I also run artisan queue:work.
My VideoCall model has this method:
public function chatChannelName(): string
{
$routeKey = $this->getRouteKey();
return "videocalls.{$routeKey}.chat";
}
My channel route:
Broadcast::channel('videocalls.{video_call}.chat', function(?Participant $participant, VideoCall $video_call): bool {
return (bool) (
$participant?->video_call_id === $video_call->id
);
}, ['guards' => ['video-call']]);
Then, on my controller:
$message = $participant->chatMessages()->create(
$request->validated()
);
ChatMessageSent::dispatch($message);
return back();
The messages get submitted and stored in the database correctly.
My event:
class ChatMessageSent implements ShouldBroadcast
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
public function __construct(public ChatMessage $chatMessage) {}
public function broadcastAs(): string
{
return 'chat_message.sent';
}
public function broadcastOn(): array
{
return [
new PrivateChannel($this->chatMessage->participant->videoCall->chatChannelName()),
];
}
}
My front end:
useEffect(() => {
console.log('SETTING CHAT LISTENERS', channelName)
Echo.private(channelName).listen('chat_message.sent', event => {
console.log(event)
})
}, [channelName])
The 'SETTING CHAT LISTENERS' console log runs without issue, and logs the right channelName.
All good, except, one thing... the console.log on the Echo.private.(channelName).listen.... is not firing.
Here are my Reverb logs:
{
"event": "pusher:subscribe",
"data": {
"auth": "dci97wgyk3ybtjjoiuvw:1c2cf8c7707df17c25606df8a9185344044f9efe9aed74a35b75c04798d66a22",
"channel": "private-videocalls.JkzeP3L...
Broadcasting To ................................................................................ private-videocalls.JkzeP3LR0aE.chat
{
"event": "chat_message.sent",
"data": {
"chatMessage": {
"id": 21,
"participant_id": 7,
"body": "hello",
"created_at": "2024-09-12T11:...
Here are my queue logs:
2024-09-12 11:55:19 App\Events\ChatMessageSent .......................................................................................... RUNNING
2024-09-12 11:55:20 App\Events\ChatMessageSent .................................................................................... 304.29ms DONE
What am I missing here?
So, it seems that when you use:
public function broadcastAs(): string
{
return 'chat_message.sent';
}
You then have to Echo.listen to .chat_message.sent and not chat_message.sent.
Without the extra dot at the begining it doesnt listen.
Please or to participate in this conversation.