{"bugs":{"url":"https://github.com/porsager/pws/issues"},"dist":{"shasum":"e6b446bff1d6e8824a2a269f1c73be737bfa1ab2","tarball":"https://registry.npmjs.org/pws/-/pws-3.0.0.tgz","fileCount":9,"integrity":"sha512-FN/DfzDvxpVeoBr8yH6okR4IHEFI4+oV2rrb4KrK+cBOudU0N3Cm/hVVR8GxbsKUC2dxUlnEMMmwP8RL4Sm17A==","signatures":[{"sig":"MEQCICvmGFHXhR1umIZB6FvLeEeT5xXIZv9fqZgZfP+J08vQAiATm2l0b/nLASE9vihf9nl6uolbiJsBhSIXgUkTxXQiug==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":27988,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcvuAwCRA9TVsSAnZWagAAYjMP/A9NHSzFpD6q+n29QVDv\nwKxaDnVVsq2S8pzD1SCdxgw1vuZH/R9Gli2HVnbFDJNOPDTMbYxCT3D0HyGc\npq5Mpo60lpUFQzQ1dM5s0JhvDFbIfjhqPE1pbRAccrNyOcsCGSE+JQQonPe7\n1C3AkEaV0SaLUKXmQqwHR0usIsqbmserlrbJHZ6A6ZCkpaQ9baXdnteJ0a+C\nFDAhtmzcDSSYvdyKgh2s9nLe7ipm67wzvTtty5GKZIWJoDTpancdDrCH3iHN\n/mKqVE8ZopTuTrBTm3+AEl1rD8uCOTpWWVNJeNa9Ew/jBVO/yJS/4ydoroWE\nHWLm1zGadbtt+5k9mX/FVLa5IqInH6IoPtXGLraKoUZ1jM1u1hPJCXxMSMHq\nThzHxou9pJJy4ukP2akJqhAi0wILNO6FpZYwRHsQ5JHqla1ApP6EItuXUnir\nzBUG5SCEoe5xGnqc7m+WRtVVTAyFR43my3q+QheoVXQJVMDY9JHQQr2Pt35N\nWsYRLWqnhjoBEK2sapb++eLL0twpxQNcXEdnA2ZOUSoWF0AhjM1+jZ6mfmYL\n/vFmx5aQn8ErZARhfBewayVyZbXok8r12PE8e7DAfp4TeAQTS2m4ufTSTlaP\nsY+lE9csYPD+UHxXBKllrApHshvrb2jyX0zwYmoDINOx42qoJbyLsnW3fJFN\n0gmX\r\n=bRp4\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","name":"pws","author":{"name":"Rasmus Porsager","email":"rasmus@porsager.com"},"module":"dist/index.esm.js","readme":"[![NPM version](https://img.shields.io/npm/v/pws.svg)](https://www.npmjs.com/package/pws)\n[![Size](https://img.shields.io/bundlephobia/minzip/pws.svg)]()\n[![license](https://img.shields.io/github/license/porsager/pws.svg)]()\n\n# 🤝 PWS - PersistentWebSocket\n\nPWS gives you a reconnecting websocket to use in the browser or in node simply by switching out `new WebSocket` with `new PersistentWebSocket`.\n\nIt behaves the same as a regular browser WebSocket, but reconnects automatically with a simple backoff algorithm if the connection closes.\n\n## Getting started\n```js\nconst pws = new PersistentWebSocket(url)\n\n// Called every time a connection is established\npws.onopen = () => pws.send('Hello')\n\n// Echo messages received\npws.onmessage = event => pws.send('You said: ' + event.data)\n```\n\nMore details at https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket\n\n## Using in node\n\nYou can also use PWS with the nodejs WebSocket library [ws](https://github.com/websockets/ws)\n\n```\nconst WebSocket = require('ws')\n    , Pws = require('pws')\n\nconst pws = Pws(url, WebSocket)\n\n// as in the browser...\n```\n\nMore details at https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketaddress-protocols-options\n\n\n### Heartbeat\n\nTo ensure a persistent connection it's necesarry to send messages at regular intervals from the server to keep the connection alive. The WebSocket protocol only implements a ping to be sent from the server, but not in the other direction. This can leave the client in a half open state where it thinks it's connected, but doesn't receive messages from the server.\nTo prevent this state PWS let's you set a specific timeout after which to force a reconnection if you did not receive any messages from the server.\n\n```js\nnew PersistentWebSocket(url, {\n  pingTimeout: 30 * 1000 // Reconnect if no message received in 30s.\n})\n```\n\n### Backoff algorithm\n\nThe backoff algorithm is inspired by primus and  http://dthain.blogspot.com/2009/02/exponential-backoff-in-distributed.html, and stops at a maximum reconnection timeout of 5 minutes.\n\n### Reconnect on browser `online`\n\nPWS will also reconnect on the browsers `online` event, irregardless of the current timeout for the next reconnect, to ensure a connection is regained as fast as possible.\n","gitHead":"78c243f96b254f443b206d15d10372724ea99355","license":"WTFPL","scripts":{"build":"rollup -c","prepublishOnly":"npm run build"},"_npmUser":{"name":"porsager","email":"npm@janosch.dk"},"homepage":"https://github.com/porsager/pws#readme","keywords":["websocket","reconnect","ubre","ping","timeout"],"deprecated":"too experimental release","repository":{"url":"git+https://github.com/porsager/pws.git","type":"git"},"_npmVersion":"6.4.1","description":"A Persistent WebSocket wrapper","directories":{},"maintainers":[{"name":"porsager","email":"npm@janosch.dk"}],"_nodeVersion":"10.15.0","_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"rollup":"0.67.3","rollup-plugin-buble":"0.19.4","rollup-plugin-terser":"3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/pws_3.0.0_1556013104368_0.19041731873904122","host":"s3://npm-registry-packages"},"_id":"pws@3.0.0","version":"3.0.0"}