{"id":26180014,"url":"https://github.com/jellydn/ws-sockette","last_synced_at":"2026-03-12T11:05:23.480Z","repository":{"id":37074081,"uuid":"476317125","full_name":"jellydn/ws-sockette","owner":"jellydn","description":"The little WebSocket wrapper for nodejs","archived":false,"fork":false,"pushed_at":"2025-04-11T20:24:23.000Z","size":1385,"stargazers_count":5,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-11T21:32:10.793Z","etag":null,"topics":["nodejs","websocket","ws"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jellydn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["jellydn"],"ko_fi":"dunghd"}},"created_at":"2022-03-31T13:26:30.000Z","updated_at":"2025-04-11T20:24:26.000Z","dependencies_parsed_at":"2024-03-25T05:26:59.485Z","dependency_job_id":"32a60047-d25a-41d4-9a06-7261051dd524","html_url":"https://github.com/jellydn/ws-sockette","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jellydn%2Fws-sockette","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jellydn%2Fws-sockette/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jellydn%2Fws-sockette/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jellydn%2Fws-sockette/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jellydn","download_url":"https://codeload.github.com/jellydn/ws-sockette/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975305,"owners_count":21192197,"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":["nodejs","websocket","ws"],"created_at":"2025-03-11T21:54:10.431Z","updated_at":"2026-03-12T11:05:18.432Z","avatar_url":"https://github.com/jellydn.png","language":"TypeScript","funding_links":["https://github.com/sponsors/jellydn","https://ko-fi.com/dunghd"],"categories":[],"sub_categories":[],"readme":"# Welcome to ws-sockette 👋\n\n![Version](https://img.shields.io/badge/version-0.1.0-blue.svg?cacheSeconds=2592000)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](#)\n[![Twitter: jellydn](https://img.shields.io/twitter/follow/jellydn.svg?style=social)](https://twitter.com/jellydn)\n\n\u003e The little WebSocket wrapper for nodejs\n\n## Install\n\n```sh\nyarn add ws-sockette\n```\n\n## Why\n\n[Sockette](https://github.com/lukeed/sockette) is a tiny (367 bytes) wrapper around WebSocket that will automatically reconnect if the connection is lost!\n\nHowever, sockette doesn't work for nodejs and missing support for [client options](https://github.com/lukeed/sockette/blob/master/src/index.js#L10) for create a websocket client\n\n```typescript\nnew WebSocket(\n        address: string | URL,\n        protocols?: string | string[],\n        options?: WebSocket.ClientOptions | ClientRequestArgs,\n    );\n```\n\nThat's why I take a chance to rewrite with typescript and support nodejs. If you need a tiny wrapper for browser, please use sockette.\n\n## Usage\n\n```typescript\nimport { wsSockette } from \"ws-sockette\";\n\nconst ws = wsSockette(\"ws://localhost:3000\", {\n  clientOptions: {\n    headers: {\n      Authorization: \"Basic YWxhZGRpbjpvcGVuc2VzYW1l\",\n    },\n  },\n  timeout: 5e3,\n  maxAttempts: 10,\n  onopen: (e) =\u003e console.log(\"Connected!\", e),\n  onmessage: (e) =\u003e console.log(\"Received:\", e),\n  onreconnect: (e) =\u003e console.log(\"Reconnecting...\", e),\n  onmaximum: (e) =\u003e console.log(\"Stop Attempting!\", e),\n  onclose: (e) =\u003e console.log(\"Closed!\", e),\n  onerror: (e) =\u003e console.log(\"Error:\", e),\n});\n\nws.send(\"Hello, world!\");\nws.json({ type: \"ping\" });\nws.close(); // graceful shutdown\n\n// Reconnect 10s later\nsetTimeout(ws.reconnect, 10e3);\n```\n\n## API\n\n```typescript\ninterface SocketteOptions {\n  // This is a new option if you compare with sockette\n  clientOptions?: WebSocket.ClientOptions | ClientRequestArgs;\n\n  protocols?: string | string[];\n  timeout?: number;\n  maxAttempts?: number;\n  onopen?: (ev: WebSocket.Event) =\u003e any;\n  onmessage?: (ev: WebSocket.MessageEvent) =\u003e any;\n  onreconnect?: (ev: WebSocket.ErrorEvent | WebSocket.CloseEvent) =\u003e any;\n  onmaximum?: (ev: WebSocket.ErrorEvent | WebSocket.CloseEvent) =\u003e any;\n  onclose?: (ev: WebSocket.CloseEvent) =\u003e any;\n  onerror?: (ev: WebSocket.ErrorEvent) =\u003e any;\n}\n```\n\nPlease check [here for complete document](https://github.com/lukeed/sockette/blob/master/readme.md#api)\n\n## Run tests\n\n```sh\nyarn test\n```\n\n## Author\n\n👤 **Huynh Duc Dung**\n\n- Website: https://productsway.com/\n- Twitter: [@jellydn](https://twitter.com/jellydn)\n- Github: [@jellydn](https://github.com/jellydn)\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n\n---\n\n_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjellydn%2Fws-sockette","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjellydn%2Fws-sockette","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjellydn%2Fws-sockette/lists"}