How wxn0brp/gloveslink works
Project type and purpose
• This is an open-source WebSocket communication library (“GlovesLink”) that provides both a client API and a server API for real-time, room-based messaging with built-in reconnection, authentication, and logging.
• It is not a full-stack application but rather a toolkit to be embedded into other applications (e.g., a Node.js/FalconFrame HTTP server or a browser/Node.js client).
File structure
• Top-level files:
• package.json, tsconfig.json, build.js → build/configuration
• src/adapter/browser.ts & node.ts → environment-specific WebSocket adapters
• src/client.ts → entry point for the client library
• src/server/index.ts, room.ts, socket.ts, types.ts → server core modules
• .github/workflows/build.yml → CI/CD pipeline
• sugilite.json → custom build/publish settings
• README.md → usage, API docs, architecture hints
README for additional insights
• Server integrates with an external HTTP framework (FalconFrame) to piggy-back on its HTTP server.
• Client and server both manage rooms and event emission callbacks.
• Authentication is pluggable via an authFn.
• Logging is optional.
Main components and their relationships
a. Components:
• Client Module (GlovesLinkClient)
– Connection Manager (with reconnection logic)
– Adapter Layer (browser.ts or node.ts provides WebSocket implementation)
– Event Emitter/Handler API
– Room Manager (join/leave rooms)
• Server Module (GlovesLinkServer)
– HTTP Server (FalconFrame or any Node http.Server)
– WebSocket Server (built on adapter/node.ts)
– Authentication Layer (authFn)
– Socket Manager (wraps each connection into GLSocket)
– Room Manager (broadcast to rooms)
– Logging Module
• External HTTP Framework (FalconFrame)
• External Authentication Service (optional, via authFn)
b. Interactions:
• Client opens WebSocket to Server’s HTTP endpoint → Adapter connects
• Server performs authFn(headers, token) → accept/deny
• On success, server registers socket in Room Manager
• Client emits events → travels over WebSocket → Server dispatches to appropriate handlers
• Server emits responses → travels back → Client invokes callbacks
• Automatic reconnect: Client’s Connection Manager retries on disconnect
• Rooms: Both Client and Server maintain membership lists
c. Architectural patterns and design principles:
• Adapter Pattern: Separates environment-specific WebSocket implementations
• Event-Driven Architecture: All communication via emit/on handlers
• Dependency Injection: authFn, HTTP server are injected at instantiation
• Modularization: Clear separation of concerns—connection logic, auth, room management, logging
d. Key technologies and libraries:
• TypeScript for type safety
• Node.js http.Server and optional FalconFrame
• Native WebSocket in browsers and ws library in Node (implied by adapter)
• Yarn/NPM for packaging
Detailed elements
• Component names (exact filenames or class names)
• Interfaces between components (method calls, event names)
• Data flow direction (→ or ⇄)
• Internal library modules
• Host/third-party frameworks
• External services