How zastrich/webrtcstream works
Project type and purpose
• This is a lightweight full-stack, real-time media application that implements a WebRTC “mesh” broadcast: one broadcaster streams video/audio to multiple watchers.
• The Node.js server (app.js) serves static pages, handles HTTPS/WebSocket signaling, and orchestrates WebRTC peer-to-peer connections.
File structure
• Top-level files:
• app.js – main server (Express + HTTPS + WebSocket signaling)
• cert.pem, key.pem – TLS certificate + key for HTTPS/WSS
• Dockerfile/.dockerignore – containerization support
• package.json/lock – Node dependencies
• public/ directory: static client assets
• broadcast.html/.js – broadcaster UI and signaling logic
• watch.html (index.html)/watch.js – watcher UI and signaling logic
• styles.css – shared styling
• Renovate, ESLint, Git files – maintenance/config, not part of runtime flow.
Extract insights from the README
• Project exposes port 4000 for HTTPS + WSS
• Two run modes: direct Node or Docker container
• No database, no external STUN/TURN configured (can note default Google STUN).
a. Main components
• HTTPS/WebSocket Signaling Server (Node.js in a Docker container)
• Broadcaster Client (browser)
• Watcher Clients (browsers) – one or many
• (Optional) STUN server for ICE (default or custom)
b. Relationships & data flow
1. Clients load static HTML/JS/CSS over HTTPS from the server.
2. Broadcaster & watchers establish a WebSocket (WSS) connection to the server for signaling.
3. Broadcaster emits “offer” via WSS → server → all watchers.
4. Watchers send “answer” via WSS → server → broadcaster.
5. Both sides exchange ICE candidates via WSS.
6. Once handshake completes, a direct P2P WebRTC media stream (video/audio) flows from broadcaster → each watcher.
c. Architectural patterns & principles
– Client-Server separation: server only handles static asset delivery and signaling, media never flows through it.
– Peer mesh: each watcher opens a separate P2P connection with the broadcaster.
– Secure communications: HTTPS + WSS over TLS.
d. Key technologies/frameworks
– Node.js + Express (HTTPS server)
– ws or socket.io (WebSocket signaling)
– WebRTC APIs in browser (RTCPeerConnection, getUserMedia)
– Docker (container image and deployment)
Critical details to capture
• TLS termination on the server (cert.pem/key.pem).
• WebSocket namespace or events (offer/answer/candidate).
• P2P mesh topology (one-to-many).