{"bugs":{"url":"https://github.com/porsager/pws/issues"},"dist":{"shasum":"424f3d63396629fcf27ff2d09ad0aff654a55409","tarball":"https://registry.npmjs.org/pws/-/pws-3.0.1.tgz","fileCount":9,"integrity":"sha512-KoT+4LXQKeL1fl11H5rzbz6u8zRK5bGL3ALxUV5SldpDF7pdI41tsU1y7TRY3QOrU7j6sj5L124BCf4ApmqZAw==","signatures":[{"sig":"MEUCIQDb9okcP2yp5chRH8xwBX6wBpYCdl9FF0ZxFy29MdIQNwIgWEdEIfi5a4DrEpaPKyy36h414Xwzx+OZrfYn2fM6+jo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":30942,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcv1+RCRA9TVsSAnZWagAAHF8P+QC12sHG/UFPShaQIxST\n6DqHjVnjEzLyp3Poq/s2SGcwPGWrJ8o5uMeBFNi+psP8q8HMQnzESgn+R7sZ\nM1pWFnokq3BMihiZP2y1ozReHQoaCgYXV6EcBHjsvOHBB2Q//wp4V0U209nx\nCzqZzBKDUNJqNuaCDDf8CEmTDhoemfif1tGwpfwc4zQxrtx14Hg4p4I2paio\nmW5rm/wjdo81Dq/2fASWjJDDsCnRPeyWOaKkoU7r+x58vDvrP3cjjLvzF4jq\nTeGnXD7XXva51v5/ze5z6YSMmwBHmwdJeRNn/GJoUY1492nC7HMSrnpq093N\nt+DZOc1+ZIfZuGnw0per1qhcRq2VKNtwBn72Ho5Lk5DxgybG/ngU40TIpNWR\n+mJlmZR5yYkvYYxbm/1wAdPwcF/95VIoNzJp1ZdjaWFIOgt10mbz32EyOlRm\nUYxeqVcLjSbw65w2PZY76lh/CmJzDO+CTOPrfKsMbOgMnf7rg10SKMEyXIKe\ni4KHeVsqt85zIZfNIaMxXNdW78O2h/I8u6iBeswi0hP49CJmxCP0XoMe+JZA\nAW00zjC6u15IXXEn3K82gFXEX8TWO6vdO7LO0hC2tRmoDjmH8qSdraHWY3b3\nY7qndrl9U8O8oH3j3WMiGfFHzKm2TunVW8qss1eoaFMV1RzMATmkQgOm9HVB\nqnEA\r\n=o4Vt\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":"fa35a5df7c58a25a30c623c9359ee0541ff7297c","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.1_1556045712450_0.5080528896152927","host":"s3://npm-registry-packages"},"_id":"pws@3.0.1","version":"3.0.1"}