Skip to content

Room System

The Monibuca V6 room system consists of four parts:

  1. Room Service (engine built-in) — Provides core room lifecycle management
  2. Live Plugin — Live room extension features
  3. Meeting Plugin — Meeting room extension features
  4. CustomerService Plugin — 1v1 customer service call features
# Enable Room Service (required)
# The room feature is enabled via conditional compilation in Cargo.toml
# Enable Live Room plugin
features = ["live"]
# Enable Meeting Room plugin
features = ["meeting"]
# Enable Customer Service plugin
features = ["customer-service"]
# Enable all at once
features = ["live", "meeting", "customer-service"]
graph TB
subgraph RS["Room Service (Engine Built-in)"]
Core["Room create/destroy/join/leave<br/>WebSocket/heartbeat/auth/reporting"]
API["RoomApi trait + ExtensionManager<br/>Plugins register RoomCallbacks async callbacks<br/>Plugin operations: broadcast/lock/mute/kick/ban/lobby"]
end
subgraph Plugins["Plugin Extensions"]
Live["LiveExtension (Live Room)<br/>manages_own_sessions: true"]
Meeting["MeetingExtension (Meeting Room)<br/>manages_own_sessions: false"]
end
Core --> API
API --> Live
API --> Meeting
API --> CS["CustomerServiceExtension (Customer Service)<br/>manages_own_sessions: true<br/>max_users: 2"]
Live -->|"room_api.broadcast_to_room()<br/>room_api.add_ban()<br/>room_api.remove_user()"| RS
Meeting -->|"room_api.set_room_locked()<br/>room_api.set_lobby_enabled()<br/>room_api.admit_user()"| RS
CS -->|"room_api.broadcast_to_room()<br/>room_api.remove_user()"| RS
  • Room creation, joining, leaving, and destruction
  • User management and authentication (external HTTP verification)
  • WebSocket connection management and real-time signaling
  • Heartbeat detection (auto-kick on timeout)
  • Chat rate limiting
  • Behavior reporting and statistics

RoomApi — The Sole Contract Between Plugins and Engine

Section titled “RoomApi — The Sole Contract Between Plugins and Engine”

Plugins obtain Arc<dyn RoomApi> via EngineContext.room_api() for:

Registering callbacks (during init()):

  • register_callbacks(RoomType::Live, RoomCallbacks { ... })
  • Callbacks are invoked asynchronously by the engine when room lifecycle events occur

Operating on rooms (in callbacks or HTTP handlers):

  • broadcast_to_room() — Broadcast messages
  • set_room_locked() / set_room_recording() — Room state
  • remove_user() — Kick user
  • add_ban() / remove_ban() — Ban management
  • add_chat_mute() / remove_chat_mute() — Chat mute
  • set_lobby_enabled() / admit_user() / reject_user() — Lobby (waiting room)

Clients connect to the Room Service via WebSocket for real-time signaling communication:

ws://host:port/room/{room_id}?token={auth_token}

WebSocket messages use JSON format, differentiated by the action field:

{
"action": "join_room",
"room_id": "100001",
"user_id": "user_001",
"user_name": "John"
}
ActionDirectionDescription
join_roomC→SJoin room
leave_roomC→SLeave room
heartbeatC→SHeartbeat keepalive
chatC→SChat message (broadcast after rate limiting)
actionC→SPermission operations (lock, record, kick, etc.)
media_stateC→SUpdate media state
user_joinedS→CA user has joined the room
user_leftS→CA user has left the room
room_closedS→CRoom has been closed
errorS→CError notification

Unmatched message types are forwarded to the ExtensionManager, where they are handled by plugin-registered on_message callbacks.

sequenceDiagram
participant C as Client
participant H as RoomWsHandler
participant RS as RoomService
participant EM as ExtensionManager
participant Ext as Plugin Extension
C->>H: ws: { action, room_id, ... }
alt action = "join"
H->>RS: verify_user()
RS-->>H: ok
H->>RS: Room.add_user()
H->>EM: on_user_join callback
else action = "leave"
H->>EM: on_user_leave callback
H->>RS: Room.remove_user()
else action = "chat"
H->>RS: rate_limit → Room.broadcast_text()
else action = "action"
H->>H: permission check → ActionExecutor
else other (custom)
H->>EM: on_message callback
EM->>Ext: plugin parses as LiveEvent / MeetingEvent
end

The Live plugin provides rich interactive features for live streaming scenarios. For comprehensive documentation, see Live Room Plugin.

  • Live room lifecycle: Preparing → Living → Paused → Ended
  • Co-hosting system: Supports host-audience interactive co-hosting
  • Gift system: Gift sending with combo support, broadcast via RoomApi.broadcast_to_room()
  • PK battles: Host-vs-host PK battle functionality
  • Bot viewers: Simulated viewers (for testing)
  • Data persistence: Live room data stored in database
  • Moderation capabilities: Kick, ban, and chat mute via RoomApi
