Listen callback is not working in Pusher API Laravel 5.4

前端 未结 3 2200
名媛妹妹
名媛妹妹 2021-02-19 11:20

Problem

I can confirm that Pusher API is receiving the message. I saw in Debug console of Pusher website. But listen callback is not working at all.

3条回答
  •  情书的邮戳
    2021-02-19 12:25

    I got it working. Below is the correct code. I hope this will be useful to others for sending real time messaging.

    Js Work

    
    

    Controller Code

    broadcast(new SendMessageEvent("Hi", 1))->toOthers();
    //Here 1 is recepient ID
    

    Event Code

    class SendMessageEvent implements ShouldBroadcast
    {
        use Dispatchable, InteractsWithSockets, SerializesModels;
    
        public $Message;
        private $UserID;
    
        public function __construct($message, $RecepientID)
        {
            $this->Message = $message;
            $this->UserID = $RecepientID;
        }
    
        public function broadcastOn()
        {
            return new PrivateChannel('SendMessageChannel.' . $UserID);
        }
    
    }
    

提交回复
热议问题