pub enum RTCDataChannelEvent {
OnOpen(RTCDataChannelId),
OnError(RTCDataChannelId),
OnClosing(RTCDataChannelId),
OnClose(RTCDataChannelId),
OnBufferedAmountLow(RTCDataChannelId),
OnBufferedAmountHigh(RTCDataChannelId),
}Expand description
Events that can be emitted by an RTCDataChannel.
These events track the lifecycle and buffer state of data channels.
Applications should poll these events from RTCPeerConnectionEvent::OnDataChannel
to manage data channel connections and implement flow control.
§Lifecycle Events
Data channels go through the following lifecycle:
OnOpen- Channel is ready for data transmissionOnClosing- Channel is starting to closeOnClose- Channel is fully closedOnError- An error occurred
§Buffer Events
OnBufferedAmountLow- Buffer dropped below low-water mark (safe to send more)OnBufferedAmountHigh- Buffer exceeded high-water mark (should pause sending)
§Examples
§Handling data channel events in event loop
use rtc::peer_connection::event::{RTCPeerConnectionEvent, RTCDataChannelEvent};
match event {
RTCPeerConnectionEvent::OnDataChannel(dc_event) => {
match dc_event {
RTCDataChannelEvent::OnOpen(channel_id) => {
println!("Data channel opened: {:?}", channel_id);
}
RTCDataChannelEvent::OnClose(channel_id) => {
println!("Data channel closed: {:?}", channel_id);
}
RTCDataChannelEvent::OnError(channel_id) => {
eprintln!("Data channel error: {:?}", channel_id);
}
_ => {}
}
}
_ => {}
}§Implementing flow control with buffer events
use rtc::peer_connection::event::{RTCPeerConnectionEvent, RTCDataChannelEvent};
match event {
RTCPeerConnectionEvent::OnDataChannel(dc_event) => {
match dc_event {
RTCDataChannelEvent::OnBufferedAmountLow(channel_id) => {
println!("Buffer low - resume sending");
*paused = false;
}
RTCDataChannelEvent::OnBufferedAmountHigh(channel_id) => {
println!("Buffer high - pause sending");
*paused = true;
}
_ => {}
}
}
_ => {}
}§See Also
Variants§
OnOpen(RTCDataChannelId)
Data channel has opened and is ready to send/receive data.
This event is fired when the data channel transitions to the “open” state. Data can now be sent through the channel.
OnError(RTCDataChannelId)
An error occurred on the data channel.
This event is fired when an error is encountered. The channel may still be usable depending on the error type.
OnClosing(RTCDataChannelId)
Data channel is closing.
This event is fired when the channel begins the closing process. The channel is transitioning to the “closing” state.
OnClose(RTCDataChannelId)
Data channel has closed.
This event is fired when the channel is fully closed and no longer usable. No more data can be sent or received.
OnBufferedAmountLow(RTCDataChannelId)
Buffered amount dropped below the low-water mark.
This event is fired when the amount of buffered outgoing data drops
below the threshold set by set_buffered_amount_low_threshold().
This indicates it’s safe to send more data without causing excessive buffering.
Use this event to implement flow control and prevent memory exhaustion.
OnBufferedAmountHigh(RTCDataChannelId)
Buffered amount exceeded the high-water mark (implementation-specific).
This is a non-standard event that can be used to detect when too much data is being buffered. Applications should pause sending when this fires.
Trait Implementations§
Source§impl Clone for RTCDataChannelEvent
impl Clone for RTCDataChannelEvent
Source§fn clone(&self) -> RTCDataChannelEvent
fn clone(&self) -> RTCDataChannelEvent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RTCDataChannelEvent
impl Debug for RTCDataChannelEvent
Auto Trait Implementations§
impl Freeze for RTCDataChannelEvent
impl RefUnwindSafe for RTCDataChannelEvent
impl Send for RTCDataChannelEvent
impl Sync for RTCDataChannelEvent
impl Unpin for RTCDataChannelEvent
impl UnsafeUnpin for RTCDataChannelEvent
impl UnwindSafe for RTCDataChannelEvent
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.