ActionDirectionDescription
start_liveC→SStart live stream
stop_liveC→SEnd live stream
pause_liveC→SPause live stream
resume_liveC→SResume live stream
send_giftC→SSend gift
gift_receivedS→CGift notification (broadcast)
send_danmakuC→SSend bullet comment
link_mic_requestC→SRequest co-hosting
link_mic_acceptC→SAccept co-hosting
link_mic_rejectC→SReject co-hosting
link_mic_endC→SEnd co-hosting
pk_inviteC→SSend PK invitation
pk_acceptC→SAccept PK
pk_endC→SEnd PK
live:
gift:
combo_timeout: 5 # Combo timeout (seconds)
max_combo_count: 999 # Maximum combo count
link_mic:
max_participants: 6 # Maximum co-hosting participants
timeout: 30 # Co-hosting invitation timeout (seconds)

The Meeting plugin provides comprehensive meeting management features for video conferencing scenarios. For comprehensive documentation, see Meeting Room Plugin.

  • Agenda management: Meeting agenda creation and control
  • Timer: Meeting and speaking timers
  • Real-time transcription: Speech-to-text (requires external ASR service)
  • AI meeting summary: Automatic meeting minutes generation
  • Task extraction: Extract action items from meeting content
  • Recording control: Control recording via RoomApi.set_room_recording()
  • Lobby (waiting room): Managed via RoomApi.set_lobby_enabled() + admit_user() / reject_user()
ActionDirectionDescription
start_meetingC→SStart meeting
end_meetingC→SEnd meeting
mute_participantC→SMute participant (via RoomApi)
unmute_participantC→SUnmute participant
kick_participantC→SKick participant (via RoomApi)
raise_handC→SRaise hand
lower_handC→SLower hand
start_recordingC→SStart recording (via RoomApi)
stop_recordingC→SStop recording
start_transcriptionC→SStart transcription
share_screenC→SShare screen
lock_roomC→SLock/unlock room (via RoomApi)
toggle_lobbyC→SToggle lobby (via RoomApi)
admit_userC→SAdmit user (via RoomApi)
reject_userC→SReject user (via RoomApi)
ban_userC→SBan user (via RoomApi)
participant_mutedS→CParticipant muted notification
participant_kickedS→CParticipant kicked notification
transcription_resultS→CTranscription result push
meeting:
max_participants: 50 # Maximum number of participants
enable_lobby: true # Enable lobby (waiting room)
enable_recording: true # Allow recording
enable_transcription: false # Enable transcription
timer:
max_duration: 7200 # Maximum meeting duration (seconds)
warning_before_end: 300 # Warning N seconds before end

The CustomerService plugin provides professional support for 1v1 customer service call scenarios. For comprehensive documentation, see Customer Service Plugin.

  • 1v1 calls: Each session is limited to 2 participants (agent + customer), max_users: 2
  • Session management: Create, assign agent, close, statistics
  • No-login customer side: Customers enter directly via link without registration
  • Audio mixing: Agent side can mix local audio files into the stream (background music, notification sounds)
  • Satisfaction rating: Customers can provide star ratings after the call ends
ActionDirectionDescription
accept_callC→SAgent accepts the call
end_callC→SHang up the call
transfer_callC→STransfer to another agent
hold_callC→SHold the call
resume_callC→SResume the call
call_acceptedS→CCall has been answered
call_endedS→CCall has ended
call_transferredS→CCall has been transferred
customer_service:
max_sessions: 1000 # Maximum concurrent sessions
session_timeout: 3600 # Session timeout (seconds)
enable_recording: false # Enable call recording

For detailed HTTP API reference, see Customer Service API.


The Room Service includes a comprehensive three-tier reporting system that automatically collects audio/video quality data and user behavior data, providing essential support for operations and troubleshooting.

Report TypeTriggerCore ContentStorage Table
HeartbeatPeriodic (every few seconds)Audio/video bitrate, framerate, resolution, packet loss, freeze, RTTreport_heartbeats + report_heartbeat_downstream
Leave RoomWhen user leavesSession duration, device info, SDK version, join contextreport_leave_rooms
KVEvent-drivenSuccess rate & latency for 15+ events (join/publish/subscribe, etc.)report_kv
EndpointDescription
GET /room_stats/{room_id}Detailed room statistics (heartbeat+leave+KV), supports start_time / end_time params
GET /all_room_statsSite-wide aggregate statistics with all room sessions and summaries
GET /daily_statsDaily trend data (sessions, users, peak concurrent, streaming duration)

Reporting data powers three dashboards in the Admin console:

  • Stream Detail: Real-time bitrate/framerate waveforms + historical trend charts for individual streams
  • Room Report: Sender-receiver pair bitrate comparison, freeze analysis, event timelines
  • Live Dashboard: Site-wide real-time overview, 7-day trends, risk detection, popularity ranking
room:
live:
report_retention_days: 15 # Keep last 15 days (0 = keep forever)

Background cleanup tasks automatically delete expired records. Reporting data is persisted via ReportStorage to the database, with automatic fallback to in-memory storage when the database is unavailable.