pub mod rest;
pub mod websocket;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub enum SignalingMethod {
CreateRoom,
JoinRoom,
LeaveRoom,
Offer,
Answer,
IceCandidate,
Publish,
Subscribe,
Unpublish,
Unsubscribe,
CreateDataChannel,
DataChannelMessage,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SignalingMessage {
pub jsonrpc: String,
pub method: SignalingMethod,
pub params: SignalingParams,
pub id: Option<u64>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(untagged)]
pub enum SignalingParams {
CreateRoom(CreateRoomParams),
JoinRoom(JoinRoomParams),
LeaveRoom(LeaveRoomParams),
Offer(SdpParams),
Answer(SdpParams),
IceCandidate(IceCandidateParams),
Publish(PublishParams),
Subscribe(SubscribeParams),
Unpublish(UnpublishParams),
Unsubscribe(UnsubscribeParams),
CreateDataChannel(CreateDataChannelParams),
DataChannelMessage(DataChannelMessageParams),
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CreateRoomParams {
pub room_id: String,
pub max_peers: Option<u32>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct JoinRoomParams {
pub room_id: String,
pub peer_id: String,
#[serde(default)]
pub peers: Option<Vec<PeerInfoResponse>>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PeerInfoResponse {
pub id: String,
pub is_publishing: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LeaveRoomParams {
pub room_id: String,
pub peer_id: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SdpParams {
pub room_id: String,
pub peer_id: String,
pub sdp: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct IceCandidateParams {
pub room_id: String,
pub peer_id: String,
pub candidate: String,
pub sdp_mid: String,
pub sdp_mline_index: u16,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PublishParams {
pub room_id: String,
pub peer_id: String,
pub sdp: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SubscribeParams {
pub room_id: String,
pub publisher_id: String,
pub subscriber_id: String,
pub sdp: Option<String>, #[serde(rename = "type")]
pub sdp_type: Option<String>, }
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UnpublishParams {
pub room_id: String,
pub peer_id: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UnsubscribeParams {
pub room_id: String,
pub publisher_id: String,
pub subscriber_id: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CreateDataChannelParams {
pub room_id: String,
pub peer_id: String,
pub label: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DataChannelMessageParams {
pub room_id: String,
pub peer_id: String,
pub label: String,
pub data: Vec<u8>,
pub is_text: bool,
}
impl SignalingMessage {
pub fn request(method: SignalingMethod, params: SignalingParams, id: u64) -> Self {
Self {
jsonrpc: "2.0".to_string(),
method,
params,
id: Some(id),
}
}
pub fn notification(method: SignalingMethod, params: SignalingParams) -> Self {
Self {
jsonrpc: "2.0".to_string(),
method,
params,
id: None,
}
}
}