Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listen does no working #237

Closed
larants opened this issue Jul 8, 2019 · 8 comments
Closed

listen does no working #237

larants opened this issue Jul 8, 2019 · 8 comments

Comments

@larants
Copy link

larants commented Jul 8, 2019

  • Echo Version: 1.5.4
  • Laravel Version: 5.8.26
  • PHP Version: 7.2.18
  • NPM Version: 6.10.0
  • Node Version:10.15.3

Description:

The client cannot listen the broadcast when ti is triggering

laravel-echo-server is ok
[11:06:54] - AicyyOwrtbgPNrs2AAAL joined channel: new_order
Channel: laravel_database_new_order
Event: App\Events\NewOrderEvent
Channel: laravel_database_new_order
Event: App\Events\NewOrderEvent

Steps To Reproduce:

php code

//
NewOrderEvent::broadcast(121);

class NewOrderEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
 * @var int
 */
public $order;

/**
 * Create a new event instance.
 *
 * NewOrderEvent constructor.
 * @param int $order
 */
public function __construct($order = 1)
{
    $this->order = $order;
}

/**
 * Get the channels the event should broadcast on.
 *
 * @return Channel
 */
public function broadcastOn()
{
    return new Channel('new_order');
}

/**
 * @return bool
 */
public function broadcastWhen()
{
    return true;
}

}

js code
import Echo from 'laravel-echo';
...
window.io = require('socket.io-client');

window.Echo = new Echo({
broadcaster: 'socket.io',
host: 'http://localhost:6001',
});

window.Echo.channel('new_order').listen('NewOrderEvent', e => {
// can not working
console.log(e);
});

@larants
Copy link
Author

larants commented Jul 9, 2019

I've solved the problem

window.Echo.channel('new_order')
fix to
window.Echo.channel('db_prefix_new_order')

@larants larants closed this as completed Jul 9, 2019
@kkomelin
Copy link

I described a non-ideal but better solution here tlaverdure/laravel-echo-server#400 (comment)

@ShoeRiderr
Copy link

ShoeRiderr commented Nov 20, 2020

If you have everything okay in your code and your client side still didn't connect to laravel-echo-server check your socket.io-client version.
There is issue with 3.* version on localhost (not tested on https). I changed socket.io-client version to 2.3.1 and everything works fine. I suspect that in the latest version You have to secure your site with SSL certifcate, but I'm not 100% sure. If anyone know why it happen I will be glad to know

@yangcarllin
Copy link

If you have everything okay in your code and your client side still didn't connect to laravel-echo-server check your socket.io-client version.
There is issue with 3.* version on localhost (not tested on https). I changed socket.io-client version to 2.3.1 and everything works fine. I suspect that in the latest version You have to secure your site with SSL certifcate, but I'm not 100% sure. If anyone know why it happen I will be glad to know

Thanks,you solve my problem

@a2h1r0
Copy link

a2h1r0 commented Dec 6, 2020

If you have everything okay in your code and your client side still didn't connect to laravel-echo-server check your socket.io-client version.
There is issue with 3.* version on localhost (not tested on https). I changed socket.io-client version to 2.3.1 and everything works fine. I suspect that in the latest version You have to secure your site with SSL certifcate, but I'm not 100% sure. If anyone know why it happen I will be glad to know

Thank you for your good comment. My client couldn't connect to laravel-echo-server too (I don't use https).
I changed socket.io-client version to 2.3.1, and finally, my app works fine!

@hugo-z
Copy link

hugo-z commented Dec 22, 2020

If you have everything okay in your code and your client side still didn't connect to laravel-echo-server check your socket.io-client version.
There is issue with 3.* version on localhost (not tested on https). I changed socket.io-client version to 2.3.1 and everything works fine. I suspect that in the latest version You have to secure your site with SSL certifcate, but I'm not 100% sure. If anyone know why it happen I will be glad to know

Thank you for your good comment. My client couldn't connect to laravel-echo-server too (I don't use https).
I changed socket.io-client version to 2.3.1, and finally, my app works fine!

That's the RIGHT solution for this, I've been looking to solve this issue for almost two days! Once I downgraded my socket.io-client to 2.3.1, it worked like a charm! Thanks a bunch!

@NurullahDemirel
Copy link

I've solved the problem

window.Echo.channel('new_order')
fix to
window.Echo.channel('db_prefix_new_order')

what is the db_prefix_new_order

@forwells
Copy link

I believe that most of the cute little ones do not know the specific details that cause the problem
Very fortunate to be able to explain this question,
The main reasons for the problem are as follows
The socket.io server version that the laravel-echo-server package depends on is incompatible with the socket.io client version installed by the current project FE
Here we can see the socket.io server version of the current laravel-echo-server
image

At this time, the socket.io client dependency version of the project FE may look like this:
image

So the answer was revealed,
We can't blame the laravel official(Because laravel has done so much) or any article for not mentioning this, because we can't express this weird problem caused by compatibility through a specific problem description, so after too long wandering, we learn Face all problems more carefully, coooooo

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

No branches or pull requests

8 participants