From b10a96b7bce37081a65291b455d6617a382ac652 Mon Sep 17 00:00:00 2001 From: lichon Date: Sat, 15 Nov 2025 16:04:59 +0800 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- examples/webrtc.rs | 1 + examples/webrtc_dummy.rs | 2 +- src/webrtc.rs | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/webrtc.rs b/examples/webrtc.rs index 80e405a..df4a722 100644 --- a/examples/webrtc.rs +++ b/examples/webrtc.rs @@ -14,6 +14,7 @@ use bytes::Bytes; use clap::{Arg, Command}; use tokio::time::Duration; +#[cfg(feature = "webrtc")] use webrtc::peer_connection::math_rand_alpha; #[tokio::main] diff --git a/examples/webrtc_dummy.rs b/examples/webrtc_dummy.rs index e406990..c826d64 100644 --- a/examples/webrtc_dummy.rs +++ b/examples/webrtc_dummy.rs @@ -42,4 +42,4 @@ impl WebRTCStream { } } -fn _main() {} + diff --git a/src/webrtc.rs b/src/webrtc.rs index 5c0bc4c..f2b0dc2 100644 --- a/src/webrtc.rs +++ b/src/webrtc.rs @@ -32,7 +32,8 @@ pub struct WebRTCStream { send_timeout: u64, } -/// message size limit for Chromium +/// Standard maximum message size for WebRTC data channels (RFC 8831, 65535 bytes). +/// Most browsers, including Chromium, enforce this protocol limit. const DATA_CHANNEL_BUFFER_SIZE: u16 = u16::MAX; lazy_static::lazy_static! { @@ -222,9 +223,8 @@ impl WebRTCStream { Ok(k) => { lock.remove(&k); log::debug!( - "WebRTC session removed key from cache: {} current len: {}", - k, - lock.len() + "WebRTC session removed key from cache: {}", + k ); } Err(_e) => {} @@ -274,7 +274,7 @@ impl WebRTCStream { #[inline] pub async fn get_local_endpoint(&self) -> ResultType { if let Some(local_desc) = self.pc.local_description().await { - let sdp = serde_json::to_string(&local_desc).unwrap_or_default(); + let sdp = serde_json::to_string(&local_desc)?; let endpoint = Self::sdp_to_endpoint(&sdp); Ok(endpoint) } else {