{"id":17033979,"url":"https://github.com/yisibell/myws","last_synced_at":"2026-04-07T13:32:02.842Z","repository":{"id":57307056,"uuid":"449129283","full_name":"yisibell/myws","owner":"yisibell","description":"A tiny websocket client library.","archived":false,"fork":false,"pushed_at":"2024-07-23T07:19:55.000Z","size":229,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-01T11:49:36.790Z","etag":null,"topics":["mitt","vue","vue-plugin","websocket","websocket-client"],"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/yisibell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2022-01-18T03:37:50.000Z","updated_at":"2024-07-23T07:19:59.000Z","dependencies_parsed_at":"2024-01-18T10:59:50.876Z","dependency_job_id":null,"html_url":"https://github.com/yisibell/myws","commit_stats":{"total_commits":23,"total_committers":3,"mean_commits":7.666666666666667,"dds":0.5217391304347826,"last_synced_commit":"a9ff856c3ef9cab9898950a5f188b48bdebe2886"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/yisibell/myws","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisibell%2Fmyws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisibell%2Fmyws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisibell%2Fmyws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisibell%2Fmyws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yisibell","download_url":"https://codeload.github.com/yisibell/myws/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisibell%2Fmyws/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31515144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T03:10:19.677Z","status":"ssl_error","status_checked_at":"2026-04-07T03:10:13.982Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["mitt","vue","vue-plugin","websocket","websocket-client"],"created_at":"2024-10-14T08:36:59.047Z","updated_at":"2026-04-07T13:32:02.824Z","avatar_url":"https://github.com/yisibell.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.org/package/myws\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/myws.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://npmcharts.com/compare/myws?minimal=true\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/myws.svg\"\u003e\n  \u003c/a\u003e\n  \u003cbr\u003e\n\u003c/p\u003e\n\n\n# myws\n\nA tiny websocket client library.\n\n- [Release Notes](./CHANGELOG.md).\n\n# Features\n\n- Automatically reconnect when websocket fails.\n- Support event subscription mode, receive messages by listening to events.\n- Support **Typescript**.\n\n# Installation\n\n```bash\n# pnpm\n$ pnpm add myws\n\n# yarn\n$ yarn add myws\n\n# npm\n$ npm i myws\n```\n\n# Basic Usage\n\n``` ts\nimport { initMyws } from 'myws'\n\nlet mywsInstance = initMyws({\n  open: ture,\n  api: 'wss://server/some/path',\n  // ...\n}, (wsInstance) =\u003e {\n  // 想要自动重连功能有效的话，你需要使用该回调函数对 ws 示例对象进行赋值更新。\n  mywsInstance = wsInstance\n})\n```\n\n# In Vue2\n\n\u003e **TIPS**: 该方式已不再推荐使用，请使用 `initMyws` 替代。\n\n``` ts\nimport Vue from 'vue'\nimport { wsInstaller } from 'myws'\n\nVue.use(wsInstaller, {\n  open: true,\n  api: 'wss://server/some/path'\n  // ...\n})\n```\n\n# Ws Instance \n\n初始化 `WebSocket` 后，会返回一个 `wsInstance` 示例对象。该对象包含以下几个属性。\n\n1. `WS` : 即，`new WebSocket()` 返回的示例对象。\n2. `WsBus` : 则是一个事件总线，由 `mitt` 实例化而来，你可以使用它监听 `WebSocket` 的消息。\n3. `connected` : (`boolean`) 表示 `WebSocket` 是否已完成连接。\n\n\n# Options\n\n| Key | Type | Default Value | Description  |\n| :---: | :---: | :---: | :---:  |\n| `open` | `boolean`, `string`, `number` | `true` | 是否开启 ws |\n| `api` |  `string` | - |  ws 服务地址 |\n| `protocols` |  `string`, `string[]` | `undefined` |  一个协议字符串或者一个包含协议字符串的数组。 |\n| `heart_interval` |  `number` | `50000` | ws 心跳间隔，毫秒数。 |\n| `heart_data` |  `() =\u003e any` | `undefined` | ws 心跳时传递的参数。 |\n| `reconnect_interval` |  `number` | `3000` | ws 重连间隔，毫秒数。 |\n| `reconnect_limit` |  `number` | `30` | 自动重连次数限制。|\n| `reconnect_limit_msg` |  `string` | - | 超出重连次数时的提示文本。|\n| `reconnect_msg` |  `string`, `(count: number) =\u003e string` | - | 每次尝试重连 ws 时的提示文本, 也可以是一个函数，该函数会被传入当前的重连计数。|\n| `ws_bus_emit_names` |  `Record\u003cstring, string\u003e` | - | 自定义在响应 ws 消息时，WsBus 的 emit 事件名。|\n| `onmessage` |  `(data: any) =\u003e void` | - | 接收 message 时回调。|\n| `onopen` |  `(e: Event) =\u003e void` | - | WebSocket 连接时回调。|\n| `onerror` |  `(e: Event) =\u003e void` | - | WebSocket 出错时回调。|\n| `onclose` |  `(e: Event) =\u003e void` | - | WebSocket 关闭时回调。|\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyisibell%2Fmyws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyisibell%2Fmyws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyisibell%2Fmyws/lists"}