Skip to content

Commit 4276935

Browse files
committed
document passing in bad track frame format is an error
1 parent 35d0d5d commit 4276935

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

livekit-android-sdk/src/main/java/io/livekit/android/room/datatrack/DataTrackPublishOptions.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ data class DataTrackPublishOptions(
4242
* A schema always describes frames in a specific encoding, so [frameEncoding] is required
4343
* alongside a [schema]. The declared metadata is surfaced to subscribers via [DataTrackInfo].
4444
*
45+
* Whether a schema's encoding can actually describe frames in [frameEncoding] is checked when the
46+
* track is published, surfacing as [DataTrackPublishException.InvalidSchema].
47+
*
4548
* @param frameEncoding Encoding of the track's frames.
4649
* @param schema Schema describing the track's frames.
4750
*/

livekit-android-test/src/main/java/io/livekit/android/test/mock/room/datatrack/MockLocalDataTrackManager.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import io.livekit.uniffi.NoHandle
2727
import livekit.LivekitModels
2828
import livekit.LivekitRtc
2929
import uniffi.livekit_datatrack.EncryptionProvider
30+
import uniffi.livekit_datatrack.PublishException
3031

3132
class MockLocalDataTrackManagerFactory : LocalDataTrackManagerFactory {
3233
/**
@@ -46,13 +47,22 @@ class MockLocalDataTrackManagerFactory : LocalDataTrackManagerFactory {
4647
*/
4748
var createError: LinkageError? = null
4849

50+
/**
51+
* When set, every manager this creates fails [MockLocalDataTrackManager.publishTrack] with it,
52+
* standing in for a publish the native core rejects.
53+
*/
54+
var publishError: PublishException? = null
55+
4956
override fun create(
5057
delegate: LocalDataTrackManagerDelegate,
5158
encryptionProvider: EncryptionProvider?,
5259
): LocalDataTrackManagerInterface {
5360
createError?.let { throw it }
5461
lastEncryptionProvider = encryptionProvider
55-
return MockLocalDataTrackManager(delegate).also { manager = it }
62+
return MockLocalDataTrackManager(delegate).also {
63+
it.publishError = publishError
64+
manager = it
65+
}
5666
}
5767
}
5868

@@ -87,7 +97,11 @@ class MockLocalDataTrackManager(
8797
}
8898
}
8999

100+
/** Set to make [publishTrack] fail the way the native manager does. */
101+
var publishError: PublishException? = null
102+
90103
override suspend fun publishTrack(options: DataTrackOptions): LocalDataTrack {
104+
publishError?.let { throw it }
91105
val request = LivekitRtc.SignalRequest.newBuilder()
92106
.setPublishDataTrackRequest(
93107
LivekitRtc.PublishDataTrackRequest.newBuilder()

livekit-android-test/src/test/java/io/livekit/android/room/datatrack/OutgoingDataTrackManagerMockE2ETest.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.junit.Assert.assertNotSame
4040
import org.junit.Assert.assertNull
4141
import org.junit.Assert.assertTrue
4242
import org.junit.Test
43+
import uniffi.livekit_datatrack.PublishException
4344

4445
@OptIn(ExperimentalCoroutinesApi::class)
4546
class OutgoingDataTrackManagerMockE2ETest : MockE2ETest() {
@@ -68,6 +69,29 @@ class OutgoingDataTrackManagerMockE2ETest : MockE2ETest() {
6869
assertTrue(result.exceptionOrNull() is DataTrackPublishException.Internal)
6970
}
7071

72+
/**
73+
* The core rejects a schema whose encoding cannot describe the track's frames (and the other
74+
* schema-metadata rules) before it allocates a handle. This covers the SDK's half: that the
75+
* refusal reaches the caller as a typed failure rather than an opaque one.
76+
*/
77+
@Test
78+
fun publishDataTrackSurfacesInvalidSchemaFromTheCore() = runTest {
79+
localDataTrackManagerFactory.publishError =
80+
PublishException.InvalidSchema("Specified schema and frame encodings are incompatible")
81+
connect()
82+
83+
val result = room.localParticipant.publishDataTrack(
84+
"telemetry",
85+
DataTrackPublishOptions(
86+
DataTrackFrameEncoding.Cdr,
87+
DataTrackSchemaId("reading.v1", DataTrackSchemaEncoding.JsonSchema),
88+
),
89+
)
90+
91+
assertTrue(result.isFailure)
92+
assertTrue(result.exceptionOrNull() is DataTrackPublishException.InvalidSchema)
93+
}
94+
7195
@Test
7296
fun publishDataTrackPassesEncryptionProviderWhenE2eeEnabled() = runTest {
7397
room.e2eeOptions = E2EEOptions(keyProvider = NoopKeyProvider())

0 commit comments

Comments
 (0)