I've implemented Android client using Twilio SDK to do video calls. It works as expected but I found an edge case which I can not figure out how to fix. Here is essence of video call code:
val connectionOptions = ConnectOptions.Builder(accessToken)
.audioTracks(listOf(audioManager.getLocalAudioTrack()))
.roomName(roomId)
.build()
val roomListener = RoomListener()
Video.connect(androidContext, connectOptions, roomListener)
class RoomEventListener : Room.Listener {
override fun onParticipantDisconnected(room: Room, remoteParticipant: RemoteParticipant) {
// remove participant from the screen, unsubscribe from events
}
override fun onConnectFailure(room: Room, twilioException: TwilioException) {
exitScreenWithErrorMessage(R.string.video_consult_room_connection_error)
}
override fun onReconnected(room: Room) {
_shouldShowReconnectionActivity.value = false
}
override fun onParticipantConnected(room: Room, remoteParticipant: RemoteParticipant) {
onRemoteParticipantConnected(remoteParticipant)
}
override fun onConnected(room: Room) {
_shouldShowConnectionActivity.value = false
this@VideoCallViewModel.room = room
room.remoteParticipants.forEach { onRemoteParticipantConnected(it) }
determineMainParticipant()
onLocalParticipantConnected(room)
}
override fun onDisconnected(room: Room, twilioException: TwilioException?) {
exitVideoConsultScreen()
}
override fun onReconnecting(room: Room, twilioException: TwilioException) {
_shouldShowReconnectionActivity.value = true
}
}
Test case:
- Bob joins video call using Android phone
- Jane joins same video call from any device (iOS, web, Android)
When Jane loses connection (i.e. turn off internet)
- Then Bob sees for 1-2 minutes reconnecting (programmatically "onReconnecting" callback triggered)
- [Actual] And Bob disconnected from room (in logs I see Media connection failed or Media activity ceased with error code 53405)
- [Expected] Bob stays at the room.
I'm not sure why under such conditions Android client has been disconnected (We tested it on different devices with Android 8/9).
Couple more details:
- If Jane exits room using "End call" button (so
room.disconnect()
code from Twilio SDK has been called) then Bob stays in the room. - When Bob using iOS device (implementation of iOS and Android quite the same) then described use case passes.
- We tried 5.0.1 and 5.1.0 version of
com.twilio:video-android
library. - I noticed Known Issue for Android Twilio Video library in Release notes and I'm not sure can it affects described use case or not:
Unpublishing and republishing a
LocalAudioTrack
orLocalVideoTrack
might not be seen by Participants. As a result, tracks published after aRoom.State.RECONNECTED
event might not be subscribed to by aRemoteParticipant
.