{"id":23197892,"url":"https://github.com/z-hao-wang/websocket-reconnect","last_synced_at":"2025-07-29T03:04:22.072Z","repository":{"id":50796178,"uuid":"179579942","full_name":"z-hao-wang/websocket-reconnect","owner":"z-hao-wang","description":"websocket auto reconnect wrapper","archived":false,"fork":false,"pushed_at":"2024-06-17T20:12:35.000Z","size":29,"stargazers_count":6,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-28T21:48:42.904Z","etag":null,"topics":["javascript","nodejs","typescript","websocket"],"latest_commit_sha":null,"homepage":null,"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/z-hao-wang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2019-04-04T21:29:10.000Z","updated_at":"2024-03-29T12:03:52.000Z","dependencies_parsed_at":"2024-01-18T14:42:00.167Z","dependency_job_id":"347b5839-ecda-4f68-9832-0a5350c7438b","html_url":"https://github.com/z-hao-wang/websocket-reconnect","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"debc8515368e699b9c8b1b7d03e97e452b1d63fd"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/z-hao-wang/websocket-reconnect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z-hao-wang%2Fwebsocket-reconnect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z-hao-wang%2Fwebsocket-reconnect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z-hao-wang%2Fwebsocket-reconnect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z-hao-wang%2Fwebsocket-reconnect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/z-hao-wang","download_url":"https://codeload.github.com/z-hao-wang/websocket-reconnect/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z-hao-wang%2Fwebsocket-reconnect/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267621579,"owners_count":24116900,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["javascript","nodejs","typescript","websocket"],"created_at":"2024-12-18T14:37:53.019Z","updated_at":"2025-07-29T03:04:22.042Z","avatar_url":"https://github.com/z-hao-wang.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# websocket reconnect \n\nWith typing and data caching\n\n## Getting Started\n\nThis repo will create a websocket client that auto retry to reconnect to the sever\nIt will also cache the messages that failed to send and send after reconnect success.\n\n```\nnpm i websocket-reconnect --save\n\nimport { WsReconnect } from '../src/WsReconnect';\nconst ws = new WsReconnect({ reconnectDelay: 5000 });\nws.open(`ws://${host}:${port}`);\n\nws.on('open', function open() {\n    // this will only be called once, not on reconnect\n});\n\nws.on('reconnect', function open() {\n    // this will only be called on every reconnect attempt\n});\n\nws.on('message', (data: string) =\u003e {\n    const json = JSON.parse(data);\n    console.log('======== received', json);\n});\n\nws.on('close', () =\u003e {\n    interval \u0026\u0026 clearInterval(interval);\n});\n```\nPlease refer the examples for more details\n\n## Testing with examples\n```\nnpm ci\nnpm run tsc\n# run this in terminal #1\nnode dist/example/WsServer.js\n# run this in terminal #2\nnode dist/example/WsClient.js\n```\n\nThen ctrl + c to exist terminal #1, watch the terminal #2 WsClient to auto reconnect, once WsServer is restarted, the WsClient can rebuild connect.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz-hao-wang%2Fwebsocket-reconnect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fz-hao-wang%2Fwebsocket-reconnect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz-hao-wang%2Fwebsocket-reconnect/lists"}