126 lines
2.8 KiB
Rust
126 lines
2.8 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use uuid::Uuid;
|
|
|
|
/// Messages sent over the WebSocket signaling channel
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(tag = "type", rename_all = "snake_case")]
|
|
pub enum SignalingMessage {
|
|
/// Client registers itself with the signaling server
|
|
Register { user_id: Uuid },
|
|
|
|
/// ICE/NAT candidate exchange for P2P hole punching
|
|
Offer {
|
|
from: Uuid,
|
|
to: Uuid,
|
|
room_id: Uuid,
|
|
/// Serialized offer data (public IP, port, NAT type)
|
|
sdp: String,
|
|
},
|
|
Answer {
|
|
from: Uuid,
|
|
to: Uuid,
|
|
room_id: Uuid,
|
|
sdp: String,
|
|
},
|
|
IceCandidate {
|
|
from: Uuid,
|
|
to: Uuid,
|
|
candidate: String,
|
|
},
|
|
|
|
/// Presence events
|
|
UserOnline { user_id: Uuid },
|
|
UserOffline { user_id: Uuid },
|
|
|
|
/// Room events pushed by server
|
|
RoomInvite {
|
|
from: Uuid,
|
|
room_id: Uuid,
|
|
room_name: String,
|
|
},
|
|
MemberJoined {
|
|
room_id: Uuid,
|
|
user_id: Uuid,
|
|
username: String,
|
|
},
|
|
MemberLeft {
|
|
room_id: Uuid,
|
|
user_id: Uuid,
|
|
},
|
|
|
|
/// Member kicked from room
|
|
Kicked {
|
|
room_id: Uuid,
|
|
reason: String,
|
|
},
|
|
|
|
/// Room closed by owner
|
|
RoomClosed {
|
|
room_id: Uuid,
|
|
},
|
|
|
|
/// Friend events
|
|
FriendRequest { from: Uuid, username: String },
|
|
FriendAccepted { from: Uuid, username: String },
|
|
|
|
/// Chat messages in room
|
|
ChatMessage {
|
|
room_id: Uuid,
|
|
from: Uuid,
|
|
username: String,
|
|
content: String,
|
|
timestamp: i64,
|
|
},
|
|
/// Send chat message to room (client -> server)
|
|
SendChat {
|
|
room_id: Uuid,
|
|
content: String,
|
|
},
|
|
|
|
/// P2P connection negotiation result
|
|
P2pSuccess { room_id: Uuid, peer_id: Uuid },
|
|
P2pFailed { room_id: Uuid, peer_id: Uuid },
|
|
|
|
/// Relay session control
|
|
RelayJoin {
|
|
room_id: Uuid,
|
|
session_token: String,
|
|
},
|
|
|
|
/// Ping/pong for keepalive
|
|
Ping,
|
|
Pong,
|
|
|
|
/// Server error response
|
|
Error { code: u16, message: String },
|
|
}
|
|
|
|
/// QUIC relay packet header (prefix before Minecraft TCP data)
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct RelayPacket {
|
|
pub room_id: Uuid,
|
|
pub source_peer: Uuid,
|
|
pub dest_peer: Option<Uuid>, // None = broadcast to room
|
|
pub payload: Vec<u8>,
|
|
}
|
|
|
|
/// NAT type detected by STUN
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
pub enum NatType {
|
|
None,
|
|
FullCone,
|
|
RestrictedCone,
|
|
PortRestrictedCone,
|
|
Symmetric,
|
|
Unknown,
|
|
}
|
|
|
|
/// Peer connection info exchanged during signaling
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct PeerInfo {
|
|
pub user_id: Uuid,
|
|
pub public_addr: String,
|
|
pub local_addrs: Vec<String>,
|
|
pub nat_type: NatType,
|
|
}
|