2.3 KiB
2.3 KiB
Milestone 4: Multi-User Routing (The Switchboard)
Goal: Support multiple users in rooms with stable, synchronized audio.
1. Server State & Broadcast (server_node/udp_relay.rs)
- Data Structure: Expand the
DashMapto trackChannelId -> Vec<SessionToken>. - Routing Loop: When a UDP packet arrives, look up the sender's
ChannelId. Iterate through all otherSessionTokens in that channel, grab theirSocketAddr, and useUdpSocket::send_toto forward the exact bytes. (Zero-copy payload routing). - Whisper Lists (Direct UDP): Modify the UDP header to include a
Target_SessionToken. If this value is!= 0, bypass the channel iteration and forward the packet strictly to that target'sSocketAddr.
2. Client Jitter Buffer (client_node/network/jitter.rs)
- Data Structure: Create a
std::collections::BinaryHeapwrapped in a Mutex, ordered by the packet'sSequenceNumber. - Buffering Logic: When packets arrive from the UDP socket, push them into the heap. Do NOT start popping until the heap contains at least 2 packets (40ms "Watermark").
- Tick Loop: Every 20ms, the audio playback thread pops the next expected
SequenceNumber.
3. Packet Loss Concealment (PLC) & Playback
- Missed Sequences: If the
SequenceNumberpopped from the Jitter Buffer is missing (skipped a number), calldecoder.decode_float()but passNoneor a null buffer to the Opus library. This triggers internal PLC synthesis. - Late Packets: If a packet arrives with a
SequenceNumberolder than what has already been played, immediately drop it.
4. TCP Chat & Presence Sync
- Broadcast Events: When a user joins or leaves a channel, the server broadcasts a
TcpEvent::UserJoinedorUserLeftto all users in that channel. - Chat Routing: Client sends
TcpEvent::ChatMessage. Server broadcasts it to the relevant channel. - UI Updates: The client parses these TCP events to update the
eguiTree View and append messages to the Chat Log in real-time.
5. Diagnostics Overlay
- Debug UI: Implement a developer panel (toggled via
F3or a button) inegui. - Metrics: Hook into the Jitter Buffer length, calculate packet loss % over the last 10 seconds, and ping the server via TCP to display live network health on the UI.