GithubHelp home page GithubHelp logo

Comments (2)

pl avatar pl commented on July 21, 2024 1

Hi,

It's a bit of a race condition, which is caused by pusher-js using these events internally. You can subscribe to channels before connecting, and when connection is established, pusher-js sends actual subscription requests. Problem here is that you bind to the state_changed event, which is dispatched before the connected event that is used internally, so the flow is following:

  1. you create the Pusher instance,
  2. it binds to the connected event,
  3. you bind the callback to the state_changed,
  4. connection is established,
  5. state_changed event is dispatched,
  6. you subscribe to the channel,
  7. connected event is dispatched,
  8. pusher-js assumes that all channels on the list haven't had a chance to subscribe, subscribes your channel again,
  9. existing subscription error is raised.

While it's a bit of a bug, I would advise against relying on the pusher.connection state machine. Whenever there are problems with connection, you will get state changes, while subscriptions are retried automatically after re-establishing the connection.

You should subscribe once, after creating the Pusher instance (doesn't matter when as long as it's outside of the connection callback loop). You can then bind to pusher:subscription_succeeded on the channel.

Event emitters can cause problems like this, unfortunately.

from pusher-js.

dirkbonhomme avatar dirkbonhomme commented on July 21, 2024

Sounds like a solid explanation. I don't use this flow in real applications for the reasons you mention. Fixing this would be a waste of time it seems :)

from pusher-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.