Skip to content

Live Room

The Live Room plugin (Live) provides real-time interactive live streaming capabilities for Monibuca V6. Suitable for talent shows, social live streaming, e-commerce live streaming, and other scenarios.

  • 1 Streamer + N Viewers: Support 100+ concurrent viewers, no limit on audience size
  • Real-time Interaction System:
    • Gift system & Combo support
    • Co-hosting system (Link-Mic), streamer can invite viewers to co-host
    • PK battles for real-time competition between streamers
  • Bot Viewers: Simulated viewers for testing and demonstration
  • Danmaku (Bullet Comments): Bullet comment posting, rate limiting, content filtering
  • Data Persistence: Live room information, gift records, and viewer data stored in database
  • Moderation Capabilities: Kick users, ban, chat mute, and other streamer permissions
Cargo.toml
features = ["live"]
# Live plugin depends on Room Service
# room feature is automatically enabled
graph TB
subgraph Live["LivePlugin"]
SM["SessionManager<br/>Live room info, gift system"]
GiftSys["GiftSystem<br/>Combo detection"]
LinkMic["LinkMicSystem<br/>Co-hosting request queue"]
RobotMgr["RobotManager<br/>Simulated viewers"]
DB["Data Persistence<br/>Rooms, gifts, viewers"]
end
subgraph RS["Room Service"]
Room["Room Management<br/>Streamer + Viewers"]
WS["WebSocket<br/>Signaling"]
API["RoomApi"]
end
subgraph Media["Media Layer"]
WHIP["WebRTC WHIP<br/>Publish"]
WHEP["WebRTC WHEP<br/>Subscribe"]
end
Live -->|register_callbacks| RS
SM --> DB
GiftSys --> SM
LinkMic --> SM
RobotMgr --> Room
Room --> API
API -->|broadcast_to_room<br/>add_ban, remove_user| Live
WS --> Live
WHIP --> Media
WHEP --> Media
Preparing → Living → Paused → Ended
StatusDescription
PreparingLive preparation, not yet started
LivingLive in progress, viewers can join
PausedLive paused, viewers retained, can resume later
EndedLive ended, room closed
ActionDirectionDescription
start_liveC→SStreamer starts live
stop_liveC→SStreamer ends live
pause_liveC→SStreamer pauses live
resume_liveC→SStreamer resumes live
ActionDirectionDescription
send_giftC→SViewer sends gift
gift_receivedS→CGift notification (broadcast)
ActionDirectionDescription
link_mic_requestC→SViewer requests co-hosting
link_mic_acceptC→SStreamer accepts co-hosting
link_mic_rejectC→SStreamer rejects co-hosting
link_mic_endC→SCo-hosting ends
link_mic_timeoutS→CCo-hosting invitation timeout
ActionDirectionDescription
pk_inviteC→SStreamer A invites Streamer B for PK
pk_acceptC→SStreamer B accepts PK
pk_rejectC→SStreamer B rejects PK
pk_endC→SEnd PK
pk_score_updateS→CPK score real-time update (broadcast)
ActionDirectionDescription
send_danmakuC→SSend bullet comment
danmakuS→CDanmaku notification (broadcast)
{
"action": "send_gift",
"room_id": "live_100001",
"gift_id": "rocket",
"count": 1,
"combo_id": "combo_abc123"
}

Gifts support combos. Clients use the same combo_id when sending the same gift multiple times in a short period:

// Gift 1
{
"action": "send_gift",
"gift_id": "rocket",
"count": 1,
"combo_id": "combo_xyz789"
}
// Gift 2 (same combo)
{
"action": "send_gift",
"gift_id": "rocket",
"count": 1,
"combo_id": "combo_xyz789"
}
// Server response
{
"action": "gift_received",
"gift_id": "rocket",
"combo_count": 2,
"combo_id": "combo_xyz789"
}
  • If no more gifts sent within timeout period → combo ends
  • Clients can display “×N combo” animation
  • Supports configurable maximum combo count limit
Viewer requests → Streamer accepts/rejects → Establish WebRTC connection → Co-hosting → End
{
"action": "link_mic_request",
"room_id": "live_100001"
}
{
"action": "link_mic_accept",
"room_id": "live_100001",
"target_user_id": "user_789"
}
live:
link_mic:
max_participants: 6 # Maximum co-hosting participants (including streamer)
timeout: 30 # Co-hosting invitation timeout (seconds)
auto_end_on_decline: true # Auto cleanup on decline
Streamer A invites Streamer B → Streamer B accepts/rejects → Establish PK room → Real-time scoring → End
{
"action": "pk_invite",
"target_anchor_id": "anchor_123"
}

During PK, the system calculates both sides’ scores in real-time based on:

  • Gift Contribution: Gifts sent by viewers
  • Danmaku Interaction: Number and activity of bullet comments
  • Time Coefficient: PK duration weighting
