{"bugs":{"url":"https://github.com/porsager/pws/issues"},"dist":{"shasum":"c424072181ce556eb8dbee43f1fad921c5c040a6","tarball":"https://registry.npmjs.org/pws/-/pws-3.0.2.tgz","fileCount":9,"integrity":"sha512-/SD+CeQaFqkhki7xzDG9xteUnB75KlQRU9KcwWGCA0RQF5EZtaxDFcs2I8Z6dhCWeO19oIKMdtNrIFgUk0TBjg==","signatures":[{"sig":"MEQCIEET1rbSa4RW2igGhojJIt1vdFYyfE4sTOejcQo9coqfAiAOifyjJEsjnofC9bcz892qKLs0gBxv2QzMVcHCYO/lRQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":30958,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcv2fCCRA9TVsSAnZWagAAtDIP/Awsd1/qaZMKkvBGW1CZ\nvqVml1VK9JGgcyTNNaw4fJYR4M/RxYMdQdcbTMC3+RCiZz0OaWSkQCd/FPnt\nV9zrYGtd6plDP+R5HmniQ9FclhdzFRe5iIM4aXSkiiixndqInmJ4RwwmIywl\nATOvMlP8UW3tK4LIAqZRhcm2c6P2g6uBvJ/1hbvoQOv5gjxiAQOza3nZitD+\npqyaXkckbncTjaIQIALxdMllCO+gO7JbDaCRBid6752gYQR1WApZlDFabdP3\nQkKW/YSBs2A/Ph2NEEKlz3srPOvf0w6N9OMnVhPqXNNMCoCTQCPwuoEnR2Ii\ns+BXgXsRRMKtRZEpEiq+GgzOL+e1SJG/x0aP9QfmMDtEj49WUyEGsY5BYCQb\nTASe+Dm3eCBH4tBxVzQHuQshtv9F0S5OBEd2WHfzEljY4AA2PEurzcJtDfWQ\nVSoABf8hsW/V9uK0OytibfFHTJmKznLvPViZG1stG6OHsa9b6SbWWcWpXOWJ\nheiwGrZhNfL9byf4VnDpYCnooru92cGp9sfCpBPngk29/Vl/K5R++R4RuyQE\nTD1oRx7P/Z1AaUFjBdywH4vjLbvofqmS+9Mf19SbqyLwhjW3EFRoSqjO5sCo\nbWP1V0gSmuzix1XCI1mZ5thXo4M0XP/L4g0TuiG14BJB6oHPSUgNUczE82Kk\n5Wwj\r\n=HkFl\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":"7336500de64e4c0ca01244bd9a3c4ccdc1561605","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.2_1556047809441_0.24732164901150555","host":"s3://npm-registry-packages"},"_id":"pws@3.0.2","version":"3.0.2"}