Framework: broadcasting exception with pusher

Created on 15 Aug 2018  路  6Comments  路  Source: laravel/framework

Description:

laravel throws exception when I want to broadcast on a channel
Message posted events

<?php

namespace App\Events;
use App\Message;
use App\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class MessagePosted implements ShouldBroadcast

{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * Message
     * @var Message
     */

    public $message;


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

    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrsenceChannel('chatroom');
    }
}

web.php

Route::post("/new-message",function(){
    $message = request()->get('message');
    \Log::error("hi masoud ".$message);
    $user = Auth::user();
    //CREATE ACTS AS INSERTING
    error_log("message");
    $the_message = $user->messages()->create([
        'message'=>$message,
    ]); 
    event(new MessagePosted($the_message,$user));
});

Channels

Broadcast::channel('chatroom', function ($user) {
    return $user;
});

Steps To Reproduce:

laravel realtime chat app

All 6 comments

typo?

return new PrsenceChannel('chatroom');

should be:

 return new PresenceChannel('chatroom');

no I fixed that but the problem keeps on .

I would try to find answers here, it seems _not_ to be a bug with Laravel, but a bug within your app...

https://laracasts.com/discuss
https://laravel.io/forum

thanks my efforts is ongoing to find the app ,_possible_ bug.

the problem seems to be from pusher .since it is responding me with status 0 .

Had the same problem and solved it by setting PUSHER_APP_CLUSTER=eu in the .env.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PhiloNL picture PhiloNL  路  3Comments

shopblocks picture shopblocks  路  3Comments

digirew picture digirew  路  3Comments

iivanov2 picture iivanov2  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments