David Liu

Don't wait for ice connection onJoin to fix race condition

@@ -33,16 +33,7 @@ constructor( @@ -33,16 +33,7 @@ constructor(
33 33
34 var listener: Listener? = null 34 var listener: Listener? = null
35 var rtcConnected: Boolean = false 35 var rtcConnected: Boolean = false
36 - var joinResponse: LivekitRtc.JoinResponse? = null  
37 var iceConnected: Boolean = false 36 var iceConnected: Boolean = false
38 - set(value) {  
39 - field = value  
40 - val savedJoinResponse = joinResponse  
41 - if (field && savedJoinResponse != null) {  
42 - listener?.onJoin(savedJoinResponse)  
43 - joinResponse = null  
44 - }  
45 - }  
46 private val pendingTrackResolvers: MutableMap<String, Continuation<LivekitModels.TrackInfo>> = 37 private val pendingTrackResolvers: MutableMap<String, Continuation<LivekitModels.TrackInfo>> =
47 mutableMapOf() 38 mutableMapOf()
48 39
@@ -145,7 +136,6 @@ constructor( @@ -145,7 +136,6 @@ constructor(
145 } 136 }
146 137
147 override fun onJoin(info: LivekitRtc.JoinResponse) { 138 override fun onJoin(info: LivekitRtc.JoinResponse) {
148 - joinResponse = info  
149 139
150 val iceServers = mutableListOf<PeerConnection.IceServer>() 140 val iceServers = mutableListOf<PeerConnection.IceServer>()
151 for(serverInfo in info.iceServersList){ 141 for(serverInfo in info.iceServersList){
@@ -163,7 +153,6 @@ constructor( @@ -163,7 +153,6 @@ constructor(
163 if(iceServers.isEmpty()){ 153 if(iceServers.isEmpty()){
164 iceServers.addAll(RTCClient.DEFAULT_ICE_SERVERS) 154 iceServers.addAll(RTCClient.DEFAULT_ICE_SERVERS)
165 } 155 }
166 -  
167 info.iceServersList.forEach { 156 info.iceServersList.forEach {
168 Timber.e{ "username = \"${it.username}\""} 157 Timber.e{ "username = \"${it.username}\""}
169 Timber.e{ "credential = \"${it.credential}\""} 158 Timber.e{ "credential = \"${it.credential}\""}
@@ -172,6 +161,7 @@ constructor( @@ -172,6 +161,7 @@ constructor(
172 Timber.e{" $it"} 161 Timber.e{" $it"}
173 } 162 }
174 } 163 }
  164 + listener?.onJoin(info)
175 165
176 val rtcConfig = PeerConnection.RTCConfiguration(iceServers).apply { 166 val rtcConfig = PeerConnection.RTCConfiguration(iceServers).apply {
177 sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN 167 sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN
@@ -80,6 +80,7 @@ constructor( @@ -80,6 +80,7 @@ constructor(
80 listener?.onParticipantDisconnected(this, removedParticipant) 80 listener?.onParticipantDisconnected(this, removedParticipant)
81 } 81 }
82 82
  83 + @Synchronized
83 private fun getOrCreateRemoteParticipant( 84 private fun getOrCreateRemoteParticipant(
84 sid: String, 85 sid: String,
85 info: LivekitModels.ParticipantInfo? = null 86 info: LivekitModels.ParticipantInfo? = null
@@ -157,6 +158,8 @@ constructor( @@ -157,6 +158,8 @@ constructor(
157 158
158 if (!response.hasParticipant()) { 159 if (!response.hasParticipant()) {
159 listener?.onFailedToConnect(this, RoomException.ConnectException("server didn't return any participants")) 160 listener?.onFailedToConnect(this, RoomException.ConnectException("server didn't return any participants"))
  161 + connectContinuation?.resume(Unit)
  162 + connectContinuation = null
160 return 163 return
161 } 164 }
162 165