laravel / echo

Laravel Echo library for beautiful Pusher and Ably integration.
https://laravel.com/docs/broadcasting#client-side-installation
MIT License
1.19k stars 185 forks source link

Echo Not receiving notifications from pusher #282

Closed Myestery closed 4 years ago

Myestery commented 4 years ago

Description: I'm trying to send notifications to users,

My pusher connection is good because it sends on public channels And also, i get this message on my console [2020-07-24 21:08:09][355] Processed: Illuminate\Notifications\Events\BroadcastNotificationCreated and on pusher i also see that the message was sent. I also don't get any errors on my browser console as all the websocket connections are working well. But i still dont get any messages. I tried

Echo.private('App.User.' +userId)
   .notification((notification) => {
   console.log(notification);
  });

I also tried

Echo.private('App.User.' + userId)
  .listen('.Illuminate\\Notifications\\Events\\BroadcastNotificationCreated', (e) => {
  console.log('Event Notification received ', e)
  });

I also followed many tutorials and the docs All to no avail.

Steps To Reproduce:

Create a notification and declare both the toArray method and toBroadcast methods but echo fails to catch messages from pusher

driesvints commented 4 years ago

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

Myestery commented 4 years ago

I finally solved this issue myself

Steps

In my bootstrap.js file

window.Echo = new Echo({
      broadcaster: "pusher",
      key: "my key",
      cluster: "eu",
      encrypted: true,
      authEndpoint: "api/broadcasting/auth",
      auth: {
        headers: {
          Authorization: "Bearer " + localStorage.getItem("token"),
        },
      },
    });

Then in my routes/api.php file,

Route::middleware('auth:api')->post('broadcasting/auth', function (Request $request) {
    $pusher = new Pusher\Pusher(
    $app_key,
    $app_secret,
    $app_id
);
return $pusher->socket_auth($request->request->get('private-my-channel'),($request->request->get('socket_id'));
});

There is more info on this in the documentation, I hope it helps someone someday

parallels999 commented 2 years ago

@Myestery on next version you can use bearerToken option

window.Echo = new Echo({
  broadcaster: "pusher",
  key: "my key",
  cluster: "eu",
  encrypted: true,
  authEndpoint: "api/broadcasting/auth",
  bearerToken: localStorage.getItem("token"),
  /*auth: {
    headers: {
      Authorization: "Bearer " + localStorage.getItem("token"),
    },
  },*/
});
Myestery commented 2 years ago

@Myestery on next version you can use bearerToken option

window.Echo = new Echo({
  broadcaster: "pusher",
  key: "my key",
  cluster: "eu",
  encrypted: true,
  authEndpoint: "api/broadcasting/auth",
  bearerToken: localStorage.getItem("token"),
  /*auth: {
    headers: {
      Authorization: "Bearer " + localStorage.getItem("token"),
    },
  },*/
});

Thanks