jeudi 4 juillet 2019

Why I cannot send messages to pusher but I can receive them from pusher?

Im making a chat in my app and Im using pusher. I did everything that pusher told me to do. I'm using vanilla-js in frontend. I can connect in frontend. I can receiver messages from pusher but my messages are not going anywhere. P.S I did all configuration (.env, broadcasting.php)

FRONTEND

var pusher = new Pusher('xxxxxxxx', {
                cluster: 'eu',
                forceTLS: false
            });
            window.channelName = 'my-channel-' + ;
            window.event = 'private-conversation';
            var channel = pusher.subscribe(window.channelName);
            channel.bind(window.event, function (data) {
               alert(data);
            });

BACKEND

public function sendMessage($request, $roomId){

        event(new Event(array(
            'id' => auth()->user()->id,
            'full_name' => auth()->user()->fullName()
        ), $request->input('channel'), $request->input('event'), $request->input('message')));
    }

EVENT

class Event
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $user;
    public $message;
    public $channelName;
    public $event;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($user, $channelName, $event, $message)
    {
        $this->user = $user;
        $this->channelName = $channelName;
        $this->event = $event;
        $this->message = $message;
    }

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

    public function broadcastAs()
    {
        return $this->event;
    }
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2FOrO63
via IFTTT

Aucun commentaire:

Enregistrer un commentaire