{"_id":"@benjamin0mar/openws-client","_rev":"2-afbc2f7f229f72e6570e93b17fa04ec6","name":"@benjamin0mar/openws-client","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@benjamin0mar/openws-client","version":"0.1.0","keywords":["websocket","ws","rust","openws","client","javascript","typescript","realtime","socket"],"author":"","license":"CC-BY-NC-4.0","_id":"@benjamin0mar/openws-client@0.1.0","maintainers":[{"name":"benjamin0mar","email":"benjaminomar34@gmail.com"}],"homepage":"https://github.com/benjamin0mar/openws-client-js#readme","bugs":{"url":"https://github.com/benjamin0mar/openws-client-js/issues"},"dist":{"shasum":"c49101ca971160a9aebbbc0c96891088280dd8df","tarball":"https://registry.npmjs.org/@benjamin0mar/openws-client/-/openws-client-0.1.0.tgz","fileCount":15,"integrity":"sha512-Lp2srDTJ+k0UB21VavL15kMEKqWTs3BHKNnDPeFb8VV/RPKzi+5jo1bqn+UrPIcDEsqKW4x2nBeCKuOOsSb0pQ==","signatures":[{"sig":"MEYCIQDRIC1Mblnmxv9FjuCU8G+wy8nEmncZzQxv6tpo0MHoMAIhALo6UVupR8A/oB7WpAMGKfdcuCfK5bjf8r5eeV7n6BSG","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24596},"main":"./dist/openws-client.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/openws-client.js","exports":{".":{"import":"./dist/openws-client.js","require":"./dist/openws-client.cjs"}},"gitHead":"891cab1a10554f899c1a06f92399c39c2289ea0f","private":false,"scripts":{"dev":"vite","test":"vitest run","build":"vite build && tsc","preview":"vite preview","typecheck":"tsc --noEmit","test:watch":"vitest"},"_npmUser":{"name":"benjamin0mar","email":"benjaminomar34@gmail.com"},"repository":{"url":"git+https://github.com/benjamin0mar/openws-client-js.git","type":"git"},"_npmVersion":"10.8.2","description":"[![npm](https://img.shields.io/npm/v/@benjamin0mar%2Fopenws-client)](https://www.npmjs.com/package/@benjamin0mar/openws-client)","directories":{},"_nodeVersion":"20.20.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^5.4.0","vitest":"^1.6.0","typescript":"^5.4.0"},"_npmOperationalInternal":{"tmp":"tmp/openws-client_0.1.0_1783400954514_0.2855268119073222","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@benjamin0mar/openws-client","version":"0.1.1","private":false,"type":"module","main":"./dist/openws-client.cjs","module":"./dist/openws-client.js","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/openws-client.js","require":"./dist/openws-client.cjs"}},"publishConfig":{"access":"public"},"license":"CC-BY-NC-4.0","author":"","repository":{"type":"git","url":"git+https://github.com/benjamin0mar/openws-client-js.git"},"bugs":{"url":"https://github.com/benjamin0mar/openws-client-js/issues"},"homepage":"https://github.com/benjamin0mar/openws-client-js#readme","scripts":{"dev":"vite","build":"vite build && tsc","preview":"vite preview","test":"vitest run","test:watch":"vitest","typecheck":"tsc --noEmit"},"devDependencies":{"typescript":"^5.4.0","vite":"^5.4.0","vitest":"^1.6.0"},"keywords":["websocket","ws","rust","openws","client","javascript","typescript","realtime","socket"],"_id":"@benjamin0mar/openws-client@0.1.1","gitHead":"0408794d0bbcc89c4d54d207c7a706e93e655d00","description":"[![npm](https://img.shields.io/npm/v/@benjamin0mar%2Fopenws-client)](https://www.npmjs.com/package/@benjamin0mar/openws-client)","_nodeVersion":"20.20.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-ek6xrJQB06HuOjlZGV2IDwfHYKoja54P9bGjB87WDS/VXbuZIZ384OetWFsGL/EWSWN7jDKLIQYIdyjcItD++Q==","shasum":"ff5fffb24af3548208f4b24770e8b4134697ce7f","tarball":"https://registry.npmjs.org/@benjamin0mar/openws-client/-/openws-client-0.1.1.tgz","fileCount":15,"unpackedSize":24582,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC2k/YzVlQ3wldQwexc5lWt3HKpxwrcKQyXxVCnB1IXNAIgMNJqjb+8/XwSDyMzCANtq17fy4zZ7Z2mG8q+pB/cQwQ="}]},"_npmUser":{"name":"benjamin0mar","email":"benjaminomar34@gmail.com"},"directories":{},"maintainers":[{"name":"benjamin0mar","email":"benjaminomar34@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/openws-client_0.1.1_1783465588682_0.5476089389611625"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-07T05:09:14.348Z","modified":"2026-07-07T23:06:29.008Z","0.1.0":"2026-07-07T05:09:14.640Z","0.1.1":"2026-07-07T23:06:28.835Z"},"bugs":{"url":"https://github.com/benjamin0mar/openws-client-js/issues"},"license":"CC-BY-NC-4.0","homepage":"https://github.com/benjamin0mar/openws-client-js#readme","keywords":["websocket","ws","rust","openws","client","javascript","typescript","realtime","socket"],"repository":{"type":"git","url":"git+https://github.com/benjamin0mar/openws-client-js.git"},"description":"[![npm](https://img.shields.io/npm/v/@benjamin0mar%2Fopenws-client)](https://www.npmjs.com/package/@benjamin0mar/openws-client)","maintainers":[{"name":"benjamin0mar","email":"benjaminomar34@gmail.com"}],"readme":"# openws-client\n\n[![npm](https://img.shields.io/npm/v/@benjamin0mar%2Fopenws-client)](https://www.npmjs.com/package/@benjamin0mar/openws-client)\n\nCliente WebSocket oficial en TypeScript para [**openws-server**](https://github.com/benjamin0mar/openws-server) (Rust). 0 dependencias externas.\n\n```ts\nimport { createChat } from '@benjamin0mar/openws-client'\n\nconst chat = await createChat('ws://localhost:3000/ws', {\n  username: 'alice',\n  room:     'general',\n})\n\nchat.onMessage((msg) => console.log(`${msg.from}: ${msg.text}`))\nchat.send('hola a todos!')\n```\n\n## Instalar\n\n```bash\nnpm install @benjamin0mar/openws-client\n```\n\nNecesitas el servidor Rust corriendo: [`openws-server`](https://github.com/benjamin0mar/openws-server).\n\n## API\n\n### `createChat(url, options)` → `Promise<Chat>`\n\n```ts\nconst chat = await createChat('ws://localhost:3000/ws', {\n  username: 'alice',   // requerido\n  room:     'general', // requerido\n  timeout:  5000,      // ms para el join — default: 5000\n  reconnect: true,     // default: true\n})\n```\n\n### Chat\n\n| Método | Descripción |\n|--------|-------------|\n| `send(text)` | Envía mensaje a la sala. Encola si no hay conexión. |\n| `sendTo(username, text)` | Mensaje privado. |\n| `join(room)` | Cambia de sala. Resuelve cuando el servidor confirma. |\n| `onMessage(fn)` | `{ from, text, at, room }` |\n| `onPrivate(fn)` | `{ from, text }` |\n| `onJoin(fn)` | `{ username, room }` — alguien entró |\n| `onLeave(fn)` | `{ username, room }` — alguien salió |\n| `onStatus(fn)` | `'connecting' \\| 'open' \\| 'reconnecting' \\| 'closed'` |\n| `close()` | Desconecta limpiamente. No reconecta. |\n\n### `WsClient` (acceso crudo)\n\n```ts\nimport { WsClient } from '@benjamin0mar/openws-client'\n\nconst client = new WsClient('ws://localhost:3000/ws', {\n  reconnect:    true,\n  maxRetries:   5,\n  pingInterval: 30_000,\n})\n\nclient.on('message', (raw) => { /* JSON crudo del servidor */ })\nclient.on('open',    ()    => { /* conectado */ })\nclient.on('close',   ()    => { /* desconectado */ })\nclient.send({ type: 'join', room: 'general', username: 'alice' })\nclient.close()\n```\n\n## Demo\n\n```bash\nnpm run dev\n```\n\nAbre `http://localhost:5173` en varias pestañas para probar el chat en tiempo real.\n\n## Benchmark\n\n```bash\nnpm run dev\n```\n\nVisita `http://localhost:5173/benchmark.html` para medir latencia con múltiples conexiones simultáneas.\n\n## Servidor\n\nEste cliente está diseñado para [`openws-server`](https://github.com/benjamin0mar/openws-server), un servidor WebSocket escrito en Rust.\n\n### Instalar el servidor\n\n```bash\ncargo install openws-server\n```\n\n### O ejecutarlo desde el repositorio\n\n```bash\ngit clone https://github.com/benjamin0mar/openws-server\ncd openws-server\ncargo run\n```\n\nTambién es compatible con cualquier otro servidor WebSocket que implemente el mismo [protocolo JSON](#protocolo).\n\n## Protocolo\n\nVer [`src/lib/types.ts`](src/lib/types.ts) para la definición completa de tipos de mensajes.\n\n## Licencia\n\nCreative Commons Attribution-NonCommercial 4.0 International\n","readmeFilename":"README.md"}