Skip to content

Commit

Permalink
fix: webrtc sdk apis json parse error (8xFF#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
giangndm authored Jan 26, 2024
1 parent 9dbd402 commit e78517f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
31 changes: 31 additions & 0 deletions packages/cluster/src/define/rpc/general.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{net::IpAddr, ops::Deref};

use poem_openapi::{Enum, Object};
use proc_macro::{IntoVecU8, TryFromSliceU8};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -36,3 +38,32 @@ pub enum ServerType {
WEBRTC,
RTMP,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, IntoVecU8, TryFromSliceU8, Clone)]
pub struct RemoteAddr(IpAddr);

impl From<IpAddr> for RemoteAddr {
fn from(addr: IpAddr) -> Self {
Self(addr)
}
}

impl Into<IpAddr> 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)))
}
}
22 changes: 14 additions & 8 deletions packages/cluster/src/define/rpc/webrtc.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -25,26 +28,29 @@ pub struct WebrtcConnectRequestSender {

#[derive(Debug, Serialize, Deserialize, Object, PartialEq, Eq, IntoVecU8, TryFromSliceU8, Clone)]
pub struct WebrtcConnectRequest {
pub session_uuid: Option<u64>,
pub ip_addr: IpAddr,
#[oai(skip)]
pub session_uuid: u64,
#[oai(skip)]
pub ip_addr: RemoteAddr,
#[oai(skip)]
pub user_agent: String,
pub version: Option<String>,
pub room: String,
pub peer: String,
#[serde(default = "ClusterEndpointSubscribeScope::default")]
#[oai(default = "ClusterEndpointSubscribeScope::default")]
pub sub_scope: ClusterEndpointSubscribeScope,
#[serde(default = "ClusterEndpointPublishScope::default")]
#[oai(default = "ClusterEndpointPublishScope::default")]
pub pub_scope: ClusterEndpointPublishScope,
pub token: String,
#[serde(default = "MixMinusAudioMode::default")]
#[oai(default = "MixMinusAudioMode::default")]
pub mix_minus_audio: MixMinusAudioMode,
pub join_now: Option<bool>,
pub codecs: Option<Vec<PayloadType>>,
pub receivers: WebrtcConnectRequestReceivers,
pub sdp: Option<String>,
pub compressed_sdp: Option<Vec<u8>>,
pub senders: Vec<WebrtcConnectRequestSender>,
#[serde(default = "BitrateControlMode::default")]
#[oai(default = "BitrateControlMode::default")]
pub remote_bitrate_control_mode: BitrateControlMode,
}

Expand Down
4 changes: 2 additions & 2 deletions servers/media-server/src/server/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
4 changes: 2 additions & 2 deletions servers/media-server/src/server/gateway/rpc/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions servers/media-server/src/server/webrtc/rpc/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<WebrtcConnectRequest, WebrtcConnectResponse>::new(body.0);
Expand Down

0 comments on commit e78517f

Please sign in to comment.