diff --git a/crates/livekit-core/src/lib.rs b/crates/livekit-core/src/lib.rs index bfc8c9a..15669d3 100644 --- a/crates/livekit-core/src/lib.rs +++ b/crates/livekit-core/src/lib.rs @@ -1,6 +1,3 @@ -extern crate core; -extern crate core; - pub mod proto { include!(concat!(env!("OUT_DIR"), "/livekit.rs")); } diff --git a/crates/livekit-core/src/room/id.rs b/crates/livekit-core/src/room/id.rs index f46198a..9bd35eb 100644 --- a/crates/livekit-core/src/room/id.rs +++ b/crates/livekit-core/src/room/id.rs @@ -1,21 +1,39 @@ +use std::fmt; + macro_rules! id_str { ($($name:ident;)*) => { $( + impl $name { + pub fn new(str: String) -> Self { + Self(str) + } + + pub fn as_str(&self) -> &str { + &self.0 + } + } + impl From for $name { fn from(str: String) -> $name { $name(str) } } + impl From<$name> for String { + fn from(id: $name) -> String { + id.0 + } + } + impl PartialEq<$name> for String { fn eq(&self, u: &$name) -> bool { *self == *u.0 } } - impl From<$name> for String { - fn from(id: $name) -> String { - id.0 + impl fmt::Display for $name { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(&self.0) } } )* @@ -23,13 +41,13 @@ macro_rules! id_str { } #[derive(Clone, Default, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] -pub struct ParticipantSid(pub String); +pub struct ParticipantSid(String); #[derive(Clone, Default, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] -pub struct ParticipantIdentity(pub String); +pub struct ParticipantIdentity(String); #[derive(Clone, Default, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] -pub struct TrackSid(pub String); +pub struct TrackSid(String); id_str! { ParticipantSid; diff --git a/crates/livekit-core/src/rtc_engine/mod.rs b/crates/livekit-core/src/rtc_engine/mod.rs index 86fd80f..1410b59 100644 --- a/crates/livekit-core/src/rtc_engine/mod.rs +++ b/crates/livekit-core/src/rtc_engine/mod.rs @@ -1,4 +1,3 @@ -use core::num::flt2dec::Sign; use parking_lot::Mutex; use std::sync::atomic::{AtomicBool, AtomicU8, Ordering}; use std::sync::{Arc, Weak}; diff --git a/crates/livekit-webrtc/src/data_channel.rs b/crates/livekit-webrtc/src/data_channel.rs index a45c6ca..a231ee3 100644 --- a/crates/livekit-webrtc/src/data_channel.rs +++ b/crates/livekit-webrtc/src/data_channel.rs @@ -18,7 +18,9 @@ pub struct DataChannel { impl Debug for DataChannel { fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { - write!(f, "DataChannel[{}]", self.label()) + f.debug_struct("DataChannel") + .field("label", &self.label()) + .finish() } } diff --git a/crates/livekit-webrtc/src/media_stream.rs b/crates/livekit-webrtc/src/media_stream.rs index 3fff376..38bfed9 100644 --- a/crates/livekit-webrtc/src/media_stream.rs +++ b/crates/livekit-webrtc/src/media_stream.rs @@ -1,13 +1,24 @@ use cxx::UniquePtr; +use std::fmt::{Debug, Formatter}; use libwebrtc_sys::media_stream as sys_ms; - pub use sys_ms::ffi::TrackState; pub struct MediaStreamTrack { cxx_handle: UniquePtr, } +impl Debug for MediaStreamTrack { + fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { + f.debug_struct("MediaStreamTrack") + .field("id", &self.id()) + .field("kind", &self.kind()) + .field("enabled", &self.enabled()) + .field("state", &self.state()) + .finish() + } +} + impl MediaStreamTrack { pub(crate) fn new(cxx_handle: UniquePtr) -> Self { Self { cxx_handle } @@ -38,14 +49,20 @@ pub struct MediaStream { cxx_handle: UniquePtr, } +impl Debug for MediaStream { + fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { + f.debug_struct("MediaStream") + .field("id", &self.id()) + .finish() + } +} + impl MediaStream { pub(crate) fn new(cxx_handle: UniquePtr) -> Self { - Self { - cxx_handle - } + Self { cxx_handle } } pub fn id(&self) -> String { self.cxx_handle.id() } -} \ No newline at end of file +} diff --git a/crates/livekit-webrtc/src/peer_connection.rs b/crates/livekit-webrtc/src/peer_connection.rs index 4d44676..b95005a 100644 --- a/crates/livekit-webrtc/src/peer_connection.rs +++ b/crates/livekit-webrtc/src/peer_connection.rs @@ -1,3 +1,4 @@ +use std::fmt::{Debug, Formatter}; use std::mem::ManuallyDrop; use std::sync::{Arc, Mutex}; @@ -31,6 +32,18 @@ pub struct PeerConnection { native_observer: UniquePtr, } +impl Debug for PeerConnection { + fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { + f.debug_struct("PeerConnection") + .field("signaling_state", &self.signaling_state()) + .field("ice_connection_state", &self.ice_connection_state()) + .field("ice_gathering_state", &self.ice_gathering_state()) + .field("local_description", &self.local_description()) + .field("remote_description", &self.remote_description()) + .finish() + } +} + impl PeerConnection { pub(crate) fn new( cxx_handle: UniquePtr, diff --git a/crates/livekit-webrtc/src/rtp_receiver.rs b/crates/livekit-webrtc/src/rtp_receiver.rs index 0bcfee3..6a4ea5b 100644 --- a/crates/livekit-webrtc/src/rtp_receiver.rs +++ b/crates/livekit-webrtc/src/rtp_receiver.rs @@ -1,11 +1,20 @@ use crate::media_stream::MediaStreamTrack; use cxx::UniquePtr; use libwebrtc_sys::rtp_receiver as sys_rec; +use std::fmt::{Debug, Formatter}; pub struct RtpReceiver { cxx_handle: UniquePtr, } +impl Debug for RtpReceiver { + fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { + f.debug_struct("RtpReceiver") + .field("track", &self.track()) + .finish() + } +} + impl RtpReceiver { pub(crate) fn new(cxx_handle: UniquePtr) -> Self { Self { cxx_handle }