80 lines
2.2 KiB
Rust
80 lines
2.2 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
pub type UserId = u32; // Unique identifier for a user within a room
|
|
pub type StreamId = u16; // Typically mapped to User + Media Source
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
|
|
#[repr(u8)]
|
|
pub enum MediaType {
|
|
Audio = 0,
|
|
Video = 1,
|
|
Screen = 2,
|
|
Command = 3, // For handshake/keepalive
|
|
Unknown = 255,
|
|
}
|
|
|
|
/// UDP Packet Header (fixed size binary struct)
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct PacketHeader {
|
|
pub version: u8, // Protocol version (v1)
|
|
pub media_type: MediaType,
|
|
pub user_id: UserId, // Identifies the source user (was stream_id)
|
|
pub sequence: u32, // User-defined sequence number (for reordering/loss)
|
|
pub timestamp: u32, // RTP-like timestamp
|
|
pub fragment_index: u16, // If packet is fragmented (0 if not)
|
|
pub fragment_count: u16, // Total fragments (1 if not)
|
|
pub flags: u8, // Bitmask: 0x01 = Keyframe, etc.
|
|
}
|
|
|
|
pub const FLAG_KEYFRAME: u8 = 0x01;
|
|
|
|
/// Signaling Messages (WebSocket - JSON)
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
#[serde(tag = "type", content = "data")]
|
|
pub enum ControlMsg {
|
|
/// Client -> Server: Request to join a room
|
|
Join {
|
|
room_code: String,
|
|
display_name: String,
|
|
},
|
|
/// Server -> Client: Join success
|
|
Joined {
|
|
self_id: UserId,
|
|
room_code: String,
|
|
peers: Vec<PeerInfo>,
|
|
},
|
|
/// Server -> Client: New peer joined
|
|
PeerJoined {
|
|
user_id: UserId,
|
|
display_name: String,
|
|
},
|
|
/// Server -> Client: Peer left
|
|
PeerLeft {
|
|
user_id: UserId,
|
|
},
|
|
/// Client -> Server: Update stream status (e.g. camera on/off)
|
|
UpdateStream {
|
|
user_id: UserId,
|
|
stream_id: StreamId,
|
|
active: bool,
|
|
media_type: MediaType,
|
|
},
|
|
/// Client <-> Server: Chat message
|
|
ChatMessage {
|
|
user_id: UserId,
|
|
display_name: String,
|
|
message: String,
|
|
timestamp: u64,
|
|
},
|
|
/// General Error
|
|
Error {
|
|
message: String,
|
|
},
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct PeerInfo {
|
|
pub user_id: UserId,
|
|
pub display_name: String,
|
|
// Could include active streams etc.
|
|
}
|