How apirtc/react-lib works
Project type and purpose
• This is a React component/library project (“@apirtc/react-lib”) that provides a set of React hooks and a UI component (VideoStream) to simplify integration with the ApiRTC real-time communication SDK.
• It is intended to be consumed as a peer‐dependency by any React application needing conferencing, media stream management, presence, conversations, messaging, moderation, etc.
File structure
• Top-level configuration and metadata:
• .eslintrc.json, jest.config.js, rollup.config.js, tsconfig.json, package.json, sonar-project.properties
• CHANGELOG.md, LICENSE, README.md
• docs/: Static documentation generated for functions (hooks) and types.
• src/: TypeScript source, split into
• src/hooks/: each hook in its own file plus associated tests (.spec.ts)
• src/components/: VideoStream component with entry index.ts
• src/index.ts: public export surface.
• Build and packaging: Rollup config compiles TS into ESM/CJS bundles, tests run via Jest.
Key insights from README
• Lists each hook’s purpose and usage (useSession, useUserMediaDevices, useCameraStream, useStreamApplyAudioProcessor, etc.)
• Mentions VideoStream UI component.
• Describes dependency on @apirtc/apirtc SDK and how hooks wrap SDK calls.
Main components
a. React-Lib Module
– Hooks layer (each useXxx hook)
– UI component layer (VideoStream)
– Core export index (public API surface)
b. External Dependencies
– @apirtc/apirtc SDK (peer dependency)
– Browser Web APIs (MediaDevices, getDisplayMedia)
c. Consumer Application
– Host React app importing @apirtc/react-lib, providing apiKey credentials, rendering UI
d. ApiRTC Cloud / Signaling Servers
– Remote real-time servers accessed via @apirtc/apirtc SDK
Relationships and data flows
• The Host App calls a hook (e.g., useSession) → hook initializes ApiRTC SDK session → maintains session state.
• Hooks like useUserMediaDevices access Web MediaDevices APIs → return device lists to UI.
• Hooks like useCameraStream call session.getUserMedia() → produce a MediaStream object.
• Hook useStreamApplyAudioProcessor or useStreamApplyVideoProcessor wraps the raw MediaStream via SDK processing.
• useConversation* hooks orchestrate ApiRTC conversation creation, contact list, messaging, moderation and manage remote streams (publish/subscribe).
• VideoStream component takes a MediaStream prop (from any hook) and renders it via a <video> element.
• All SDK network traffic flows to/from ApiRTC Cloud/Servers.
Architectural patterns and design principles
• Modular, single-purpose hooks each encapsulate one piece of real-time functionality.
• Separation of concerns: hooks manage state & side-effects; components manage presentation.
• Peer-dependency injection: external SDK (@apirtc/apirtc) is not bundled, ensuring version control.
• Build pipeline: Rollup for tree-shaking, Jest for unit tests with 100% coverage.
Final advice
• Be exhaustive: include every hook group, the VideoStream component, and all interactions with the SDK and browser platform.