Skip to content

Echo Not receiving notifications from pusher #282

@Myestery

Description

@Myestery
  • Echo Version: 1.8.0
  • Laravel Version: 7.0
  • PHP Version: 7.2.
  • NPM Version: 6.12.1
  • Node Version: 12.13.1

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

Activity

driesvints

driesvints commented on Jul 25, 2020

@driesvints
Member

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

Myestery commented on Aug 7, 2020

@Myestery
Author

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

parallels999 commented on Aug 26, 2022

@parallels999
Contributor

@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

Myestery commented on Aug 26, 2022

@Myestery
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @driesvints@Myestery@parallels999

        Issue actions

          Echo Not receiving notifications from pusher · Issue #282 · laravel/echo