I am using Laravel 9, Nuxt js, laravel-websocket. Laravel Echo is working only on public channels not working on private channels.
Here is my code.
channels.php
Broadcast::channel('trades', function ($user) {
return auth()->check();
});
Events file (NewTrade.php)
class NewTrade implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $trade;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($trade, User $user)
{
$this->trade = $trade;
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('trades');
}
}
nuxt.config.js
buildModules: [
['@nuxtjs/laravel-echo', {
broadcaster: process.env.BROADCAST_DRIVER,
key: process.env.PUSHER_APP_KEY,
cluster: process.env.PUSHER_APP_CLUSTER,
forceTLS: false,
wsHost: '127.0.0.1',
wsPort: 6001,
wssPort: 6001,
disableStats: true,
authModule: true,
connectOnLogin: true,
encrypted: true,
authEndpoint: process.env.PUSHER_AUTH_ENDPOINT,
}]
],
echo.js (Plugin)
import Pusher from "pusher-js";
Pusher.logToConsole = true;
client echo
this.$echo.private('trades')
.listen('NewTrade', (e) => {
console.log("A testing");
});
Note: If I send data from the public channel client-side received it but the only problem is when I broadcast on the private channel.
I have spent more than 10 hours and tried everything I could, but no luck. :(
Thanks.