{"id":13795553,"url":"https://github.com/OrdinarySF/capacitor-websocket-client","last_synced_at":"2025-05-12T23:32:23.687Z","repository":{"id":179869987,"uuid":"664276046","full_name":"OrdinarySF/capacitor-websocket-client","owner":"OrdinarySF","description":"Capacitor WebSocket Client Plugin.","archived":false,"fork":false,"pushed_at":"2023-07-15T07:06:26.000Z","size":201,"stargazers_count":52,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-24T23:15:42.997Z","etag":null,"topics":["adroid","capacitor","capacitor-plugin","ionic","websocket"],"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/OrdinarySF.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2023-07-09T13:22:44.000Z","updated_at":"2025-04-16T07:51:10.000Z","dependencies_parsed_at":"2024-01-02T23:09:52.343Z","dependency_job_id":"09bf076a-8be9-4f35-bb52-18e48fd6b49a","html_url":"https://github.com/OrdinarySF/capacitor-websocket-client","commit_stats":null,"previous_names":["ordinarysf/capacitor-websocket-client"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OrdinarySF%2Fcapacitor-websocket-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OrdinarySF%2Fcapacitor-websocket-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OrdinarySF%2Fcapacitor-websocket-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OrdinarySF%2Fcapacitor-websocket-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OrdinarySF","download_url":"https://codeload.github.com/OrdinarySF/capacitor-websocket-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253840988,"owners_count":21972574,"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":["adroid","capacitor","capacitor-plugin","ionic","websocket"],"created_at":"2024-08-03T23:00:58.582Z","updated_at":"2025-05-12T23:32:23.323Z","avatar_url":"https://github.com/OrdinarySF.png","language":"TypeScript","readme":"# @wahr/capacitor-websocket-client\n\n[![Downloads][badge-dl]][download]\n[![License][badge-license]][license]\n[![Issues][badge-issues]][issues]\n[![Version][badge-version]][download]\n\n[badge-dl]: https://img.shields.io/npm/dw/%40wahr%2Fcapacitor-websocket-client?style=flat-square\n[download]: https://www.npmjs.com/package/@wahr/capacitor-websocket-client?activeTab=versions\n[badge-license]: https://img.shields.io/npm/l/%40wahr%2Fcapacitor-websocket-client?style=flat-square\n[license]: https://github.com/OrdinarySF/capacitor-websocket-client/blob/main/LICENSE\n[badge-issues]: https://img.shields.io/github/issues/OrdinarySF/capacitor-websocket-client?style=flat-square\n[issues]: https://github.com/OrdinarySF/capacitor-websocket-client/issues\n[badge-version]: https://img.shields.io/npm/v/%40wahr%2Fcapacitor-websocket-client?style=flat-square\n\n\nCapacitor WebSocket Client Plugin.\n\n## Install\n\n```bash\nnpm install @wahr/capacitor-websocket-client\nnpx cap sync\n```\n\n## Platform support\n\n- Web\n- Android\n\n\u003e Unfortunately, we do not have a macOS device, but we are working hard.\n\n## Example\n\n#### Single connect\n\n```typescript\nawait WebSocket.onOpen({}, (message, err) =\u003e {\n    //do something...\n    console.log(\"onOpen event have a bug: \", err?.toString())\n})\n\nawait WebSocket.onMessage({}, (message, err) =\u003e {\n    //do something...\n    console.log(`received message content: ${message?.data}`)\n})\n\nawait WebSocket.connect({url: \"ws://example.com\"})\n\nsetTimeout(async () =\u003e {\n    await WebSocket.send({data: \"hello world!\"})\n}, 2000);\n```\n\n#### Multiple connect\n\n```typescript\nawait WebSocket.onOpen({id: \"chat-websocket\"}, (message, err) =\u003e {\n    //do something...\n    console.log(\"onOpen event have a bug: \", err?.toString())\n})\n\nawait WebSocket.connect({url: \"ws://example.com/chat\", id: \"chat-websocket\"})\n\nawait WebSocket.onMessage({id: \"notify-websocket\"}, (message, err) =\u003e {\n    //do something...\n    console.log(`received notify content: ${message?.data}`)\n})\n\nawait WebSocket.connect({url: \"ws://example.com/notify\", id: \"notify-websocket\"})\n\nsetTimeout(async () =\u003e {\n    await WebSocket.send({data: \"hello world!\", id: \"chat-websocket\"})\n    await WebSocket.send({data: \"connect notify.\", id: \"notify-websocket\"})\n}, 2000)\n```\n\n## API\n\n\u003cdocgen-index\u003e\n\n* [`connect(...)`](#connect)\n* [`close(...)`](#close)\n* [`send(...)`](#send)\n* [`onOpen(...)`](#onopen)\n* [`onMessage(...)`](#onmessage)\n* [`onClose(...)`](#onclose)\n* [`onError(...)`](#onerror)\n* [Interfaces](#interfaces)\n* [Type Aliases](#type-aliases)\n\n\u003c/docgen-index\u003e\n\n\u003cdocgen-api\u003e\n\u003c!--Update the source file JSDoc comments and rerun docgen to update the docs below--\u003e\n\n### connect(...)\n\n```typescript\nconnect(options\n:\nConnectionOptions\n) =\u003e\nPromise\u003cvoid\u003e\n```\n\nInitiate a WebSocket connection.\n\n| Param         | Type                                                            | Description                     |\n|---------------|-----------------------------------------------------------------|---------------------------------|\n| **`options`** | \u003ccode\u003e\u003ca href=\"#connectionoptions\"\u003eConnectionOptions\u003c/a\u003e\u003c/code\u003e | The options for the connection. |\n\n**Since:** 0.0.1\n\n--------------------\n\n### close(...)\n\n```typescript\nclose(options ? : CloseOptions | undefined)\n=\u003e\nPromise\u003cvoid\u003e\n```\n\nClose the connection.\n\n| Param         | Type                                                  |\n|---------------|-------------------------------------------------------|\n| **`options`** | \u003ccode\u003e\u003ca href=\"#closeoptions\"\u003eCloseOptions\u003c/a\u003e\u003c/code\u003e |\n\n--------------------\n\n### send(...)\n\n```typescript\nsend(options\n:\nSendMessageOptions\n) =\u003e\nPromise\u003cvoid\u003e\n```\n\nSend a message.\n\n| Param         | Type                                                              | Description                  |\n|---------------|-------------------------------------------------------------------|------------------------------|\n| **`options`** | \u003ccode\u003e\u003ca href=\"#sendmessageoptions\"\u003eSendMessageOptions\u003c/a\u003e\u003c/code\u003e | The options for the message. |\n\n**Since:** 0.0.1\n\n--------------------\n\n### onOpen(...)\n\n```typescript\nonOpen(options\n:\nOnOpenOptions, callback\n:\nOnOpenCallback\n) =\u003e\nPromise\u003cvoid\u003e\n```\n\nRegister a callback to be invoked when the connection is opened.\n\n| Param          | Type                                                      | Description                          |\n|----------------|-----------------------------------------------------------|--------------------------------------|\n| **`options`**  | \u003ccode\u003e\u003ca href=\"#onopenoptions\"\u003eOnOpenOptions\u003c/a\u003e\u003c/code\u003e   | The options for the connection info. |\n| **`callback`** | \u003ccode\u003e\u003ca href=\"#onopencallback\"\u003eOnOpenCallback\u003c/a\u003e\u003c/code\u003e | The callback that will be invoked.   |\n\n**Since:** 0.0.3\n\n--------------------\n\n### onMessage(...)\n\n```typescript\nonMessage(options\n:\nOnMessageOptions, callback\n:\nOnMessageCallback\n) =\u003e\nPromise\u003cvoid\u003e\n```\n\nRegister a callback to be invoked when a message is received.\n\n| Param          | Type                                                            | Description                        |\n|----------------|-----------------------------------------------------------------|------------------------------------|\n| **`options`**  | \u003ccode\u003e\u003ca href=\"#onmessageoptions\"\u003eOnMessageOptions\u003c/a\u003e\u003c/code\u003e   | The options for the message info.  |\n| **`callback`** | \u003ccode\u003e\u003ca href=\"#onmessagecallback\"\u003eOnMessageCallback\u003c/a\u003e\u003c/code\u003e | The callback that will be invoked. |\n\n**Since:** 0.0.3\n\n--------------------\n\n### onClose(...)\n\n```typescript\nonClose(options\n:\nOnCloseOptions, callback\n:\nOnCloseCallback\n) =\u003e\nPromise\u003cvoid\u003e\n```\n\nRegister a callback to be invoked when the connection is closed.\n\n| Param          | Type                                                        | Description                          |\n|----------------|-------------------------------------------------------------|--------------------------------------|\n| **`options`**  | \u003ccode\u003e\u003ca href=\"#oncloseoptions\"\u003eOnCloseOptions\u003c/a\u003e\u003c/code\u003e   | The options for the connection info. |\n| **`callback`** | \u003ccode\u003e\u003ca href=\"#onclosecallback\"\u003eOnCloseCallback\u003c/a\u003e\u003c/code\u003e | The callback that will be invoked.   |\n\n**Since:** 0.0.3\n\n--------------------\n\n### onError(...)\n\n```typescript\nonError(options\n:\nOnErrorOptions, callback\n:\nOnErrorCallback\n) =\u003e\nPromise\u003cvoid\u003e\n```\n\nRegister a callback to be invoked when an error occurs.\n\n| Param          | Type                                                        | Description                        |\n|----------------|-------------------------------------------------------------|------------------------------------|\n| **`options`**  | \u003ccode\u003e\u003ca href=\"#onerroroptions\"\u003eOnErrorOptions\u003c/a\u003e\u003c/code\u003e   | The options for the error info.    |\n| **`callback`** | \u003ccode\u003e\u003ca href=\"#onerrorcallback\"\u003eOnErrorCallback\u003c/a\u003e\u003c/code\u003e | The callback that will be invoked. |\n\n**Since:** 0.0.3\n\n--------------------\n\n### Interfaces\n\n#### ConnectionOptions\n\n| Prop      | Type                | Description                                                                                             | Since |\n|-----------|---------------------|---------------------------------------------------------------------------------------------------------|-------|\n| **`url`** | \u003ccode\u003estring\u003c/code\u003e | The URL to which to connect; this should be the URL to which the WebSocket server will respond.         | 0.0.1 |\n| **`id`**  | \u003ccode\u003estring\u003c/code\u003e | The ID uniquely identifies a connection; no input is required, if you do not need multiple connections. | 0.0.1 |\n\n#### CloseOptions\n\n| Prop         | Type                | Description                                                                                                                                                                            |\n|--------------|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **`id`**     | \u003ccode\u003estring\u003c/code\u003e | The ID uniquely identifies a connection; no input is required, if you do not need multiple connections.                                                                                |\n| **`code`**   | \u003ccode\u003enumber\u003c/code\u003e | An integer WebSocket connection close code value indicating a reason for closure. Status code as defined by [Section 7.4 of RFC 6455](http://tools.ietf.org/html/rfc6455#section-7.4). |\n| **`reason`** | \u003ccode\u003estring\u003c/code\u003e | A string explaining the reason for the connection close.                                                                                                                               |\n\n#### SendMessageOptions\n\n| Prop       | Type                | Description                                                                                             | Since |\n|------------|---------------------|---------------------------------------------------------------------------------------------------------|-------|\n| **`data`** | \u003ccode\u003estring\u003c/code\u003e | The data to send to the server.                                                                         | 0.0.1 |\n| **`id`**   | \u003ccode\u003estring\u003c/code\u003e | The ID uniquely identifies a connection; no input is required, if you do not need multiple connections. | 0.0.1 |\n\n#### OnOpenOptions\n\n| Prop     | Type                | Description                                                                                             | Since |\n|----------|---------------------|---------------------------------------------------------------------------------------------------------|-------|\n| **`id`** | \u003ccode\u003estring\u003c/code\u003e | The ID uniquely identifies a connection; no input is required, if you do not need multiple connections. | 0.0.1 |\n\n#### OnOpenData\n\n| Prop     | Type                | Description                                                                                             | Since |\n|----------|---------------------|---------------------------------------------------------------------------------------------------------|-------|\n| **`id`** | \u003ccode\u003estring\u003c/code\u003e | The ID uniquely identifies a connection; no input is required, if you do not need multiple connections. | 0.0.1 |\n\n#### OnMessageOptions\n\n| Prop     | Type                | Description                                                                                             | Since |\n|----------|---------------------|---------------------------------------------------------------------------------------------------------|-------|\n| **`id`** | \u003ccode\u003estring\u003c/code\u003e | The ID uniquely identifies a connection; no input is required, if you do not need multiple connections. | 0.0.1 |\n\n#### OnMessageData\n\n| Prop       | Type                | Description                                                                                             | Since |\n|------------|---------------------|---------------------------------------------------------------------------------------------------------|-------|\n| **`id`**   | \u003ccode\u003estring\u003c/code\u003e | The ID uniquely identifies a connection; no input is required, if you do not need multiple connections. | 0.0.1 |\n| **`data`** | \u003ccode\u003estring\u003c/code\u003e | The data sent by the message emitter.                                                                   | 0.0.1 |\n\n#### OnCloseOptions\n\n| Prop     | Type                | Description                                                                                             | Since |\n|----------|---------------------|---------------------------------------------------------------------------------------------------------|-------|\n| **`id`** | \u003ccode\u003estring\u003c/code\u003e | The ID uniquely identifies a connection; no input is required, if you do not need multiple connections. | 0.0.1 |\n\n#### OnCloseData\n\n| Prop         | Type                | Description                                                                                                                                                                            | Since |\n|--------------|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------|\n| **`id`**     | \u003ccode\u003estring\u003c/code\u003e | The ID uniquely identifies a connection; no input is required, if you do not need multiple connections.                                                                                | 0.0.1 |\n| **`code`**   | \u003ccode\u003enumber\u003c/code\u003e | An integer WebSocket connection close code value indicating a reason for closure. Status code as defined by [Section 7.4 of RFC 6455](http://tools.ietf.org/html/rfc6455#section-7.4). | 0.0.1 |\n| **`reason`** | \u003ccode\u003estring\u003c/code\u003e | A string explaining the reason for the connection close.                                                                                                                               | 0.0.1 |\n\n#### OnErrorOptions\n\n| Prop     | Type                | Description                                                                                             | Since |\n|----------|---------------------|---------------------------------------------------------------------------------------------------------|-------|\n| **`id`** | \u003ccode\u003estring\u003c/code\u003e | The ID uniquely identifies a connection; no input is required, if you do not need multiple connections. | 0.0.1 |\n\n#### OnErrorData\n\n| Prop        | Type                | Description                                                                                             | Since |\n|-------------|---------------------|---------------------------------------------------------------------------------------------------------|-------|\n| **`id`**    | \u003ccode\u003estring\u003c/code\u003e | The ID uniquely identifies a connection; no input is required, if you do not need multiple connections. | 0.0.1 |\n| **`error`** | \u003ccode\u003estring\u003c/code\u003e | The error message.                                                                                      | 0.0.1 |\n\n### Type Aliases\n\n#### OnOpenCallback\n\n\u003ccode\u003e(message: \u003ca href=\"#onopendata\"\u003eOnOpenData\u003c/a\u003e | null, err?: any): void\u003c/code\u003e\n\n#### OnMessageCallback\n\n\u003ccode\u003e(message: \u003ca href=\"#onmessagedata\"\u003eOnMessageData\u003c/a\u003e | null, err?: any): void\u003c/code\u003e\n\n#### OnCloseCallback\n\n\u003ccode\u003e(message: \u003ca href=\"#onclosedata\"\u003eOnCloseData\u003c/a\u003e | null, err?: any): void\u003c/code\u003e\n\n#### OnErrorCallback\n\n\u003ccode\u003e(message: \u003ca href=\"#onerrordata\"\u003eOnErrorData\u003c/a\u003e | null, err?: any): void\u003c/code\u003e\n\n\u003c/docgen-api\u003e\n","funding_links":[],"categories":["Plugins","Other plugins"],"sub_categories":["Community Plugins","Specialized Hardware"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOrdinarySF%2Fcapacitor-websocket-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOrdinarySF%2Fcapacitor-websocket-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOrdinarySF%2Fcapacitor-websocket-client/lists"}