{"id":21975090,"url":"https://github.com/nwaughachukwuma/ws-reqonet","last_synced_at":"2025-04-28T15:41:25.844Z","repository":{"id":44773233,"uuid":"439168967","full_name":"nwaughachukwuma/ws-reqonet","owner":"nwaughachukwuma","description":"Simple WebSocket wrapper with reconnect logic","archived":false,"fork":false,"pushed_at":"2024-01-21T21:21:07.000Z","size":1188,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-23T22:19:29.724Z","etag":null,"topics":["reconnection","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nwaughachukwuma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-17T00:55:14.000Z","updated_at":"2023-03-04T03:50:07.000Z","dependencies_parsed_at":"2022-08-12T11:21:50.074Z","dependency_job_id":null,"html_url":"https://github.com/nwaughachukwuma/ws-reqonet","commit_stats":null,"previous_names":["nwaughachukwuma/ws-rekanet"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwaughachukwuma%2Fws-reqonet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwaughachukwuma%2Fws-reqonet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwaughachukwuma%2Fws-reqonet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwaughachukwuma%2Fws-reqonet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nwaughachukwuma","download_url":"https://codeload.github.com/nwaughachukwuma/ws-reqonet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227160047,"owners_count":17740021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["reconnection","websocket"],"created_at":"2024-11-29T15:49:39.435Z","updated_at":"2024-11-29T15:49:39.973Z","avatar_url":"https://github.com/nwaughachukwuma.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/20521315/183275677-b09e49c0-a381-4132-af39-d0da80dc5ab6.gif\" alt=\"Logo\" /\u003e\n\u003c/p\u003e\n\n# ws-reqonet [formerly ws-rekanet]\n\n[![Publish](https://github.com/nwaughachukwuma/ws-reqonet/actions/workflows/publish.yml/badge.svg)](https://github.com/nwaughachukwuma/ws-reqonet/actions/workflows/publish.yml)\n\nSimple WebSocket wrapper with reconnect logic 💫\n\n## Motivation\n\n\u003e The Websocket API although effective and simple doesn't provide any reconnection logic. This library aims to solve this shortcoming by providing a mechanism to shore up `session_affinity` between the client [a web browser] and the server. It also provides a simple queue implementation where data being sent while the connection is broken are bucketed, to be relayed when connection is restored.\n\u003e\n\u003e Notes\n\u003e\n\u003e 1. the library is basically a wrapper for native WebSocket class, re-exposing its API.\n\u003e 2. it's built on browser event interface which allows it to emit native WebSocket events.\n\u003e 3. well tested with AVA.\n\n## 🛠 installation\n\n```bash\n# yarn\nyarn add ws-reqonet\n\n# pnpm\npnpm install ws-reqonet\n\n# npm\nnpm install ws-reqonet\n```\n\n## 🔱 Usage\n\n```ts\nimport WSReqonet from \"ws-reqonet\";\n\nconst url = `ws://localhost:3001/`;\nconst protocols = [];\nconst options = {\n  maxRetryAttempts: 10,\n  queueMessage: true,\n};\n\n// initialize\nconst wsClient = new WSReqonet(url, protocols, options);\n\nwsClient.on(\"open\", () =\u003e {\n  console.log(\"websocket connection established\");\n});\nwsClient.on(\"message\", (event: any) =\u003e {\n  console.log(event.data);\n});\nwsClient.on(\"error\", (error: any) =\u003e {\n  console.log(\"websocket error\", error);\n});\nwsClient.on(\"close\", () =\u003e {\n  console.log(\"websocket connection closed\");\n});\n\nconst payload = { message };\nwsClient.send(JSON.stringify(payload));\n```\n\n## 🎯 API\n\n### url\n\nType: `string`\n\n### protocols\n\nType: `string | string[]`\nDefault: []\n\nEither a single protocol string or an array of protocol strings. These strings are used to indicate sub-protocols, so that a single server can implement multiple WebSocket sub-protocols (for example, you might want one server to be able to handle different types of interactions depending on the specified protocol). See more [MDN](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket), [WhatWG#web-sockets](https://html.spec.whatwg.org/multipage/web-sockets.html#websocket)\n\n### options\n\nType: `object`\n\n#### maxRetryAttempts\n\nThe maximum number of retries - how many attempts at reconnecting\n\nType: `number`\\\nDefault: 5\n\n#### queueMessage\n\nWhether to store 'send' data when the connection is broken, which is to be relayed when connection is restored.\n\nType: `boolean`\\\nDefault: true\n\n#### disableReconnect\n\nWhether to disable reconnection\n\nType: `boolean`\\\nDefault: false\n\n#### debug\n\nWhether to run in debug mode which enables logging to dev tools\n\nType: `boolean`\\\nDefault: false\n\n### events\n\n#### open, close, message, error\n\nThe same as native [WebSocket events](https://html.spec.whatwg.org/multipage/web-sockets.html#websocket)\n\n#### reconnection_timeout\n\nIndicates when reconnection attempts timeout.\n\n#### reconnected\n\nEmitted when reconnection attempt is successful - connection restored\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnwaughachukwuma%2Fws-reqonet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnwaughachukwuma%2Fws-reqonet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnwaughachukwuma%2Fws-reqonet/lists"}