正在显示
2 个修改的文件
包含
19 行增加
和
8 行删除
| @@ -34,7 +34,6 @@ constructor( | @@ -34,7 +34,6 @@ constructor( | ||
| 34 | @Named(InjectionNames.SIGNAL_JSON_ENABLED) | 34 | @Named(InjectionNames.SIGNAL_JSON_ENABLED) |
| 35 | private val useJson: Boolean, | 35 | private val useJson: Boolean, |
| 36 | ) : WebSocketListener() { | 36 | ) : WebSocketListener() { |
| 37 | - | ||
| 38 | var isConnected = false | 37 | var isConnected = false |
| 39 | private set | 38 | private set |
| 40 | private var currentWs: WebSocket? = null | 39 | private var currentWs: WebSocket? = null |
| @@ -44,7 +43,7 @@ constructor( | @@ -44,7 +43,7 @@ constructor( | ||
| 44 | url: String, | 43 | url: String, |
| 45 | token: String, | 44 | token: String, |
| 46 | ) { | 45 | ) { |
| 47 | - val wsUrlString = "$url/rtc?access_token=$token" | 46 | + val wsUrlString = "$url/rtc?access_token=$token&protocol=$PROTOCOL_VERSION" |
| 48 | Timber.i { "connecting to $wsUrlString" } | 47 | Timber.i { "connecting to $wsUrlString" } |
| 49 | 48 | ||
| 50 | val request = Request.Builder() | 49 | val request = Request.Builder() |
| @@ -304,16 +303,18 @@ constructor( | @@ -304,16 +303,18 @@ constructor( | ||
| 304 | const val SD_TYPE_ANSWER = "answer" | 303 | const val SD_TYPE_ANSWER = "answer" |
| 305 | const val SD_TYPE_OFFER = "offer" | 304 | const val SD_TYPE_OFFER = "offer" |
| 306 | const val SD_TYPE_PRANSWER = "pranswer" | 305 | const val SD_TYPE_PRANSWER = "pranswer" |
| 306 | + const val PROTOCOL_VERSION = 1; | ||
| 307 | 307 | ||
| 308 | private fun iceServer(url: String) = | 308 | private fun iceServer(url: String) = |
| 309 | PeerConnection.IceServer.builder(url).createIceServer() | 309 | PeerConnection.IceServer.builder(url).createIceServer() |
| 310 | 310 | ||
| 311 | + // more stun servers might slow it down, WebRTC recommends 3 max | ||
| 311 | val DEFAULT_ICE_SERVERS = listOf( | 312 | val DEFAULT_ICE_SERVERS = listOf( |
| 312 | iceServer("stun:stun.l.google.com:19302"), | 313 | iceServer("stun:stun.l.google.com:19302"), |
| 313 | iceServer("stun:stun1.l.google.com:19302"), | 314 | iceServer("stun:stun1.l.google.com:19302"), |
| 314 | - iceServer("stun:stun2.l.google.com:19302"), | ||
| 315 | - iceServer("stun:stun3.l.google.com:19302"), | ||
| 316 | - iceServer("stun:stun4.l.google.com:19302"), | 315 | +// iceServer("stun:stun2.l.google.com:19302"), |
| 316 | +// iceServer("stun:stun3.l.google.com:19302"), | ||
| 317 | +// iceServer("stun:stun4.l.google.com:19302"), | ||
| 317 | ) | 318 | ) |
| 318 | } | 319 | } |
| 319 | } | 320 | } |
| @@ -202,10 +202,12 @@ constructor( | @@ -202,10 +202,12 @@ constructor( | ||
| 202 | return | 202 | return |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | - val participantSid = streams.first().id | ||
| 206 | - val trackSid = track.id() | 205 | + var (participantSid, trackSid) = unpackStreamId(streams.first().id) |
| 206 | + if (trackSid == null) { | ||
| 207 | + trackSid = track.id() | ||
| 208 | + } | ||
| 207 | val participant = getOrCreateRemoteParticipant(participantSid) | 209 | val participant = getOrCreateRemoteParticipant(participantSid) |
| 208 | - participant.addSubscribedMediaTrack(track, trackSid) | 210 | + participant.addSubscribedMediaTrack(track, trackSid!!) |
| 209 | } | 211 | } |
| 210 | 212 | ||
| 211 | /** | 213 | /** |
| @@ -447,3 +449,11 @@ sealed class RoomException(message: String? = null, cause: Throwable? = null) : | @@ -447,3 +449,11 @@ sealed class RoomException(message: String? = null, cause: Throwable? = null) : | ||
| 447 | class ConnectException(message: String? = null, cause: Throwable? = null) : | 449 | class ConnectException(message: String? = null, cause: Throwable? = null) : |
| 448 | RoomException(message, cause) | 450 | RoomException(message, cause) |
| 449 | } | 451 | } |
| 452 | + | ||
| 453 | +internal fun unpackStreamId(packed: String): Pair<String, String?> { | ||
| 454 | + val parts = packed.split('|') | ||
| 455 | + if (parts.size != 2) { | ||
| 456 | + return Pair(packed, null) | ||
| 457 | + } | ||
| 458 | + return Pair(parts[0], parts[1]) | ||
| 459 | +} |
-
请 注册 或 登录 后发表评论