Committed by
GitHub
Don't override client provide ice servers (#193)
正在显示
2 个修改的文件
包含
27 行增加
和
7 行删除
| @@ -8,7 +8,18 @@ data class ConnectOptions( | @@ -8,7 +8,18 @@ data class ConnectOptions( | ||
| 8 | /** Auto subscribe to room tracks upon connect, defaults to true */ | 8 | /** Auto subscribe to room tracks upon connect, defaults to true */ |
| 9 | val autoSubscribe: Boolean = true, | 9 | val autoSubscribe: Boolean = true, |
| 10 | 10 | ||
| 11 | + /** | ||
| 12 | + * A user-provided list of ice servers. This will be merged into | ||
| 13 | + * the ice servers in [rtcConfig] if it is also provided. | ||
| 14 | + */ | ||
| 11 | val iceServers: List<PeerConnection.IceServer>? = null, | 15 | val iceServers: List<PeerConnection.IceServer>? = null, |
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * A user-provided RTCConfiguration to override options. | ||
| 19 | + * | ||
| 20 | + * Note: LiveKit requires [PeerConnection.SdpSemantics.UNIFIED_PLAN] | ||
| 21 | + * and a mutable list should be provided for iceServers constructor. | ||
| 22 | + * */ | ||
| 12 | val rtcConfig: PeerConnection.RTCConfiguration? = null, | 23 | val rtcConfig: PeerConnection.RTCConfiguration? = null, |
| 13 | /** | 24 | /** |
| 14 | * capture and publish audio track on connect, defaults to false | 25 | * capture and publish audio track on connect, defaults to false |
| @@ -173,9 +173,7 @@ internal constructor( | @@ -173,9 +173,7 @@ internal constructor( | ||
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | // update ICE servers before creating PeerConnection | 175 | // update ICE servers before creating PeerConnection |
| 176 | - val iceServers = if (connectOptions?.iceServers != null) { | ||
| 177 | - connectOptions.iceServers | ||
| 178 | - } else { | 176 | + val iceServers = run { |
| 179 | val servers = mutableListOf<PeerConnection.IceServer>() | 177 | val servers = mutableListOf<PeerConnection.IceServer>() |
| 180 | for (serverInfo in joinResponse.iceServersList) { | 178 | for (serverInfo in joinResponse.iceServersList) { |
| 181 | val username = serverInfo.username ?: "" | 179 | val username = serverInfo.username ?: "" |
| @@ -197,10 +195,21 @@ internal constructor( | @@ -197,10 +195,21 @@ internal constructor( | ||
| 197 | 195 | ||
| 198 | // Setup peer connections | 196 | // Setup peer connections |
| 199 | val rtcConfig = connectOptions?.rtcConfig?.apply { | 197 | val rtcConfig = connectOptions?.rtcConfig?.apply { |
| 200 | - val mergedServers = this.iceServers.toMutableList() | ||
| 201 | - iceServers.forEach { server -> | ||
| 202 | - if (!mergedServers.contains(server)) { | ||
| 203 | - mergedServers.add(server) | 198 | + val mergedServers = this.iceServers |
| 199 | + if (connectOptions.iceServers != null) { | ||
| 200 | + connectOptions.iceServers.forEach { server -> | ||
| 201 | + if (!mergedServers.contains(server)) { | ||
| 202 | + mergedServers.add(server) | ||
| 203 | + } | ||
| 204 | + } | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + // Only use server-provided servers if user doesn't provide any. | ||
| 208 | + if (mergedServers.isEmpty()) { | ||
| 209 | + iceServers.forEach { server -> | ||
| 210 | + if (!mergedServers.contains(server)) { | ||
| 211 | + mergedServers.add(server) | ||
| 212 | + } | ||
| 204 | } | 213 | } |
| 205 | } | 214 | } |
| 206 | } | 215 | } |
-
请 注册 或 登录 后发表评论