I'm trying to listen on a private channel with Laravel Echo, but it does not listen on private channel only, public channel works fine.
I'm also using beyondcode/Laravel-Websockets package, and it shows me in the websockets dashboard panel, all the connections and event made. It shows al the private connections made by the package itself, my public connections and all the events triggered (private and public), but it does not show me my private connections
The event if fired and the data is saved in the database, all works totally fine except that in the view, I'm not receiven any data from the private event triggered
I tried downgrading my Laravel Echo version, to version "^1.3.2", when the predefined was "^1.5.4"
This is my laravel event wich broadcast on a private channel
<?php
namespace App\Events;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
class NuevoGasto implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $gasto;
public function __construct($gasto)
{
$this->gasto = $gasto;
}
public function broadcastOn()
{
return new PrivateChannel('nuevo-gasto-channel');
}
}
Note I'm using ShouldBroadcastNow trait, so I don't need to use a queue
This is my bootstrap.js file wich have my Laravel Echo configuration
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
wsHost: window.location.hostname,
wsPort: 6001,
disableStats: true,
});
This is my routes/channels.php file
Broadcast::channel('nuevo-gasto-channel', function ($user) {
return true;
});
Note I'm returning true for demo purposes
This is my view file when I listen for a NuevoGasto event, on nuevo-gasto-channel
Echo.private('nuevo-gasto-channel')
.listen('NuevoGasto', (e) => {
console.log(e);
});
And finally this is my Controller, where I trigger the event
...
broadcast(new NuevoGasto($gasto))->toOthers();
...
I'm not getting any errors, it's just no listening on the private channel