Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

laravel echo not reconnect after fail #69

Closed
svn292 opened this issue Dec 21, 2018 · 5 comments
Closed

laravel echo not reconnect after fail #69

svn292 opened this issue Dec 21, 2018 · 5 comments

Comments

@svn292
Copy link

svn292 commented Dec 21, 2018

laravel echo not reconnect after fail
here is my code
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
wsHost: window.location.hostname,
wsPort: 6001,
disableStats: true,
});

@stephenlake
Copy link

It may be worth while if you actually provided some output and/or input since "my code" is the default copy/paste. Regardless, pretty sure Echo does reconnect automatically by default - it attempts every couple of seconds, but falls back to Pusher if no connection can be made.

Add enabledTransports: ['ws', 'wss'] to your Echo options to prevent using Pusher as a fallback.

@stayallive
Copy link
Contributor

According to the docs the enabledTransports is not needed. If that is needed you might want to PR that to the docs @stephenlake.

But yes, @svn292 please add some more info. This is how the docs says you should do it and works for a lot of people so we need a bit more context or error output.

@stephenlake
Copy link

stephenlake commented Jan 7, 2019

@stayallive You're correct, enabledTransports is not needed. It's available to restrict transports and in turn fallback transports which is usually the underlying cause of the client not reconnecting to the correct defined wsHost.

See Issue #19 (Laravel Echo will still connect to Pusher as fallback). Echo will reconnect on a potential different transport if a connection fails. I suspect this is what's happening because Echo does reconnect, but again it's pretty difficult to identify issues without anything to go on.

@svn292
Copy link
Author

svn292 commented Jan 9, 2019

its working

@svn292 svn292 closed this as completed Jan 9, 2019
@SVV-team
Copy link

SVV-team commented Nov 8, 2021

Hi all found great solution ;)

  1. Bind to pusher event state_changed
  2. When state = disconnected call connect method ;)
  3. Enjoy !
window.Echo.connector.pusher.connection.bind('state_change', function(states) {
  if(states.current === 'disconnected') {
      window.Echo.connector.pusher.connect();
  }
});

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

No branches or pull requests

4 participants