0

I have a laravel backend and react front end app. and i need to show event notification to react front end. its working perfectly when using channel but when i use privateChannel and try to login, laravel-websockets debug dashboard shows the event fired but not broadcast to the front end. and server log shows this error

Exception ErrorException thrown: Undefined property: stdClass::$auth 1544082: exception ErrorException thrown: Undefined property: stdClass::$auth.

but server not stopping its working. here is my codes.

class BroadcastServiceProvider extends ServiceProvider
{
/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Broadcast::routes();

    require base_path('routes/channels.php');
}
}

Event

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

public function broadcastAs()
{
    return 'activity-log';
}

channel.php

Broadcast::channel('activity', function()
{
  return true;
});

React Front End

const pusher = new Pusher('key', {

authEndpoint: baseApiURL + "broadcast/auth",
auth: {
headers: {
  'Accept': 'application/json',
  'Content-Type': 'application/json',
  'Authorization': 'Bearer ' + Cookies.get("token") ?? "",
 },
},
forceTLS: false,
cluster: 'mt1',
wsHost: '127.0.0.1',
wsPort: 6001,
enableStats: false,
encrypted: true,
enabledTransports: ['ws']

});

const chnlActivity = pusher.subscribe('private-activity');

chnlActivity.bind("activity-log", function (data) {
  console.log(data.activities);
});

0 Answers0