{"id":39067222,"url":"https://github.com/mitz-it/websocket-client","last_synced_at":"2026-01-17T18:17:23.984Z","repository":{"id":65177499,"uuid":"585725128","full_name":"mitz-it/websocket-client","owner":"mitz-it","description":"An abstraction over WebSocket to manage strongly typed messages","archived":false,"fork":false,"pushed_at":"2023-10-19T17:01:48.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-09-23T16:47:02.390Z","etag":null,"topics":["abstraction","web-socket","web-sockets","websocket","websockets"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitz-it.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-01-05T22:57:12.000Z","updated_at":"2023-01-06T17:49:43.000Z","dependencies_parsed_at":"2023-01-13T15:53:09.003Z","dependency_job_id":"f65618a7-72a2-41cf-ab82-97c6e6b5cd86","html_url":"https://github.com/mitz-it/websocket-client","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/mitz-it/websocket-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitz-it%2Fwebsocket-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitz-it%2Fwebsocket-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitz-it%2Fwebsocket-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitz-it%2Fwebsocket-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitz-it","download_url":"https://codeload.github.com/mitz-it/websocket-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitz-it%2Fwebsocket-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28515214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T17:57:59.192Z","status":"ssl_error","status_checked_at":"2026-01-17T17:57:52.527Z","response_time":85,"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":["abstraction","web-socket","web-sockets","websocket","websockets"],"created_at":"2026-01-17T18:17:21.754Z","updated_at":"2026-01-17T18:17:23.952Z","avatar_url":"https://github.com/mitz-it.png","language":"TypeScript","readme":"# Mitz IT - Web Socket Client\n\nA higher-level abstraction of the `WebSocket` object that manages strongly-typed received messages.\n\n## Installation\n\n```bash\nnpm install @mitz-it/websocket-client@^2.0.0\n```\n\n## Usage\n\nImport the client:\n\n```javascript\nimport WebSocketClient from \"@mitz-it/websocket-client\";\n```\n\nStrongly typed messages can be managed using corresponding strongly typed handlers, represented by `MessageHandler\u003cTMessage\u003e`:\n\n| Property | Type                          | Description                             |\n| -------- | ----------------------------- | --------------------------------------- |\n| key      | `string`                      | Unique identifier for the message type  |\n| callback | `OnMessageCallback\u003cTMessage\u003e` | Function invoked with the typed message |\n| assert   | `TypeAssertion\u003cTMessage\u003e`     | Asserts if a message matches the type   |\n\nDefine your handler by implementing the `MessageHandler\u003cTMessage\u003e` structure:\n\n```typescript\ninterface CustomMessage {\n  foo: string;\n  bar: int;\n}\n\nconst callback = (message: CustomMessage): void =\u003e {\n  console.log(message);\n};\n\nconst assert = (message: any): message is CustomMessage =\u003e {\n  return \"foo\" in message \u0026\u0026 \"bar\" in message;\n};\n\nconst handler = {\n  key: \"custom-message-key\",\n  callback: callback,\n  assert: assert,\n};\n```\n\nCreate an instance of the `WebSocketClient` object, and register the handler:\n\n```typescript\nconst client = new WebSocketClient(\"wss://some-domain.com\");\n\nclient.addMessageHandler(handler);\n\nclient.connect(\n  () =\u003e console.log(\"Connected!\"),\n  (e, reconnect) =\u003e {\n    if (e.code === YOUR_SERVER_CODE_FOR_MAX_TIME_LIMIT) {\n      console.log(\"Reconnecting...\");\n      reconnect();\n    }\n  }\n);\n```\n\nPublishing a message:\n\n```typescript\nclient.publish\u003cCustomMessage\u003e({ foo: \"string\", bar: 1 });\n```\n\nSafe publishing:\n\n```typescript\nif (client.connected())\n  client.publish\u003cCustomMessage\u003e({ foo: \"string\", bar: 1 });\n```\n\nRemove a handler:\n\n```typescript\nclient.removeMessageHandler(\"custom-message-key\");\n```\n\nClear all handlers:\n\n```typescript\nclient.clearMessageHandlers();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitz-it%2Fwebsocket-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitz-it%2Fwebsocket-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitz-it%2Fwebsocket-client/lists"}