pub struct DataTrack<L> { /* private fields */ }Expand description
Track for communicating application-specific data between participants in room.
Implementations§
Source§impl<L> DataTrack<L>
impl<L> DataTrack<L>
Sourcepub fn info(&self) -> &DataTrackInfo
pub fn info(&self) -> &DataTrackInfo
Information about the data track.
Sourcepub fn is_published(&self) -> bool
pub fn is_published(&self) -> bool
Whether or not the track is still published.
Sourcepub async fn wait_for_unpublish(&self)
pub async fn wait_for_unpublish(&self)
Waits asynchronously until the track is unpublished.
Use this to trigger follow-up work once the track is no longer published. If the track is already unpublished, this method returns immediately.
Source§impl DataTrack<Local>
impl DataTrack<Local>
Sourcepub fn try_push(&self, frame: DataTrackFrame) -> Result<(), PushFrameError>
pub fn try_push(&self, frame: DataTrackFrame) -> Result<(), PushFrameError>
Try pushing a frame to subscribers of the track.
§Example
fn read_sensor() -> Vec<u8> {
// Read some sensor data...
vec![0xFA; 16]
}
let frame = read_sensor().into(); // Convert to frame
track.try_push(frame)?;
See DataTrackFrame for more ways to construct a frame and how to attach metadata.
§Errors
Pushing a frame can fail for several reasons:
- The track has been unpublished by the local participant or SFU
- The room is no longer connected
- Frames are being pushed too fast
Source§impl DataTrack<Remote>
impl DataTrack<Remote>
Sourcepub async fn subscribe(
&self,
) -> Result<DataTrackStream, DataTrackSubscribeError>
pub async fn subscribe( &self, ) -> Result<DataTrackStream, DataTrackSubscribeError>
Subscribes to the data track.
§Returns
A stream that yields DataTrackFrames as they arrive.
§Options
To set custom subscription options, see Self::subscribe_with_options.
§Multiple Subscriptions
An application may call subscribe more than once to process frames in
multiple places. For example, one async task might plot values on a graph
while another writes them to a file.
Internally, only the first call to subscribe communicates with the SFU and
allocates the resources required to receive frames. Additional subscriptions
reuse the same underlying pipeline and do not trigger additional signaling.
Note that newly created subscriptions only receive frames published after the initial subscription is established.
Sourcepub async fn subscribe_with_options(
&self,
options: DataTrackSubscribeOptions,
) -> Result<DataTrackStream, DataTrackSubscribeError>
pub async fn subscribe_with_options( &self, options: DataTrackSubscribeOptions, ) -> Result<DataTrackStream, DataTrackSubscribeError>
Subscribes to the data track, specifying custom options.
Same usage and return as Self::subscribe with an additional argument
to specify options.
Sourcepub fn publisher_identity(&self) -> &str
pub fn publisher_identity(&self) -> &str
Identity of the participant who published the track.