Skip to content

Commit

Permalink
Fix dummy test datachannel callback behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma233 committed Mar 19, 2024
1 parent a1efaaa commit 37e5f81
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions crates/transport/src/connections/dummy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use crate::notifier::Notifier;
use crate::pool::Pool;

/// Max delay in ms on sending message
const DUMMY_DELAY_MAX: u64 = 100;
const DUMMY_DELAY_MAX: u64 = 1000;
/// Min delay in ms on sending message
const DUMMY_DELAY_MIN: u64 = 0;
const DUMMY_DELAY_MIN: u64 = 100;
/// Config random delay when send message
const SEND_MESSAGE_DELAY: bool = true;
/// Config random delay when channel opening
Expand Down Expand Up @@ -93,6 +93,18 @@ impl DummyConnection {
}

self.callback().on_peer_connection_state_change(state).await;

// Simulate the behavior where the data channel is not opened immediately upon connection,
// but rather after a certain number of milliseconds.
if state == WebrtcConnectionState::Connected {
let cb = self.callback();
tokio::spawn(async move {
if CHANNEL_OPEN_DELAY {
random_delay().await;
}
cb.on_data_channel_open().await;
});
}
}
}

Expand Down

0 comments on commit 37e5f81

Please sign in to comment.