How esonwong/network-rc works
Project type and purpose
• This is a full-stack IoT control system for a remote-control car based on Raspberry Pi.
• The front-end is a React SPA (in front-end/) that offers UI for video streaming, controls, settings, voice chat, etc.
• The back-end is a Node.js server (root index.js + lib/) running on the Pi, exposing HTTP/WebSocket endpoints, managing WebRTC, GPIO channels, cameras, audio and TTS.
File structure
• Top level:
• index.js: server entrypoint
• lib/: back-end modules (AudioServer, CameraServer, MicrophoneServer, WebRTC, GPIO drivers, TTS, session, stream, updater, etc.)
• front-end/: React app with components, Redux store, WebRTC helper, static assets
• deploy.js + install.sh: deployment scripts
• test/: unit tests for hardware modules
• Patterns & technologies:
• MVC-style separation: front-end (V) ↔ server routes & WebSocket handlers (C) ↔ hardware modules (M)
• WebRTC for real-time audio/video
• WebSocket (via @clusterws/cws) for signaling and control messages
• FFmpeg & Pulseaudio for media handling
• GPIO libraries (rpio, rpio-pwm) for channel control
• FRP for tunneling traffic over 4G/5G
README for insights
• Purpose: low-latency remote control with video, multi-camera, multi-channel PWM, voice, audio playback, auto server/RTC switch.
• Dependencies: ffmpeg, pulseaudio, Node.js.
• Deployment: single-node on Raspberry Pi, expose HTTP at port 8080, optional FRP server externally.
a. Components:
1. Front-end React SPA (Browser)
2. Node.js Control Server
• HTTP Server (static assets, REST APIs)
• WebSocket / signaling server
• WebRTC media gateway
• Hardware Controllers:
– CameraServer (spawns FFmpeg, streams video)
– AudioServer & MicrophoneServer (Pulseaudio)
– GPIO Controller (27 PWM channels, rpio)
– TTS Engine
3. Raspberry Pi hardware
• Cameras, microphones, speakers, motors/servos (GPIO)
4. External services (optional)
• FRP tunnel server (for NAT traversal)
• STUN/TURN (if used)
• Remote WebRTC peers (gamepad/keyboard clients)
b. Relationships & data flow:
• Browser ↔ HTTP ➔ Control Server (serves UI, config APIs)
• Browser ↔ WebSocket ➔ Control Server (control commands, channel updates, status)
• Browser ↔ WebRTC ➔ Control Server ↔ hardware media modules ➔ camera/audio hardware
• Control Server ↔ GPIO libs ➔ motor controllers
• Control Server ↔ TTS module ➔ speaker hardware
• Control Server ↔ FRP (outgoing connection to public server)
c. Architectural patterns:
• Component-based front-end + central Signal & Media Gateway on back-end
• Adapter pattern for hardware abstraction (CameraServer, AudioServer, GPIO)
• Pub/Sub or EventEmitter for inter-module messaging (session, stream, status)
d. Key technologies/frameworks:
• React, Redux (front-end)
• Node.js, @clusterws/cws, ws-avc-player
• FFmpeg, Pulseaudio
• WebRTC (native, via wrtc library)
• rpio, rpio-pwm (GPIO)
• FRP (remote port forwarding)
Detail without over-splitting
• Key modules and their groupings
• Event/control flows and media flows separately for clarity
• Hardware pins/channels if critical