How shinyoshiaki/node-sfu works
Project type and purpose
• This is a full‐stack monorepo for a real‐time communications SDK and demo.
• Core functionality (packages/core, packages/json-rpc, packages/utils) implements pub/sub, data/media publication, fragmentation/compression, and JSON-RPC transport.
• packages/client is an SDK wrapper around core for application code.
• packages/conference is a React+Tailwind demo web app that uses the SDK to run multi‐party video, audio, and chat.
• packages/reference-server is a lightweight JSON-RPC server for signaling.
• packages/e2e and packages/conference/e2e hold end‐to‐end tests.
• A werift submodule provides pure‐JS WebRTC stack.
Main components
A. Frontend Application
– packages/conference (React UI, hooks, components, ConferenceLayout, ChatPanel, VideoGrid)
– uses the client SDK for data/media operations.
B. Client SDK
– packages/client (connectionManager, publisher/subscriber, data/mediaPublication/subscription)
– depends on JSON-RPC adapter and core logic.
C. Core Library
– packages/core (room/member abstractions, data/media pub/sub implementations)
– imports werift adapter for WebRTC, JSON-RPC transport shim, util modules.
D. JSON-RPC Module
– packages/json-rpc (jsonrpc.ts, transport.ts, types) used by both core and client to encode/decode messages over WebSocket or other transports.
E. Utilities
– packages/utils (fragmentation, compression) for splitting large data frames.
F. Reference Signaling Server
– packages/reference-server (main.ts) provides a JSON-RPC over WebSocket endpoint, routes messages between members in the same room.
G. Subsystems & Tests
– Submodule werift for WebRTC peer connection stack.
– packages/e2e and conference/e2e to drive end‐to‐end scenarios via Playwright or Vitest.
Relationships & Data flows
• UI events in the conference app → client SDK APIs (publisher.publishData(), subscriber.subscribeMedia(), etc.)
• SDK invokes JSON-RPC transport → connects to reference-server over WebSocket → server forwards messages to peers.
• Core uses werift to establish WebRTC peer connections for media/data channels.
• Utils (fragmentation/compression) used by SDK for large‐payload handling.
• Peer‐to‐peer channels carry data/media after signaling.
Architectural patterns & principles
• Monorepo + packages: clear separation of concerns (core logic, protocol, SDK, demo, server, tests).
• Pub/Sub pattern for both data and media publication/subscription.
• Adapter pattern: JSON-RPC adapter, werift adapter.
• Layered design: UI → SDK → Core/Protocol → Transport → Network.