withDataTrack

suspend fun <T> withDataTrack(name: String, options: DataTrackPublishOptions? = null, block: suspend (LocalDataTrack) -> T): Result<T>

Publishes a data track for the duration of block, then unpublishes it automatically.

The track is unpublished when block returns, throws, or the calling coroutine is cancelled.

room.localParticipant.withDataTrack("telemetry") { track ->
track.tryPush(DataTrackFrame(payload))
}

Return

A successful Result containing the value returned by block, or a failure if the track cannot be published or block throws.

Parameters

name

Track name visible to other participants. Must be unique per publisher.

options

Optional encoding and schema metadata; see publishDataTrack.

block

Receives the published track; the track is unpublished when it returns or throws.