$ show socketio/socket.io
Socket.IO is a real-time bidirectional event-based communication library for Node.js and the browser. The repository is a monorepo containing multiple packages: the server (`socket.io`), client (`socket.io-client`), low-level transport layer (`engine.io`, `engine.io-client`), packet parsers (`engine.io-parser`, `socket.io-parser`), adapters for horizontal scaling (`socket.io-adapter`, `@socket.io/cluster-adapter`, `@socket.io/cluster-engine`), and emitters for cross-process communication (`@socket.io/postgres-emitter`, `@socket.io/redis-streams-emitter`). The architecture is layered: Engine.IO handles transport abstraction (HTTP long-polling, WebSocket, WebTransport) with upgrade mechanisms, while Socket.IO adds higher-level features like namespaces, rooms, acknowledgements, and connection state recovery. The client library provides automatic reconnection with exponential backoff, binary data support, and multiplexing across namespaces. The codebase is written in TypeScript with extensive test coverage, protocol documentation, and a rich set of examples demonstrating integration with various frameworks (React, Angular, Vue, Next.js, NestJS) and deployment patterns (clustering, load balancing, authentication).
The LLM identified 3 files worth highlighting for reuse:
A standalone, generic event emitter implementation with typed event support. It provides `on`, `once`, `off`, `emit`, `listeners`, and `hasListeners` methods. The class is used as a base for all Socket.IO and Engine.IO sockets, managers, and transports. It is fully self-contained (no internal dependencies) and can be extracted into any project requiring a robust event system.
An implementation of exponential backoff with jitter for reconnection delays. It accepts `min`, `max`, `jitter`, and `factor` parameters, and provides `duration()` to compute the next delay. The algorithm is isolated, well-documented, and reusable in any system needing retry logic with backoff.
Encodes Engine.IO packets into binary or text format, supporting strings, ArrayBuffers, Blobs, and Node.js Buffers. It handles base64 encoding for binary data in polling transports and uses a compact packet header (type + optional length). The module is self-contained (depends only on `commons.ts` for packet types) and demonstrates careful handling of binary data across environments.