diff --git a/packages/cluster/src/define/rpc/general.rs b/packages/cluster/src/define/rpc/general.rs index 3f02ff06..e5791819 100644 --- a/packages/cluster/src/define/rpc/general.rs +++ b/packages/cluster/src/define/rpc/general.rs @@ -1,3 +1,5 @@ +use std::{net::IpAddr, ops::Deref}; + use poem_openapi::{Enum, Object}; use proc_macro::{IntoVecU8, TryFromSliceU8}; use serde::{Deserialize, Serialize}; @@ -36,3 +38,32 @@ pub enum ServerType { WEBRTC, RTMP, } + +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, IntoVecU8, TryFromSliceU8, Clone)] +pub struct RemoteAddr(IpAddr); + +impl From for RemoteAddr { + fn from(addr: IpAddr) -> Self { + Self(addr) + } +} + +impl Into for RemoteAddr { + fn into(self) -> IpAddr { + self.0 + } +} + +impl Deref for RemoteAddr { + type Target = IpAddr; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl Default for RemoteAddr { + fn default() -> Self { + Self(IpAddr::V4(std::net::Ipv4Addr::new(127, 0, 0, 1))) + } +} diff --git a/packages/cluster/src/define/rpc/webrtc.rs b/packages/cluster/src/define/rpc/webrtc.rs index fc1f2a9a..d4afd297 100644 --- a/packages/cluster/src/define/rpc/webrtc.rs +++ b/packages/cluster/src/define/rpc/webrtc.rs @@ -1,8 +1,11 @@ -use std::{fmt::Debug, net::IpAddr}; +use std::fmt::Debug; use crate::{ClusterEndpointPublishScope, ClusterEndpointSubscribeScope, MediaSessionToken, VerifyObject}; -use super::super::media::{BitrateControlMode, MixMinusAudioMode, PayloadType}; +use super::{ + super::media::{BitrateControlMode, MixMinusAudioMode, PayloadType}, + general::RemoteAddr, +}; use poem_openapi::Object; use proc_macro::{IntoVecU8, TryFromSliceU8}; use serde::{Deserialize, Serialize}; @@ -23,16 +26,13 @@ pub struct WebrtcConnectRequestSender { pub screen: Option, } -fn default_ipaddr() -> IpAddr { - IpAddr::V4(std::net::Ipv4Addr::new(127, 0, 0, 1)) -} - #[derive(Debug, Serialize, Deserialize, Object, PartialEq, Eq, IntoVecU8, TryFromSliceU8, Clone)] pub struct WebrtcConnectRequest { - pub session_uuid: Option, - #[oai(default = "default_ipaddr")] - pub ip_addr: IpAddr, - #[oai(default = "String::default")] + #[oai(skip)] + pub session_uuid: u64, + #[oai(skip)] + pub ip_addr: RemoteAddr, + #[oai(skip)] pub user_agent: String, pub version: Option, pub room: String, diff --git a/servers/media-server/src/server/gateway.rs b/servers/media-server/src/server/gateway.rs index 5a5d826c..ce80ef79 100644 --- a/servers/media-server/src/server/gateway.rs +++ b/servers/media-server/src/server/gateway.rs @@ -221,11 +221,11 @@ where node_id, ServiceType::Webrtc, RPC_WEBRTC_CONNECT, - req.param().ip_addr, + req.param().ip_addr.clone().into(), location, &req.param().version.clone(), &req.param().user_agent.clone(), - req.param().session_uuid.expect("Should assign session_uuid on gateway"), + req.param().session_uuid, req, dest_service_id, ); diff --git a/servers/media-server/src/server/gateway/rpc/http.rs b/servers/media-server/src/server/gateway/rpc/http.rs index 2df40fa4..a5156be5 100644 --- a/servers/media-server/src/server/gateway/rpc/http.rs +++ b/servers/media-server/src/server/gateway/rpc/http.rs @@ -254,8 +254,8 @@ impl GatewayHttpApis { if let Some(sdp) = body.0.sdp.take() { body.0.compressed_sdp = Some(string_zip.compress(&sdp)); } - body.0.session_uuid = Some(data.1.generate_session_uuid()); - body.0.ip_addr = ip_addr; + body.0.session_uuid = data.1.generate_session_uuid(); + body.0.ip_addr = ip_addr.into(); body.0.user_agent = user_agent; if body.0.verify(data.1.verifier().deref()).is_none() { diff --git a/servers/media-server/src/server/webrtc/rpc/http.rs b/servers/media-server/src/server/webrtc/rpc/http.rs index 30f7e36c..f37581fa 100644 --- a/servers/media-server/src/server/webrtc/rpc/http.rs +++ b/servers/media-server/src/server/webrtc/rpc/http.rs @@ -263,8 +263,8 @@ impl WebrtcHttpApis { } log::info!("[HttpApis] create Webrtc endpoint {}/{}", body.0.room, body.0.peer); - body.0.session_uuid = Some(data.1.generate_session_uuid()); - body.0.ip_addr = ip_addr; + body.0.session_uuid = data.1.generate_session_uuid(); + body.0.ip_addr = ip_addr.into(); body.0.user_agent = user_agent; let (req, rx) = RpcReqResHttp::::new(body.0);