How illuspas/node-media-server works
Project Type and Purpose
• This is a specialized full-stack Node.js application: a high-performance live streaming server (Node-Media-Server v4).
• It implements RTMP/RTMPS, HTTP/HTTP2-FLV push/play, static file serving, recording to FLV, notifications, and authentication.
File Structure Analysis
• bin/ : CLI entry point and TLS cert/config files.
• src/index.js : main bootstrap.
• src/core/ : core media abstractions (avcodec, avpacket, context, logger).
• src/protocol/ : protocol parsers/serializers (AMF, FLV, RTMP).
• src/server/ : server modules for each protocol and feature (rtmp_server, http_server, notify_server, broadcast_server, record_server).
• src/session/ : per-connection session logic (RTMP, FLV, record, base).
• src/vendor/ : third-party or compiled modules.
• Configuration: package.json, Dockerfile, GitHub workflows.
README Insights
• Describes supported protocols, features, clients, and configuration options (static files, recording path).
• Emphasizes high-performance/low-latency streaming and lack of external database.
Main Components & Interactions
a. Ingest Clients
• OBS/FFmpeg → push streams via RTMP/RTMPS or HTTP-FLV to the server.
b. Protocol Layer
• RTMP Server (port 1935), HTTP/HTTP2-FLV Server (port 8000/8443)
• Uses src/protocol modules to parse incoming chunks.
c. Session Layer
• Creates a Session object for each connection (rtmp_session, flv_session).
• Manages handshakes, authentication, and lifecycle.
d. Core Processing
• src/core/context: coordinates publishers, subscribers, GOP cache.
• src/core/avpacket & avcodec: encapsulate video/audio frames.
• Logger for diagnostics.
e. Server Features
• Broadcast Server: routes packets from publisher to subscribers.
• Record Server: writes FLV files for VOD.
• Notify Server: sends callbacks on events (connect, publish, done).
• Static File Server: serves HTML/static assets and recorded FLV.
f. Clients & Playback
• Subscribers pull via RTMP or HTTP-FLV.
• NodePlayer.js/WebDemo as sample clients.
g. External Integrations
• Notification Webhooks (user-configurable URLs).
• Filesystem for static and recording storage.
Architectural Patterns & Principles
• Modular layering: protocol → session → core → feature servers.
• Event-driven, non-blocking I/O (Node.js).
• Separation of concerns: each server type in its own module.
• In-memory GOP cache for low-latency replay.