Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Can't recieve broadcasted message from laravel echo server #407

Open
rst630 opened this issue May 17, 2019 · 6 comments · Fixed by laravel/framework#31261
Open

Can't recieve broadcasted message from laravel echo server #407

rst630 opened this issue May 17, 2019 · 6 comments · Fixed by laravel/framework#31261

Comments

@rst630
Copy link

rst630 commented May 17, 2019

In laravel-echo-console:


L A R A V E L  E C H O  S E R V E R

version 1.5.2

⚠ Starting server in DEV mode...

✔  Running at localhost on port 6001
✔  Channels are ready.
✔  Listening for redis events...

Server ready!

[7:07:00 PM] - YSTAl2zDJP0HtuoCAAAA joined channel: public
[7:07:00 PM] - Sending auth request to: https://xxxxx/broadcasting/auth

[7:07:00 PM] - YSTAl2zDJP0HtuoCAAAA authenticated for: private-survey.2
[7:07:00 PM] - YSTAl2zDJP0HtuoCAAAA joined channel: private-survey.2


Channel: laravel_database_private-survey.2
Event: server.message

All looks fine, but I can't recieve this message in browser:

window.Echo.private('survey.2')
 .listen('.server.message', (e) => {
        console.log(e)  
});
e {events: {…}, name: "private-survey.2", socket: p, options: {…}, eventFormatter: t}

My event class:


   public function __construct($message)
    {
        $this->message = $message;
    }

    public function broadcastOn()
    {
        return new PrivateChannel('survey.2');
    }

    public function broadcastAs()
    {
        return 'server.message';
    }

In laravel telescope I see:

{
  message: "wdfwsfwf",
  socket: null
}

does it normal that socket is null? Also always 0 listeners for this event.

What's wrong?

@shijunti19
Copy link

me too

@rst630
Copy link
Author

rst630 commented May 21, 2019

my problem was here Channel: laravel_database_ private-survey.2
change this in config/database.php

echo must join to "survey.2" in this case

if broadcasAs

 public function broadcastAs()
    {
        return 'server.message';
    }

echo must listen ".server.message" - dot before says not using namespace - this is event - not channel!

@handhikadj
Copy link

I've thumbed it up this post. Me too

@eightyfive
Copy link

I believe this issue belongs in laravel/echo#232. This is up to the client to know what namespaced events it wants to listen to.

My understanding is that Laravel is sending the correct namespaced events, laravel-echo-server receives them correctly, but laravel-echo listens to the wrong channel (private-survey.2 instead of listening to laravel_database_private-survey.2 ).

I'd say laravel-echo needs a new configuration option:

const echo = new Echo({
  // ...
  keyPrefix: "laravel_database_"
});

@timoschwarzer
Copy link

This should be fixed with laravel-echo-server 1.6.0 and Laravel 6.13

@skeeith
Copy link

skeeith commented Feb 23, 2020

@eightyfive I do believe this is the best solution. cause if ever the system would have multiple clients, multiple redis databases it would know what namespace to listen too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants