{"id":19245088,"url":"https://github.com/rxtoolkit/ws","last_synced_at":"2025-02-23T15:15:40.189Z","repository":{"id":214798842,"uuid":"365888716","full_name":"rxtoolkit/ws","owner":"rxtoolkit","description":"🔌 RxJS operators for working with WebSockets","archived":false,"fork":false,"pushed_at":"2024-03-27T12:38:50.000Z","size":597,"stargazers_count":1,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-05T05:49:06.274Z","etag":null,"topics":["fp","functional-programming","observables","package","reactive-programming","rxjs","websocket","websockets"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/rxtoolkit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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":"2021-05-10T01:50:42.000Z","updated_at":"2024-01-02T15:45:42.000Z","dependencies_parsed_at":"2024-11-09T17:30:18.327Z","dependency_job_id":"c36801f6-aca6-4908-bfea-f68254db5233","html_url":"https://github.com/rxtoolkit/ws","commit_stats":null,"previous_names":["rxtoolkit/ws"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxtoolkit%2Fws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxtoolkit%2Fws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxtoolkit%2Fws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxtoolkit%2Fws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rxtoolkit","download_url":"https://codeload.github.com/rxtoolkit/ws/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240331361,"owners_count":19784646,"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":["fp","functional-programming","observables","package","reactive-programming","rxjs","websocket","websockets"],"created_at":"2024-11-09T17:26:35.581Z","updated_at":"2025-02-23T15:15:40.089Z","avatar_url":"https://github.com/rxtoolkit.png","language":"JavaScript","readme":"# @rxtk/ws\n\u003e 🔌 RxJS operators for working with WebSockets\n\n```bash\nnpm i @rxtk/ws\n```\n\n```bash\nyarn add @rxtk/ws\n```\n\n## API\n\n### `conduit`\nOpening a two-way WebSocket is a very common software pattern.  The `conduit` operator makes it trivially easy to do this.  It pipes an Observable into a two-way websocket. Each item in the input Observable will be published to the server. The output Observable will be the messages sent from the server to the client.\n\nOptionally, it can be performed using a custom serializer or deserializer -- otherwise, it will assume the messages are encoded/decoded as JSON and transmitted as JSON strings.\n\nThe conduit also supports error handling and many disconnection scenarios (see examples below).\n\n#### Basic usage\n```javascript\nimport { from } from 'rxjs';\nimport { conduit } from '@rxtk/ws';\n\nconst messagesToSend$ = from([\n  {body: 'data'},\n  {body: 'more data'},\n]);\nconst socketResponse$ = messageToSend$.pipe(\n  conduit({url: 'wss://mysite.com'})\n);\n\nsocketResponse$.subscribe(); // this will attempt to send the messages to the server\n```\n\n#### With error handling\n```javascript\nimport { from } from 'rxjs';\nimport { conduit } from '@rxtk/ws';\n\nconst messagesToSend$ = from([\n  {body: 'data'},\n  {body: 'more data'},\n]);\nconst socketResponse$ = messageToSend$.pipe(\n  conduit({url: 'wss://mysite.com'})\n);\n\nsocketResponse$.subscribe(); // this will attempt to send the messages to the server\nsocketResponse$.error$.subscribe(); // returns WebSocket errors\n```\n\n#### Custom serialization\n```javascript\nimport { from } from 'rxjs';\nimport { conduit } from '@rxtk/ws';\n\nconst decodeMessage = base64Message =\u003e atob(base64Message);\nconst encodeMessage = binaryString =\u003e btoa(binaryString);\n\nconst messagesToSend$ = from([\n  'somebinarystring',\n  'anotherbinarystring',\n]);\nconst socketResponse$ = messageToSend$.pipe(\n  conduit({\n    url: 'wss://mysite.com',\n    serializer: encodeMessage,\n    deserializer: decodeMessage,\n  })\n);\nsocketResponse$.subscribe();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxtoolkit%2Fws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frxtoolkit%2Fws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxtoolkit%2Fws/lists"}