{"_rev":"5-300953fe5f1450a671e55bb6cfdaf50e","time":{"created":"2026-06-28T12:04:39.754Z","modified":"2026-06-28T12:04:40.336Z","1.0.0":"2026-06-23T21:19:43.419Z","1.0.1":"2026-06-28T12:04:40.101Z"},"_id":"@ananay-nag/bit-socket-node","name":"@ananay-nag/bit-socket-node","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@ananay-nag/bit-socket-node","version":"1.0.1","description":"Schema-driven binary WebSocket framework for Node.js and browsers","main":"index.js","types":"types/index.d.ts","exports":{".":{"types":"./types/index.d.ts","import":"./index.js","default":"./index.js"},"./server":{"types":"./types/server.d.ts","import":"./dist/bitsocket-server.esm.js","require":"./dist/bitsocket-server.cjs","default":"./dist/bitsocket-server.esm.js"},"./client":{"types":"./types/client.d.ts","import":"./dist/bitsocket-client.esm.js","default":"./dist/bitsocket-client.esm.js"},"./dist/bitsocket-client.esm.js":{"types":"./types/client.d.ts","import":"./dist/bitsocket-client.esm.js","default":"./dist/bitsocket-client.esm.js"},"./dist/bitsocket-server.esm.js":{"types":"./types/server.d.ts","import":"./dist/bitsocket-server.esm.js","default":"./dist/bitsocket-server.esm.js"},"./dist/bitsocket-server.cjs":{"types":"./types/server.d.ts","require":"./dist/bitsocket-server.cjs"}},"scripts":{"test":"node --test test/*.test.js","build":"rollup -c","prepublishOnly":"npm run build","pack":"npm pack","publish":"npm publish --access public"},"keywords":["websocket","binary","realtime","schema","socket","web","binary-socket"],"author":{"name":"ANANYA NAG"},"license":"ISC","type":"module","dependencies":{"@msgpack/msgpack":"^3.1.3","fflate":"^0.8.3","ws":"^8.21.0"},"devDependencies":{"@eslint/js":"^10.0.1","@rollup/plugin-commonjs":"^29.0.3","@rollup/plugin-node-resolve":"^16.0.3","eslint":"^10.5.0","globals":"^17.6.0","prettier":"^3.8.4","rollup":"^4.62.0"},"_id":"@ananay-nag/bit-socket-node@1.0.1","gitHead":"0ae6e4f3454d95aeb01b27d25462ff47e54d5aee","_nodeVersion":"22.23.0","_npmVersion":"10.9.8","dist":{"integrity":"sha512-bT0bH6Op1iG88Y7kDzXcV+v9ovqPEWvoO4tj5y0CCFKK1wueko+OUJ5t4Hw32wFITWNrwoZGi1TiXKAwr5bOfQ==","shasum":"e668a2b2ab5eb56a06e96e1ba2157be37061a787","tarball":"https://registry.npmjs.org/@ananay-nag/bit-socket-node/-/bit-socket-node-1.0.1.tgz","fileCount":12,"unpackedSize":463441,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBlTZO1s/OhcriXsIEYaGaP+1TtInr4XRTX38f+k64RzAiEA9pXrNr4KTycBssxbGAglXCYYt7Wf72jYuoRI3hngHl8="}]},"_npmUser":{"name":"ananay-nag","email":"ananaynag1994s@gmail.com"},"directories":{},"maintainers":[{"name":"ananay-nag","email":"ananaynag1994s@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/bit-socket-node_1.0.1_1782648279950_0.9452659905298422"},"_hasShrinkwrap":false}},"maintainers":[{"name":"ananay-nag","email":"ananaynag1994s@gmail.com"}],"description":"Schema-driven binary WebSocket framework for Node.js and browsers","keywords":["websocket","binary","realtime","schema","socket","web","binary-socket"],"author":{"name":"ANANYA NAG"},"license":"ISC","readme":"<div align=\"center\">\n  <h1>⚡ BitSocket</h1>\n  <p><strong>A high-performance, schema-driven, binary WebSocket framework for Node.js.</strong></p>\n  <p>BitSocket provides the developer experience of Socket.io but with <b>Protobuf-level network compression</b>. By leveraging a strict Schema Engine, BitSocket drops JSON completely, stripping keys and formatting to deliver up to an 80% reduction in network payload size.</p>\n</div>\n\n<hr />\n\n## 🚀 Why BitSocket?\n\nSocket.io is built on top of Engine.io, which means it transmits stringified JSON. If you send an array of 100 user objects, the keys `\"id\"`, `\"name\"`, and `\"email\"` are transmitted 100 times. \n\n**BitSocket completely eliminates this overhead.** \nBy defining Schemas on your server, BitSocket maps your JavaScript objects directly into strict `ArrayBuffers`. The keys are never transmitted over the network—only the pure, deeply compressed binary data.\n\n### Features\n- 🧬 **Schema Auto-Discovery**: Define your schemas on the server. The moment a client connects, the server pushes the schemas to the client during the handshake. Zero manual schema sharing required!\n- 📦 **Extreme Binary Compression**: Drops all JSON overhead resulting in 40% to 80% smaller network payloads.\n- 🔄 **Connection Multiplexing**: Share a single underlying TCP connection across multiple isolated Namespaces (e.g. `/user`, `/store`), exactly like Socket.io.\n- 👥 **Room Broadcasting**: Full support for group communication (`socket.join('room')`, `io.to('room').emit(...)`).\n- ♾️ **Recursive Data Types**: Native support for deeply nested objects and multi-dimensional arrays without losing compression.\n- 🧩 **Dynamic MsgPack Fallbacks**: Need to send an arbitrary, unpredictable JSON dictionary? Define the field as `'object'` and BitSocket seamlessly drops down to MsgPack compression for that specific field.\n\n---\n\n## 🛠️ Installation\n\n```bash\nnpm install @ananay-nag/bit-socket-node\n```\n\n---\n\n## 📖 Quick Start\n\n### 1. The Server\nDefine your schemas, attach them to a namespace, and start listening!\n\n```javascript\nimport { BitSocketServer, Schema } from '@ananay-nag/bit-socket-node';\n\nconst io = new BitSocketServer({ port: 5005 });\n\n// 1. Define strict binary schemas\nconst UserSchemas = [\n  new Schema('user:create', {\n    name: 'string',\n    age: 'uint8',\n    tags: ['string'] // Support for strict arrays!\n  }),\n  new Schema('user:created', {\n    id: 'uint32',\n    success: 'boolean',\n    metadata: 'object' // Dynamic arbitrary JSON falls back to MsgPack!\n  })\n];\n\n// 2. Attach schemas to a Namespace\nio.of('/user').schema(UserSchemas);\n\n// 3. Handle Connections\nio.of('/user').on('connection', (socket) => {\n  console.log('User connected!', socket.id);\n\n  socket.on('user:create', (payload) => {\n    console.log(\"Received:\", payload); // { name: 'Alice', age: 25, tags: ['admin'] }\n\n    // Broadcast a response to everyone in a specific room\n    socket.join('admin-room');\n    socket.to('admin-room').emit('user:created', {\n      id: 1045,\n      success: true,\n      metadata: { serverPing: 12 }\n    });\n  });\n});\n```\n\n### 2. The Client\nThe client only needs to connect. **It automatically downloads the schemas during the connection handshake!**\n\n```javascript\nimport { BitSocketClient } from '@ananay-nag/bit-socket-node';\n\n// Connect the root multiplexer\nconst root = new BitSocketClient('ws://localhost:5005');\n\n// Open the /user channel (Re-uses the existing WebSocket connection!)\nconst userClient = root.of('/user');\n\nuserClient.on('connect', () => {\n  // Emit the event using a normal JS object. \n  // BitSocket intercepts it, strips the keys, and compresses it using the downloaded Schema!\n  userClient.emit('user:create', {\n    name: \"Alice\",\n    age: 25,\n    tags: ['admin']\n  });\n});\n\nuserClient.on('user:created', (payload) => {\n  console.log(\"Success:\", payload); \n});\n```\n\n---\n\n## 🧱 Supported Schema Types\n\nBitSocket currently supports mapping your JavaScript data into the following strict memory representations:\n\n| Schema Type | JavaScript Type | Byte Size |\n|-------------|-----------------|-----------|\n| `'uint8'`   | Number          | 1 byte    |\n| `'boolean'` | Boolean         | 1 byte    |\n| `'uint16'`  | Number          | 2 bytes   |\n| `'uint32'`  | Number          | 4 bytes   |\n| `'int32'`   | Number          | 4 bytes   |\n| `'float64'` | Number          | 8 bytes   |\n| `'string'`  | String          | 4 bytes (len) + utf8 bytes |\n| `'bytes'`   | Uint8Array      | 4 bytes (len) + buffer |\n\n### Advanced Types\n- **Arrays**: Wrap a type in brackets. `['string']` or `[['uint8']]`.\n- **Nested Objects**: Define a literal object. `{ profile: { age: 'uint8' } }`.\n- **Dynamic Fallbacks**: Use `'object'`, `'array'`, or `'any'` to allow arbitrary JSON data. BitSocket will compress this specific field using MsgPack while preserving keys.\n\n---\n\n## 🌐 Multiplexing & Rooms\n\nBitSocket matches the elegant routing API of Socket.io:\n\n**Namespaces (Multiplexing)**  \nKeep logic separated without opening multiple TCP connections.\n```javascript\nconst chatNsp = root.of('/chat');\nconst gameNsp = root.of('/game');\n```\n\n**Rooms**  \nCreate isolated communication channels within a namespace.\n```javascript\n// Server Side\nsocket.join('lobby-1');\nsocket.leave('lobby-1');\n\n// Emit to everyone in the room EXCEPT the sender\nsocket.broadcast.to('lobby-1').emit('message', data);\n\n// Emit to everyone in the room INCLUDING the sender\nio.of('/chat').to('lobby-1').emit('message', data);\n```\n\n---\n\n## 📈 Performance vs Socket.io\nSee the `NETWORK_ANALYSIS.md` document for a fully quantified byte-for-byte breakdown. In summary:\n- **Single Objects**: ~40% smaller payloads.\n- **Large Arrays**: ~50% to 80% smaller payloads.\n- **Continuous Metrics**: ~60% smaller payloads.\n\nBecause network latency (I/O) is the slowest bottleneck in any real-time system, BitSocket provides lower end-to-end latency for high-frequency applications.\n\n---\n\n## 📦 Version History\n\nFor detailed features and run methods of each release, please refer to the VERSION file.\n\n- [**v1.0.0**](./VERSION_V1_0_0.md) (2026-06-23) - Initial stable release containing core BitSocket schema engine, namespace multiplexing, room broadcasting, and handshake middleware.\n- [**v1.0.1**](./VERSION_V1_0_1.md) (2026-06-23) - Initial stable release containing core BitSocket schema engine, namespace multiplexing, room broadcasting, and handshake middleware.\n\n","readmeFilename":"README.md"}