

Clients
├─ 主播(OBS/APP) ---> (RTMP/WebRTC) ---> Flow Ingress (流媒体集群 SRS/ZLMediaKit)
├─ 观众(Web/Mobile) ---> (HLS / HTTP-FLV / WebRTC) ---> CDN / Flow Origin
└─ Chat clients (WebSocket) ---> WS Cluster (Swoole/Node)
Backend Services (REST / RPC)
├─ API Gateway (Nginx / Kong)
├─ Auth Service (JWT / short tokens)
├─ Room Service (PHP/Laravel or Hyperf) <-- DB (MySQL) & Cache (Redis)
├─ Stream Controller (Hooks for on_publish/on_close)
├─ Chat Service (Swoole WS) + Redis Pub/Sub
├─ Billing/Gift Service (orders/payments)
├─ Recorder/Transcoder (FFmpeg jobs /流媒体内置)
└─ Admin/Operator UI
Storage & Infra
├─ MySQL (metadata)
├─ Redis (在线/限流/计数)
├─ Object Storage (OBS / S3 / MinIO) for recordings
├─ CDN for HLS/TS/FLV distribution
├─ Monitoring (Prometheus + Grafana)
└─ Logging (ELK / Loki)on_publish(推流开始)、on_close(推流结束)、http-flv/hls url。
ffmpeg 批量转码/合并 TS → MP4,或在流媒体服务器中直接配置录制。
stream_key。
rtmp://ingest.example.com/live/{stream_key}。
on_publish HTTP 回调到:POST /hook/on_publish(body: name=stream_key,user=...)
rooms.is_live=1、写入 streams(start_at)、触发 Kafka/Redis 通知。
GET /room/{id}/play-token → 后端生成短期 play_token(HMAC + expire)并返回。
http://origin.example.com/live/{stream_key}.flv?token=xxx 拉流;origin 校验 token(nginx-lua 或流媒体内置 hook),或 CDN 通过签名校验。
on_close 回调。
streams.stop_at,将录制文件(若有)异步触发转码任务(消息队列)。
streams.record_url。
stream_key(生成时与房间绑定),并在 on_publish 回调再校验。可加 IP 白名单/时效。
base64(roomId|exp|sig)。
-- users, rooms, streams, messages, gifts, orders
CREATE TABLE users (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(64),
password_hash VARCHAR(255),
role TINYINT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE rooms (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
owner_id BIGINT,
title VARCHAR(255),
stream_key VARCHAR(128) UNIQUE,
is_live TINYINT DEFAULT 0,
viewers_count INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE streams (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
room_id BIGINT,
start_at DATETIME,
stop_at DATETIME,
record_url VARCHAR(512),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE messages (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
room_id BIGINT,
user_id BIGINT,
type VARCHAR(32),
content TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX(room_id)
);
CREATE TABLE orders (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
user_id BIGINT,
room_id BIGINT,
gift_id INT,
amount INT,
status VARCHAR(32),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);POST /api/v1/rooms — 创建房间(返回 stream_key)
POST /api/v1/hook/on_publish — 流媒体回调(验证推流)
POST /api/v1/hook/on_close — 断流回调
GET /api/v1/rooms/{id}/play-token — 获取短期播放 token
GET /api/v1/rooms/{id} — 房间详情(is_live、hls_url)
WS /ws?token=xxx — 弹幕/聊天室连接(token 校验)
live-system/
├─ services/
│ ├─ api/ # PHP 后端 (Laravel/Hyperf)
│ │ ├─ app/
│ │ ├─ routes/
│ │ ├─ tests/
│ │ └─ Dockerfile
│ ├─ ws/ # WebSocket 服务 (Swoole or Node)
│ │ └─ ...
│ ├─ streamer-hooks/ # Hook handlers for on_publish/on_close
│ └─ worker/ # 转码、录制后处理 worker
├─ infra/
│ ├─ srs/ # srs conf / docker-compose for local dev
│ ├─ nginx/ # nginx conf including lua token verify
│ └─ k8s/ # helm charts / manifests
├─ docs/
│ ├─ architecture.md
│ └─ runbook.md
├─ scripts/
│ └─ deploy.sh
└─ docker-compose.ymlffmpeg + 并发脚本模拟 N 个推流/观众连接;测带宽、CPU、延迟与错误率。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。