Code Monkey home page Code Monkey logo

Comments (5)

kinsi55 avatar kinsi55 commented on July 19, 2024 1

I have exactly the same issue with Twitch PubSub.

RWS: handleClose { shouldRetry: true }
RWS: retries count: 1
RWS: handleClose - reconnectDelay: 2125.6480950789783
RWS: connect
RWS: bypass properties
RWS: timeout

Edit: Looks like i've found the Culprit. In the connect function, a handler for 'close' is created which calls the handleClose function, which then tries to reconnect by calling connect after a delay. The issue is that the connect function has a timeout delay which does not try to reconnect upon timeout, thus it stalls. Lemme whip up a fix.

from reconnecting-websocket.

pladaria avatar pladaria commented on July 19, 2024 1

Happy to hear that!

ReconnectingWebsocket uses the standard WebSocket API

you can use .addEventListener or assign a function to onopen:
rws.onopen = () => console.log('open');

from reconnecting-websocket.

pladaria avatar pladaria commented on July 19, 2024

Please, don't use ws as Websocket constructor. Use the wrapper module html5-websocket as documented in the README: https://github.com/pladaria/reconnecting-websocket#using-alternative-constructor

The way ws frees resources seems to be incompatible with this library. This may change in the future, I'm planning a full rewrite.

from reconnecting-websocket.

Bomper avatar Bomper commented on July 19, 2024

Just wanted to note that using Html5WebSocket isn't a drop-in replacement for WebSocket. Neither .on('open'), nor .onopen works.

const ReconnectingWebSocket = require('reconnecting-websocket');
const rws = new ReconnectingWebSocket('wss://ws-feed.gdax.com', [], {
  constructor: Html5WebSocket,
  debug: true,
});

rws.onopen(() => {            // <-- TypeError: rws.onopen is not a function
  rws.send(JSON.stringify({
    type: 'subscribe',
    product_ids: ['BTC-USD'],
    channels: ['matches'],
  }));
});

I had to convert my code to use .addEventListener.

However, the connection to GDAX now does reconnect automatically, so thanks for the module! 🙌

from reconnecting-websocket.

geekbleek avatar geekbleek commented on July 19, 2024

The URL posted above appears to no longer have a section on alternate constructors: https://github.com/pladaria/reconnecting-websocket#using-alternative-constructor Can you provide guidance on the best constructor for serverside usage in node.js?

from reconnecting-websocket.

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.