Skip to content

Commit

Permalink
Remove RoomOptions from Room.connect (livekit#346)
Browse files Browse the repository at this point in the history
This was causing confusion in users who expected it to overwrite the existing room options
  • Loading branch information
davidliu authored Dec 26, 2023
1 parent e636133 commit c6646c3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class LiveKit {
}
room.adaptiveStream = options.adaptiveStream
room.dynacast = options.dynacast
room.e2eeOptions = options.e2eeOptions

return room
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ data class RoomOptions(
val dynacast: Boolean = false,

/**
* Options for end-to-end encryption.
* @see [Room.e2eeOptions]
*/
val e2eeOptions: E2EEOptions? = null,

Expand Down
14 changes: 12 additions & 2 deletions livekit-android-sdk/src/main/java/io/livekit/android/room/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import io.livekit.android.Version
import io.livekit.android.audio.AudioHandler
import io.livekit.android.dagger.InjectionNames
import io.livekit.android.e2ee.E2EEManager
import io.livekit.android.e2ee.E2EEOptions
import io.livekit.android.events.*
import io.livekit.android.memory.CloseableManager
import io.livekit.android.renderer.TextureViewRenderer
Expand Down Expand Up @@ -161,6 +162,13 @@ constructor(
localParticipant.dynacast = value
}

/**
* Options for end-to-end encryption. Must be setup prior to [connect].
*
* If null, e2ee will be disabled.
*/
var e2eeOptions: E2EEOptions? = null

/**
* Default options to use when creating an audio track.
*/
Expand Down Expand Up @@ -210,15 +218,17 @@ constructor(
videoTrackCaptureDefaults = videoTrackCaptureDefaults,
audioTrackPublishDefaults = audioTrackPublishDefaults,
videoTrackPublishDefaults = videoTrackPublishDefaults,
e2eeOptions = null,
e2eeOptions = e2eeOptions,
)

suspend fun connect(url: String, token: String, options: ConnectOptions = ConnectOptions(), roomOptions: RoomOptions = getCurrentRoomOptions()) {
suspend fun connect(url: String, token: String, options: ConnectOptions = ConnectOptions()) {
if (this::coroutineScope.isInitialized) {
coroutineScope.cancel()
}
coroutineScope = CoroutineScope(defaultDispatcher + SupervisorJob())

val roomOptions = getCurrentRoomOptions()

// Setup local participant.
localParticipant.reinitialize()
coroutineScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ class RoomTest {
override fun create(dynacast: Boolean): LocalParticipant {
return Mockito.mock(LocalParticipant::class.java)
.apply {
whenever(this.events).thenReturn(object : EventListenable<ParticipantEvent> {
override val events: SharedFlow<ParticipantEvent> = MutableSharedFlow()
})
whenever(this.events).thenReturn(
object : EventListenable<ParticipantEvent> {
override val events: SharedFlow<ParticipantEvent> = MutableSharedFlow()
},
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ class CallViewModel(

private suspend fun connectToRoom() {
try {
room.e2eeOptions = getE2EEOptions()
room.connect(
url = url,
token = token,
roomOptions = RoomOptions(e2eeOptions = getE2EEOptions()),
)

// Create and publish audio/video tracks
Expand Down

0 comments on commit c6646c3

Please sign in to comment.