LocalDataTrack

class LocalDataTrack : DataTrackFrameSink

A data track published by the local participant. Obtain one from io.livekit.android.room.participant.LocalParticipant.publishDataTrack, then push frames with tryPush or send.

The publication stays live until unpublish is called, the SFU unpublishes the track, or the room disconnects. Dropping the last reference eventually unpublishes the track, but only once it is garbage collected — call unpublish to end the publication at a predictable point, or io.livekit.android.room.participant.LocalParticipant.withDataTrack to scope one to a block.

val result = room.localParticipant.publishDataTrack("telemetry")
result.onSuccess { track ->
track.tryPush(DataTrackFrame(payload))
track.unpublish()
}

Types

Link copied to clipboard

Policy for send when the send queue is full.

Properties

Link copied to clipboard

Metadata for this track.

Link copied to clipboard
open override val isPublished: Boolean

Whether the track is currently published. Becomes false after unpublish or if the SFU unpublishes it.

Functions

Link copied to clipboard
suspend fun send(frames: Flow<DataTrackFrame>, onQueueFull: LocalDataTrack.FrameDropPolicy = FrameDropPolicy.DROP): Result<Unit>

Sends frames from frames until it ends or the track is unpublished.

Link copied to clipboard
open override fun tryPush(frame: DataTrackFrame): Result<Unit>

Pushes a frame to subscribers.

Link copied to clipboard
fun unpublish()

Unpublishes the track. Subsequent tryPush calls fail with DataTrackPushFrameException.TrackUnpublished.

Link copied to clipboard
suspend fun waitForUnpublish()

Waits until the track is unpublished, by either the local participant or the SFU.