Skip to content

Commit 6ef444f

Browse files
committed
fix(p2p/webrtc): initial message getting lost sometimes for web based webrtc
1 parent 0ab766f commit 6ef444f

File tree

1 file changed

+14
-5
lines changed
  • p2p/src/service_impl/webrtc

1 file changed

+14
-5
lines changed

p2p/src/service_impl/webrtc/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,17 @@ impl Drop for RTCChannel {
184184
}
185185
}
186186

187-
async fn wait_for_ice_gathering_complete(pc: &RTCConnection) {
188-
let timeout = Duration::from_secs(3);
189-
187+
async fn sleep(dur: Duration) {
190188
#[cfg(not(target_arch = "wasm32"))]
191-
let timeout = tokio::time::sleep(timeout);
189+
let fut = tokio::time::sleep(dur);
192190
#[cfg(target_arch = "wasm32")]
193-
let timeout = gloo_timers::future::TimeoutFuture::new(timeout.as_millis() as u32);
191+
let fut = gloo_timers::future::TimeoutFuture::new(dur.as_millis() as u32);
192+
fut.await
193+
}
194+
195+
async fn wait_for_ice_gathering_complete(pc: &RTCConnection) {
196+
let timeout = sleep(Duration::from_secs(3));
197+
194198
tokio::select! {
195199
_ = timeout => {}
196200
_ = pc.wait_for_ice_gathering_complete() => {}
@@ -513,6 +517,11 @@ async fn peer_loop(
513517
let chan_clone = chan.clone();
514518
let event_sender_clone = event_sender.clone();
515519
spawn_local(async move {
520+
// Add a delay for sending messages after channel
521+
// was opened. Some initial messages get lost otherwise.
522+
// TODO(binier): find deeper cause and fix it.
523+
sleep(Duration::from_secs(3)).await;
524+
516525
while let Some((msg_id, encoded)) = sender_rx.recv().await {
517526
let encoded = bytes::Bytes::from(encoded);
518527
let mut chunks =

0 commit comments

Comments
 (0)