Laravel echo is no listening

laravel, laravel-artisan, laravel-echo, php

Solution

If you using the Echo.channel(`my-channel`) for example you need to do something like this, attention to the ('.my-event') for some reason you need to a (.) before the event name.

Echo.channel(`my-channel`)
.listen('.my-event', (e) => {
    consolec.log(e);
});

Problem

I'm trying to do a simple real time chat using broadcast events with socket.io That is my chatController.. ``` public function index(Request $request) { $sender=Auth::user()->id; $receiver=\App\User::find(2); $message=new Message; $message->message="Hola, esto es una prueba de eventos"; $message->user_receiver_id=$receiver->id; $message->user_sender_id=Auth::user()->id; $message->id_chat=1; $message->save(); event(new \App\Events\sendMessage($message,$receiver)); return response()->json(["status"=>"ok"]); } ``` This chat store in a database the messages according to determinate group (chat). The event that will be fired is: ``` class sendMessage implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; /** * Create a new event instance. * * @return void */ public $message; public $user_receiver; public function __construct(Message $message,User $user_receiver) { $this->message=$message; $this->user_receiver=$user_receiver; } public function broadcastOn() { \Log::info($this->message->id_chat); return new PrivateChannel('chat.1'); } } ``` My app.js is: ``` require('./bootstrap'); import Echo from "laravel-echo"; window.Echo = new Echo({ broadcaster: 'socket.io', host: window.location.hostname + ':6001' }); window.Echo.channel('chat.1') .listen('sendMessage', e => { console.log(e); }); ``` To start, I just want to get the public variables from my `sendMessages` event; after this I will build the view. I've run `php artisan listener` and the Laravel echo server. But when I send a message I get this output on the server: ``` CHANNEL private-chat.1 CHANNEL private-chat.1 CHANNEL private-chat.1 ``` And this on the client: ``` $ php artisan queue: listen [2017-05-11 23:26:42] Processing: App\Events\sendMessage [2017-05-11 23:26:43] Processed: App\Events\sendMessage [2017-05-11 23:29:28] Processing: App\Events\sendMessage [2017-05-11 23:29:291 Processed: App\Events\sendMessage [2017-05-11 23:32:11] Processing: App\Events\sendMessage [2017-05-11 23:32:12] Processed: App\Events\sendMessage [2017-05-11 23:46:46] Processing: App\Events\sendMessage [2017-05-11 23:46:47] Processed: App\Events\sendMessage [2017-05-11 23:50:32] Processing: App\Events\sendMessage [2017-05-11 23:50:33] Processed: App\Events\sendMessage [2017-05-11 23:50:52] Processing: App\Events\sendMessage [2017-05-11 23:50:53] Processed: App \Events\sendMessage [Symfony\Component\Process\Exception\ProcessTimedOutException] The process "'/usr/bin/php' 'artisan' queue:work 11 --once --queue='default ' --delay=0 --memory=128 --sleep=3 --tries=0" exceeded the timeout of 60 seconds. ```

Original source

Related problems