{"_id":"@arkosjs/websockets-client","_rev":"5-000ec1073d6d8135ddcf3afef036c862","name":"@arkosjs/websockets-client","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0-canary":{"name":"@arkosjs/websockets-client","version":"0.1.0-canary","author":{"name":"Uanela Como"},"license":"MIT","_id":"@arkosjs/websockets-client@0.1.0-canary","maintainers":[{"name":"uanela","email":"uanelaluiswayne@gmail.com"}],"homepage":"https://www.arkosjs.com","bugs":{"url":"https://github.com/uanela/arkos/issues"},"dist":{"shasum":"867fd6f53720566c4bec3629e80fb9829ae71e8d","tarball":"https://registry.npmjs.org/@arkosjs/websockets-client/-/websockets-client-0.1.0-canary.tgz","fileCount":20,"integrity":"sha512-84wGfH2Qkajp+AtXY5NkApkLso4Pi8kZ3xhjagXDgIcBt3I+yfh14ChWqRhkg4KuZPfAXE8apUHoOS6530go4g==","signatures":[{"sig":"MEUCIQDTrCWKu8N+EmkO9qruKfRqAfTGBPrqKobN/BJAIdZMIAIgEWH8qQaiqi/bZk+5SkYJu3H2AJW0jtmWVRHy14MUD60=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":33543},"main":"dist/exports/index.js","types":"dist/exports/index.d.ts","module":"dist/exports/index.js","gitHead":"08b04cc251fdbe56faae194c4f69f75f7dd0f412","scripts":{"build":"rm -r ./dist && tsc","typecheck":"tsc --noEmit"},"_npmUser":{"name":"uanela","email":"uanelaluiswayne@gmail.com"},"repository":{"url":"git+https://github.com/uanela/arkos.git","type":"git"},"_npmVersion":"10.9.8","description":"Framework-agnostic WebSocket client for Arkos Gateway","directories":{},"_nodeVersion":"22.22.3","dependencies":{"socket.io-client":"^4.7.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^6.0.3"},"peerDependencies":{"socket.io-client":"^4.7.0"},"_npmOperationalInternal":{"tmp":"tmp/websockets-client_0.1.0-canary_1779981966273_0.3057635378996568","host":"s3://npm-registry-packages-npm-production"}},"0.1.0-canary.1":{"name":"@arkosjs/websockets-client","version":"0.1.0-canary.1","author":{"name":"Uanela Como"},"license":"MIT","_id":"@arkosjs/websockets-client@0.1.0-canary.1","maintainers":[{"name":"uanela","email":"uanelaluiswayne@gmail.com"}],"homepage":"https://www.arkosjs.com","bugs":{"url":"https://github.com/uanela/arkos/issues"},"dist":{"shasum":"48515cf06326c796097643bd5dfe47692e3d8e75","tarball":"https://registry.npmjs.org/@arkosjs/websockets-client/-/websockets-client-0.1.0-canary.1.tgz","fileCount":20,"integrity":"sha512-6hh5P7Jdn6rKdBkt06EgVG7rvzNUHir4iynLLOrriax8pYdnUVK6A5I7ILjM5M8HgF7fh9wR2EBkkVHeNk3yaA==","signatures":[{"sig":"MEUCIQCIGQmOtXOkpKeAfYkD48VE8jKo3OQ9NekLcsdPHvD+wQIgPCCIPW2ernO5+WUeCihEabhkcNHT56SB/bYrFXRyApU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":33545},"main":"dist/exports/index.js","types":"dist/exports/index.d.ts","module":"dist/exports/index.js","gitHead":"08b04cc251fdbe56faae194c4f69f75f7dd0f412","scripts":{"build":"rm -r ./dist && tsc","typecheck":"tsc --noEmit"},"_npmUser":{"name":"uanela","email":"uanelaluiswayne@gmail.com"},"repository":{"url":"git+https://github.com/uanela/arkos.git","type":"git"},"_npmVersion":"10.9.8","description":"Framework-agnostic WebSocket client for Arkos Gateway","directories":{},"_nodeVersion":"22.22.3","dependencies":{"socket.io-client":"^4.7.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^6.0.3"},"peerDependencies":{"socket.io-client":"^4.7.0"},"_npmOperationalInternal":{"tmp":"tmp/websockets-client_0.1.0-canary.1_1779982048859_0.28367886641615736","host":"s3://npm-registry-packages-npm-production"}},"0.1.0-canary.2":{"name":"@arkosjs/websockets-client","version":"0.1.0-canary.2","author":{"name":"Uanela Como"},"license":"MIT","_id":"@arkosjs/websockets-client@0.1.0-canary.2","maintainers":[{"name":"uanela","email":"uanelaluiswayne@gmail.com"}],"homepage":"https://www.arkosjs.com","bugs":{"url":"https://github.com/uanela/arkos/issues"},"dist":{"shasum":"cd264a21a4bcefe22bdcf475d55634dd8eff2e24","tarball":"https://registry.npmjs.org/@arkosjs/websockets-client/-/websockets-client-0.1.0-canary.2.tgz","fileCount":20,"integrity":"sha512-2uwrr+b8jq2oZhjX5lX9h2zvfW4Igbz7nmW42Fy+0LNrGQKOkIUtgon8kzY94LQE/R9DS0kn39O8A+EHwfUyPA==","signatures":[{"sig":"MEYCIQD9j5vnehptdiH62RND/ejxWVA/ts8TQqkGlP3nrq4/+wIhAMn2Q6L9fFXr5JVj/vlbe5g66nortGWL66Jj6OU2UGI0","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":36453},"main":"dist/exports/index.js","types":"dist/exports/index.d.ts","module":"dist/exports/index.js","gitHead":"aeabbdefbcf8a82afe8000607ae2698ecb2ad3f5","scripts":{"build":"rm -r ./dist && tsc","typecheck":"tsc --noEmit","prepublishOnly":"pnpm build"},"_npmUser":{"name":"uanela","email":"uanelaluiswayne@gmail.com"},"repository":{"url":"git+https://github.com/uanela/arkos.git","type":"git"},"_npmVersion":"10.9.8","description":"Framework-agnostic WebSocket client for Arkos Gateway","directories":{},"_nodeVersion":"22.22.3","dependencies":{"socket.io-client":"^4.7.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^6.0.3"},"peerDependencies":{"socket.io-client":"^4.7.0"},"_npmOperationalInternal":{"tmp":"tmp/websockets-client_0.1.0-canary.2_1779992548458_0.8014289915740154","host":"s3://npm-registry-packages-npm-production"}},"0.1.0-canary.3":{"name":"@arkosjs/websockets-client","version":"0.1.0-canary.3","author":{"name":"Uanela Como"},"license":"MIT","_id":"@arkosjs/websockets-client@0.1.0-canary.3","maintainers":[{"name":"uanela","email":"uanelaluiswayne@gmail.com"}],"homepage":"https://www.arkosjs.com","bugs":{"url":"https://github.com/uanela/arkos/issues"},"dist":{"shasum":"62b4514aa3696803cbd401c0f583f3adcd088d1b","tarball":"https://registry.npmjs.org/@arkosjs/websockets-client/-/websockets-client-0.1.0-canary.3.tgz","fileCount":23,"integrity":"sha512-A5SLMicJ8QjEiEfmOb1VECLqX4MeKAh/JF/m436wILCtdZW0zh40E4TrUlYT4b1nrLF06KRPXnilTUvrrh2oJg==","signatures":[{"sig":"MEYCIQCbKBKIFPlhbVcVFex4kswa0pbOpsFNhpCNeTlrvBRvJgIhANKY2fgDwlS0jJQTN1MZEH1s+JZ4pAZy536AYLT7OTPc","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":38770},"main":"dist/exports/index.js","types":"dist/exports/index.d.ts","module":"dist/exports/index.js","gitHead":"3ee835a08012df97e6ee33fbddc9500c0169d501","scripts":{"build":"rm -r ./dist && tsc","typecheck":"tsc --noEmit","prepublishOnly":"pnpm build"},"_npmUser":{"name":"uanela","email":"uanelaluiswayne@gmail.com"},"repository":{"url":"git+https://github.com/uanela/arkos.git","type":"git"},"_npmVersion":"11.16.0","description":"Framework-agnostic WebSocket client for Arkos Gateway","directories":{},"_nodeVersion":"22.22.3","dependencies":{"socket.io-client":"^4.7.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^6.0.3"},"peerDependencies":{"socket.io-client":"^4.7.0"},"_npmOperationalInternal":{"tmp":"tmp/websockets-client_0.1.0-canary.3_1780098819245_0.3790638423244528","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@arkosjs/websockets-client","version":"0.2.0","description":"Framework-agnostic WebSocket client for Arkos Gateway","main":"dist/exports/index.js","module":"dist/exports/index.js","types":"dist/exports/index.d.ts","author":{"name":"Uanela Como"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/uanela/arkos.git"},"bugs":{"url":"https://github.com/uanela/arkos/issues"},"homepage":"https://www.arkosjs.com","scripts":{"build":"rm -r ./dist && tsc && tsx script/post-build.ts","prepublishOnly":"pnpm build","typecheck":"tsc --noEmit"},"dependencies":{"socket.io-client":"^4.7.0"},"devDependencies":{"typescript":"^6.0.3"},"peerDependencies":{"socket.io-client":"^4.7.0"},"gitHead":"b2ec362f0e7825bf942af7329b28e8c1c46e6065","_id":"@arkosjs/websockets-client@0.2.0","_nodeVersion":"24.18.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-ZSJiV0+BT15nft7zzyvsOuSLwXgBLytQQ8v5sOAGsW3l0PyoI9kTq4PXZ0uuK+UrFOm9+U67tUVdUIMbXLltsw==","shasum":"37187a3e7b8a7c8e7b8c1ab8a474cd31dc671b17","tarball":"https://registry.npmjs.org/@arkosjs/websockets-client/-/websockets-client-0.2.0.tgz","fileCount":23,"unpackedSize":40091,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCMpAbn+LbJj/L6ny3LdbMwuCRD9SYf/Bu2zi32TXu8PQIhAMf/sJArG2A++Yo9NO66ebatkBPbqDJvJ5fF/mKUcH0+"}]},"_npmUser":{"name":"uanela","email":"uanelaluiswayne@gmail.com"},"directories":{},"maintainers":[{"name":"uanela","email":"uanelaluiswayne@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/websockets-client_0.2.0_1785839269466_0.8014489332972419"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-28T15:26:05.817Z","modified":"2026-08-04T10:27:49.886Z","0.1.0-canary":"2026-05-28T15:26:06.412Z","0.1.0-canary.1":"2026-05-28T15:27:29.026Z","0.1.0-canary.2":"2026-05-28T18:22:28.611Z","0.1.0-canary.3":"2026-05-29T23:53:39.384Z","0.2.0":"2026-08-04T10:27:49.600Z"},"bugs":{"url":"https://github.com/uanela/arkos/issues"},"author":{"name":"Uanela Como"},"license":"MIT","homepage":"https://www.arkosjs.com","repository":{"type":"git","url":"git+https://github.com/uanela/arkos.git"},"description":"Framework-agnostic WebSocket client for Arkos Gateway","maintainers":[{"name":"uanela","email":"uanelaluiswayne@gmail.com"}],"readme":"![Header Image](https://www.arkosjs.com/img/arkos-readme-header.webp?v=4)\n\n<div align=\"center\">\n\n[![npm](https://img.shields.io/npm/v/@arkosjs/websockets-client)](https://www.npmjs.com/package/@arkosjs/websockets-client)\n![npm](https://img.shields.io/npm/dt/@arkosjs/websockets-client)\n![GitHub](https://img.shields.io/github/license/uanela/arkos)\n\n</div>\n\n<div align=\"center\">\n<h2>Framework-Agnostic WebSocket Client for Arkos Gateway</h2>\n<p>Handle real-time communication with automatic deduplication, ack/retry/timeout, and observable connection state — without framework lock-in</p>\n</div>\n\n<div align=\"center\">\n\n**[Installation](#installation)** •\n**[Quick Start](#quick-start)** •\n**[API Reference](#api-reference)** •\n**[How \\_meta Works](#how-_meta-works)** •\n**[Framework Adapters](#framework-adapters)** •\n**[Documentation](https://www.arkosjs.com/docs/core-concepts/components/gateways)** •\n**[GitHub](https://github.com/uanela/arkos)**\n\n</div>\n\n---\n\n## What is `@arkosjs/websockets-client`?\n\nThis is the **core WebSocket client** that powers all Arkos real-time features. It wraps socket.io and adds:\n\n- **Automatic `_meta` injection** — every emit gets a unique ID and timestamp for dedup/maxAge\n- **Client-side deduplication** — guards against reconnect replay and server retry storms\n- **Ack + retry + timeout** — request-response patterns with exponential backoff\n- **Observable connection state** — drive framework reactivity without framework coupling\n- **Zero framework dependencies** — works standalone or with React, Vue, Svelte, Solid, Angular\n\n## Installation\n\n```bash\nnpm install @arkosjs/websockets-client socket.io-client\n```\n\nYou'll also need `socket.io-client` as a peer dependency.\n\n## Quick Start\n\n### Create a Manager and Client\n\n```ts\nimport { Manager } from \"socket.io-client\";\nimport { createWebsocketClient } from \"@arkosjs/websockets-client\";\n\nconst manager = new Manager(\"http://localhost:3000\", {\n    auth: { token: \"your-auth-token\" },\n    reconnection: true,\n});\n\nconst client = createWebsocketClient(manager);\n```\n\n### Get a Gateway for a Namespace\n\n```ts\nconst chat = client.gateway(\"/chat\");\nconst orders = client.gateway(\"/orders\");\n```\n\nCalling `.gateway()` with the same namespace twice returns the same instance — no duplicate connections. Socket.io multiplexes all namespaces over a single TCP connection.\n\n### Listen to Events\n\n```ts\nconst off = chat.on(\"receive_message\", (data) => {\n    console.log(data);\n});\n\n// Cleanup when done\noff();\n```\n\nClient-side deduplication is applied automatically when `_meta.mid` is present — guards against reconnect replay or server retry storms.\n\n### Emit Events\n\n**Fire and forget:**\n\n```ts\nchat.emit(\"send_message\", { room: \"general\", content: \"hello\" });\n```\n\n**With acknowledgement:**\n\n```ts\nconst result = await chat.emit(\"send_message\", data, {\n    ack: true,\n    timeout: 5000,\n    retries: 3,\n});\n\nif (result.success) {\n    console.log(result.data);\n} else {\n    console.error(result.error);\n}\n```\n\nRetries with exponential backoff on timeout, capped at 5s per attempt.\n\n### Track Connection State\n\n```ts\nconst unsub = chat.subscribe({\n    onStatus: (status) => {\n        console.log(status); // \"connected\" | \"disconnected\" | \"reconnecting\" | \"connecting\"\n    },\n    onUser: (user) => {\n        console.log(user); // Populated when server emits \"authenticated\"\n    },\n});\n\n// Cleanup\nunsub();\n```\n\nOr read the current state synchronously:\n\n```ts\nchat.status; // \"connected\" | \"disconnected\" | \"reconnecting\" | \"connecting\"\nchat.user; // { id, email, ... } | null\n```\n\n---\n\n## API Reference\n\n### `createWebsocketClient(manager)`\n\nCreates a `WebsocketClient` from a socket.io `Manager`.\n\n```ts\nconst client = createWebsocketClient(manager);\n```\n\n### `client.gateway(namespace)`\n\nReturns (or lazily creates) a `GatewayClient` for the given namespace.\n\n```ts\nconst chat = client.gateway(\"/chat\");\nconst orders = client.gateway(\"/orders\");\n```\n\nSubsequent calls with the same namespace return the cached instance.\n\n### `client.destroy()`\n\nDisconnects all namespace sockets and clears the gateway map.\n\n```ts\nclient.destroy();\n```\n\n---\n\n## GatewayClient API\n\nThe object returned by `client.gateway()`. All interaction with a namespace goes through here.\n\n### `.on(event, handler)` → `() => void`\n\nListen to a server event. Returns an unsubscribe function.\n\n```ts\nconst off = chat.on(\"receive_message\", (data) => {\n    console.log(data);\n});\n\n// Cleanup\noff();\n```\n\n**Deduplication:** Client-side dedup is applied automatically when `_meta.mid` is present in the payload — it's stripped before the handler is called.\n\n### `.emit(event, data)` → `void`\n\nFire-and-forget emit. Automatically injects `_meta.mid` and `_meta.timestamp`.\n\n```ts\nchat.emit(\"send_message\", { room: \"general\", content: \"hello\" });\n```\n\n### `.emit(event, data, { ack: true, timeout?, retries? })` → `Promise<ArkosEmitResult>`\n\nEmit with acknowledgement. Returns a promise resolving to the server's ack response.\n\n```ts\nconst result = await chat.emit(\"send_message\", data, {\n    ack: true,\n    timeout: 5000, // Wait 5s before retrying (default: 5000)\n    retries: 3, // Retry up to 3 times (default: 0)\n});\n\nif (result.success) {\n    console.log(\"Data:\", result.data);\n} else {\n    console.error(\"Error:\", result.error);\n}\n```\n\nRetries use exponential backoff: 1s, 2s, 4s, capped at 5s.\n\n### `.subscribe(subscriber)` → `() => void`\n\nSubscribe to connection state changes. Used by framework adapters to drive reactivity.\n\n```ts\nconst unsub = chat.subscribe({\n    onStatus: (status) => {\n        // \"connected\" | \"disconnected\" | \"reconnecting\" | \"connecting\"\n    },\n    onUser: (user) => {\n        // Populated when server emits \"authenticated\"\n    },\n});\n\n// Cleanup\nunsub();\n```\n\n### `.status`\n\nCurrent connection status (non-reactive sync read).\n\n```ts\nif (chat.status === \"connected\") {\n    chat.emit(\"send_message\", data);\n}\n```\n\n### `.user`\n\nCurrent user object (non-reactive sync read). Populated when the server emits `\"authenticated\"` after authentication.\n\n```ts\nif (chat.user) {\n    console.log(`Connected as ${chat.user.id}`);\n}\n```\n\n### `.rawSocket`\n\nEscape hatch to the underlying socket.io `Socket` instance for advanced use cases.\n\n```ts\nchat.rawSocket.id; // Socket ID\n```\n\n### `.destroy()`\n\nRemoves all listeners and cleans up internal state. Called automatically by `client.destroy()`.\n\n```ts\nchat.destroy();\n```\n\n---\n\n## How `_meta` Works\n\nEvery `.emit()` call automatically wraps your payload with a `_meta` envelope:\n\n```ts\n// You call this\nchat.emit(\"send_message\", { room: \"general\", content: \"hello\" });\n\n// Server receives this\n{\n  room: \"general\",\n  content: \"hello\",\n  _meta: {\n    mid: \"550e8400-e29b-41d4-a716-446655440000\",  // Auto-generated UUID\n    timestamp: \"2026-01-01T00:00:00.000Z\"          // Auto-generated ISO timestamp\n  }\n}\n```\n\nThis `_meta` envelope is what [ArkosGateway](https://www.arkosjs.com/docs/core-concepts/components/gateways)'s `dedup` and `maxAge` options consume for server-side deduplication and time-based validation.\n\n**You never need to construct it manually.** On the receive side, `_meta` is stripped before your handler is called — it's internal plumbing, not your data.\n\n---\n\n## Framework Adapters\n\nThis package is the **core** used by all official Arkos framework bindings. If you're using a framework, use one of these instead:\n\n| Framework | Package                       | Status                      |\n| --------- | ----------------------------- | --------------------------- |\n| React     | `@arkosjs/react-websockets`   | ✅ Available                |\n| Svelte    | `@arkosjs/svelte-websockets`  | 🚧 Looking for contributors |\n| Vue       | `@arkosjs/vue-websockets`     | 🚧 Looking for contributors |\n| Solid     | `@arkosjs/solid-websockets`   | 🚧 Looking for contributors |\n| Angular   | `@arkosjs/angular-websockets` | 🚧 Looking for contributors |\n\nEach adapter wraps this core in your framework's reactivity primitives (hooks, stores, services, etc.).\n\n**Want to contribute a binding?** See [CONTRIBUTING_FRAMEWORK_BINDINGS.md](../../CONTRIBUTING_FRAMEWORK_BINDINGS.md).\n\n---\n\n## Peer Dependencies\n\n| Package            | Version  |\n| ------------------ | -------- |\n| `socket.io-client` | `^4.7.0` |\n\n---\n\n## Related\n\n- [ArkosGateway Documentation](https://www.arkosjs.com/docs/core-concepts/components/gateways)\n- [Contributing Framework Bindings](../../CONTRIBUTING_FRAMEWORK_BINDINGS.md)\n- [`@arkosjs/react-websockets`](../react-websockets)\n\n---\n\n## License\n\nMIT\n\n<div align=\"center\">\n\n**[Installation](#installation)** •\n**[Quick Start](#quick-start)** •\n**[API Reference](#api-reference)** •\n**[How \\_meta Works](#how-_meta-works)** •\n**[Framework Adapters](#framework-adapters)** •\n**[Documentation](https://www.arkosjs.com/docs/core-concepts/components/gateways)** •\n**[GitHub](https://github.com/uanela/arkos)**\n\nBuilt with ❤️ as part of [Arkos.js](https://arkosjs.com)\n\n_Real-time WebSocket communication, simplified._\n\n</div>\n","readmeFilename":"README.md"}