I have some issues about to connect to broadcasting from React
I sure don't have any error on my code, this is my code
on my broadcast.php
on config folder
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'host' => '192.168.0.114',
'port' => 6001,
'scheme' => 'http'
],
],
and on my api.php
on route folder i am adding
Broadcast::routes(['middleware' => ['api', 'auth:sanctum']]);
on .env
file
PUSHER_APP_ID=osamah
PUSHER_APP_KEY=osamah
PUSHER_APP_SECRET=osamah
PUSHER_APP_CLUSTER=mt1
on channel.php
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
on my react listen
const echo = new Echo({
broadcaster: 'pusher',
key: 'osamah',
cluster: 'mt1',
wsHost: '192.168.0.114',
wsPort: 6001,
forceTLS: false,
disableStats: true,
authEndpoint: "http://192.168.0.114/api/broadcasting/auth",
auth: {
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer 1542|3hVrlJ3A968IeZ23kejqTp8CJ9p4RCkcj66gRK4z'
},
}
});
echo.connector.pusher.connection.bind('connected', () => {
console.log('connected');
axios.get(`http://192.168.0.114/api/count`, {
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer 1542|3hVrlJ3A968IeZ23kejqTp8CJ9p4RCkcj66gRK4z'
},
})
.then(res => {
console.log(res);
})
});
echo.private('App.Models.User.393').notification((e)=>console.log(e.user));