live:
pk:
enable: true # Enable PK feature
timeout: 300 # PK invitation timeout (seconds)
duration: 600 # Single PK duration (seconds)
scoring:
gift_multiplier: 1.5 # Gift contribution multiplier
danmaku_weight: 0.1 # Danmaku weight
  • Test live features: Simulate real viewer behavior
  • Demo: Increase live room activity
  • Load testing: Evaluate system capacity
{
"action": "add_robots",
"room_id": "live_100001",
"count": 50,
"behaviors": {
"gift_probability": 0.3, // 30% probability to send gift
"danmaku_probability": 0.5, // 50% probability to send danmaku
"link_mic_probability": 0.05 // 5% probability to request co-hosting
}
}
{
"action": "send_danmaku",
"content": "Great stream!"
}
  • Rate Limiting: Prevents spam
  • Content Filtering: Sensitive word filtering
  • User Levels: Different limits for VIP users
  • Auto-cleanup: Automatically delete expired danmaku
live:
danmaku:
max_per_minute: 10 # Maximum 10 per minute
max_length: 200 # Maximum length
cooldown: 2 # Minimum interval between danmaku (seconds)
Terminal window
curl -X POST http://localhost:8080/live/rooms \
-H "Content-Type: application/json" \
-d '{
"anchor_id": "anchor_001",
"title": "Tonight Show",
"cover_url": "https://example.com/cover.jpg"
}'
Terminal window
curl http://localhost:8080/live/rooms
Terminal window
curl http://localhost:8080/live/rooms/{room_id}
Terminal window
curl http://localhost:8080/live/rooms/{room_id}/gift-stats
FieldTypeDescription
idstringRoom ID
anchor_idstringStreamer ID
titlestringLive title
statusenumLive status
start_timetimestampStart time
end_timetimestampEnd time
viewer_countintViewer count
total_gift_amountdecimalTotal gift amount
FieldTypeDescription
idstringGift ID
room_idstringRoom ID
sender_idstringSender ID
gift_typestringGift type
countintCount
amountdecimalAmount
created_attimestampCreation time
live:
# Gift system
gift:
combo_timeout: 5 # Combo timeout (seconds)
max_combo_count: 999 # Maximum combo count
# Co-hosting system
link_mic:
max_participants: 6 # Maximum co-hosting participants
timeout: 30 # Invitation timeout (seconds)
# PK battle
pk:
enable: true
timeout: 300 # Invitation timeout (seconds)
duration: 600 # Battle duration (seconds)
# Danmaku system
danmaku:
max_per_minute: 10
max_length: 200
cooldown: 2
# Database
database:
enable: true # Enable persistence
table_prefix: "live_" # Table name prefix
# Bot viewers
robot:
enable: true # Enable bots
max_robots: 10000 # Maximum robots
const room = document.getElementById('room') as MbRoom;
const publisher = document.getElementById('publisher') as MbPublisher;
// Connect to live room
room.setAttribute('ws-url', 'ws://localhost:8080/room?type=live');
room.setAttribute('room-id', 'live_100001');
// Streamer publish
await publisher.startCapture({ audio: true, video: true });
await publisher.startPublish();
const room = document.getElementById('room') as MbRoom;
// Send gift
room.sendMessage({
action: 'send_gift',
gift_id: 'rocket',
count: 1,
combo_id: 'combo_123'
});
// Request co-hosting
room.sendMessage({
action: 'link_mic_request'
});
// Listen for co-hosting acceptance
room.addEventListener('link_mic_accept', (event) => {
// Establish co-hosting WebRTC connection
await publisher.startPublish();
});
// Send danmaku
room.sendMessage({
action: 'send_danmaku',
content: 'Go streamer!'
});
// Listen for danmaku
room.addEventListener('danmaku', (event) => {
console.log(`${event.username}: ${event.content}`);
});

Complete Live Room Demo is located at web-sdk/packages/demo/live/:

live/
├── src/
│ ├── pages/
│ │ ├── Lobby/index.tsx # Live room list
│ │ ├── LiveRoom/index.tsx # Live room (streamer/viewer)
│ │ └── GiftPanel/index.tsx # Gift panel
│ ├── components/
│ │ ├── Danmaku/index.tsx # Danmaku component
│ │ ├── Viewers/index.tsx # Viewer list
│ │ └── GiftEffect/index.tsx # Gift effects
│ ├── services/api.ts # API wrapper
│ └── types/index.ts # Type definitions
├── package.json # port: 5474
└── vite.config.ts
Terminal window
cd web-sdk/packages/demo/live
pnpm install
pnpm dev
# Visit http://localhost:5474
http://localhost:5474?role=anchor&anchor_id=anchor_001
http://localhost:5474?role=viewer&room_id=live_100001

Demo automatically detects device type. For mobile devices:

  • Full-screen portrait video
  • Floating danmaku bar at bottom
  • Floating gift/interaction buttons on right (safe area)
  • Swipe up to show gift panel
  • Long press to send danmaku