2.0.0-alpha • Published 7 years ago

pws v2.0.0-alpha

Weekly downloads
579
License
MIT
Repository
github
Last release
7 years ago

PWS - PersistentWebSocket

npm install pws -S

WebSockets are great, but as soon as you start having a need for an always online connection (reconnecting) you either have to roll your own or pull in a big library like socket.io or primus. Both are great libraries, but maybe not really necessary for what you're doing.

This module gives you a reconnecting websocket to use in the browser or in node simply by switching out new WebSocket with new PersistentWebSocket.

It behaves the same as a regular browser WebSocket, but reconnects automatically with a simple backoff algorithm when the connection closes. It also expects a heartbeat (any message will do) from the server every 30 seconds, or else it will close the connection and begin reconnecting (configurable).

The reason for doing a reconnect on a missing heartbeat from the server is because WebSockets doesn't close if the connection is not closed properly. This can often lead to stale connections. A server can implement the ping>pong from the WebSocket specification to ensure connections are still alive, but this doesn't solve the problem for clients. If doing a ping from the server it might be beneficial to include a timestamp and get some information on the connections latency.

6.0.1

3 years ago

7.0.0

3 years ago

6.0.0

4 years ago

5.0.2

5 years ago

5.0.1

6 years ago

5.0.0

6 years ago

5.0.0-beta.1

6 years ago

4.3.0

6 years ago

4.2.0

6 years ago

4.1.2

6 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.0.6

6 years ago

4.0.5

6 years ago

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

2.0.3

7 years ago

3.0.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

2.0.0-alpha2

7 years ago

2.0.0-alpha

7 years ago

1.0.2

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.4.0

8 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago