Reputation: 63
I'm making a little dating app where I use Pusher and Laravel. I use an event called NewMessage
and listening on channel msg.{userId}
. Listening works, however broadcasting events doesn't. It works on production though.
My code is as follows:
NewMessage.php
public function __construct(Message $message, $toUserId, $conversation)
{
//
$this->message = $message;
$this->toUserId = $toUserId;
$this->conversation = $conversation;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('msg.'.$this->toUserId);
}
public function broadcastAs()
{
return 'NewMessage';
}
ConversationController.php
event(new NewMessage($message, $toUserId, $conversation));
Upvotes: 4
Views: 4818
Reputation: 11
It works on localhost, there's one small detail a lot of people miss in Laravel's documentation: "Broadcasting is done via queues so that performance is not affected".
All you need to do is run php artisan queue:work
and it'll magically work
Upvotes: 1
Reputation: 510
Check the .env file of your production application and set BROADCAST_DRIVER=log
to BROADCAST_DRIVER=pusher
.
Upvotes: 3
Reputation: 63
in config/broadcasting.php i just set the encrypted
to false and it works!
Upvotes: 0