{"bugs":{"url":"https://github.com/porsager/pws/issues"},"dist":{"shasum":"03eb53b8b2d601bb3586474990d118276dab9a00","tarball":"https://registry.npmjs.org/pws/-/pws-3.0.3.tgz","fileCount":9,"integrity":"sha512-SQgKiDpH4Eb0L2Za/otIwERWmLopgPl6AVvvqO33GJjIsmh6Kwr0E/NqX5AVkjFIDaAZQErMF6cu2Lvd44KjIQ==","signatures":[{"sig":"MEUCIQCJGmPqFwOERqm4UhNU9Lmaq8F2mgPTWXe1atGaHlBSfAIgUB/3jSHYBPLouBKMoRQ6iji6uf3bEGIYsGKqlgVKss8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":33742,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcv4gPCRA9TVsSAnZWagAABrQP/iNREmdlkDk1Q2+juQCM\ncUxdLMwM0N1qVDTUlJEYmiDjNFX5MUQ1R3o7Qn5DulRU/bCb/5AlVo+o0hkx\nEzvru0Vonq19qj9UL8QN0iTOsPq6kcWGdMfNgE0DafRW+c0t0Sx0XtPPj/J0\nQTxtGbPEzP/lPR65vAvVoUX11Nld9AuxfDdKD4h0e88yGIhp3uVp1pffhoVg\njRoO/dEsDl/LWAjJ7qhBPfkqneGzIEeC3OJT+cxKbZLAjmmC+q77A4sBMV0R\nBNlEJJzWgOkJ5NfiuK/UQg1Jm7zyE3mvO1Nznz7w1a1EHLjLy1l4f2pj9z7P\nCo5A48GdYDv9W1mZL6iUx57JdctUdwKE83K5zAopqG5IJV5qMpBHPzpmJse/\n881h/AXApg8QAmG+5TI2jvrYXNyT4L1UiBuIFAK/koLIM11RITNzSH+L/Ajf\ngpBCWKhOiut0iuM7w6SpVuGE9bWgXRXdaPNjqLGonr6udEDjBEEfDoJ0umH+\nOjV37fFTg76loFUUrhEe5dQe44C+Mnmb9HiNEOTWKhnfVwyexFiyk4ingT9B\nFUDMNUQxc2P4oZ4xfFhUaS1/mAH+z0D2ydfGtUseN2tex3Du+ouLxex3YsE2\nPZAQDxEZgaUHg+HU0SL6vQPxwH7jVst1WezXIM7Mg/hCjqJCc8vi5lFx4wlU\n71E4\r\n=Kx60\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":"038862599db94b015a25c784e5aad41c6a7386f5","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.3_1556056079014_0.08836088344317439","host":"s3://npm-registry-packages"},"_id":"pws@3.0.3","version":"3.0.3"}