Laravel pusher listen to a private event: error 403 page forbidden

Viewed 86

I am using laravel 8, vue.js and pusher to create events with broadcast functionality. Everything works fine. On pusher I receive the content sent by the event. The problem arises when I go to listen to the event on the frontend. The error that appears is always the same.

http://127.0.0.1:8000/broadcasting/auth 403 (Forbidden)

This is the code for listening to the event:

  Echo.private(`CallEvent.${data.session_id}`).listen(
          "PrivateCallEvent",
          e => {
             console.log(e)
          }

This is the related channel

 Broadcast::channel('CallEvent.{session}', function ($user,Session $session ) {

if ($user->id == $session->user_1 || $user->id == $session->user_2) {
    return true;
}
 return false;
});

This is the Private event:

    public $message;
public $event;

/**
 * Create a new event instance.
 *
 * @return void
 */
public function __construct($message,$event)
{

    $this->message= $message;
    $this->event= $event;
    $this->dontBroadcastToCurrentUser();
}

/**
 * Get the channels the event should broadcast on.
 *
 * @return \Illuminate\Broadcasting\Channel|array
 */
public function broadcastOn()
{
    return new PrivateChannel('CallEvent.'.$this->event['session_id']);
}

}

Pusher API message:

API message
Channel: private-CallEvent.353, Event: App\Events\PrivateCallEvent
Socket ID: 133983.19535029
14:12:03
{
"message": "test",
"event": {
"id": 607,
"message_id": 320,
"session_id": 353,
"user_id": 1,
"type": 0,
"created_at": "2021-11-09T14:12:03.000000Z",
"updated_at": "2021-11-09T14:12:03.000000Z"

} }

0 Answers
Related