Martin-Pitt / webresock

Yet another reconnecting WebSocket using reconnect-core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

webresock

Yet another client-side reconnecting WebSocket.

This one is using reconnect-core.

Why?

ReconnectingWebSocket already exists so why bothering?

ReconnectingWebSocket is great but it only allows a backoff strategy using a predictable reconnection time interval. This means that if 100.000 clients are connected to your websocket server, when it fails and starts over again, it will face 100.000 connection attempts at once.

webresock tries to fix this issue by providing a way to choose alternate backoff strategies which eventually distribute the clients connection attempts.

How?

webresock uses reconnect-core to handle the WebSocket reconnection in case of a temporary server failure.

In order to use webresock, get the package through bower:

bower install --save webresock

And use it:

<script src="webresock.js"></script>
<script>
  webresock.reconnect({
    // reconnect-core options
    strategy: new webresock.backoff.Backoff({
      // backoff strategy
    })
  })
  .on('connect', (ws) => ws
    .on('message', console.log)
  )
  .connect('ws://whatever')
</script>

Contributing

I'm open to discussing and merging any PR as long as my schedule allows it.

Before sending any PR, ensure that npm test still succeeds. In case of a new feature, ensure that tests are extended accordingly.

References

About

Yet another reconnecting WebSocket using reconnect-core

License:MIT License


Languages

Language:JavaScript 100.0%