正在显示
2 个修改的文件
包含
29 行增加
和
27 行删除
| @@ -48,13 +48,6 @@ internal constructor( | @@ -48,13 +48,6 @@ internal constructor( | ||
| 48 | .mapNotNull { it as? LocalTrackPublication } | 48 | .mapNotNull { it as? LocalTrackPublication } |
| 49 | .toList() | 49 | .toList() |
| 50 | 50 | ||
| 51 | - private var isReconnecting = false | ||
| 52 | - | ||
| 53 | - /** | ||
| 54 | - * Holds on to publishes that need to be republished after a full reconnect. | ||
| 55 | - */ | ||
| 56 | - private var publishes = mutableMapOf<Track, TrackPublishOptions>() | ||
| 57 | - | ||
| 58 | /** | 51 | /** |
| 59 | * Creates an audio track, recording audio through the microphone with the given [options]. | 52 | * Creates an audio track, recording audio through the microphone with the given [options]. |
| 60 | * | 53 | * |
| @@ -214,18 +207,15 @@ internal constructor( | @@ -214,18 +207,15 @@ internal constructor( | ||
| 214 | ), | 207 | ), |
| 215 | publishListener: PublishListener? = null | 208 | publishListener: PublishListener? = null |
| 216 | ) { | 209 | ) { |
| 217 | - val published = publishTrackImpl( | ||
| 218 | - track, | 210 | + publishTrackImpl( |
| 211 | + track = track, | ||
| 212 | + options = options, | ||
| 219 | requestConfig = { | 213 | requestConfig = { |
| 220 | disableDtx = !options.dtx | 214 | disableDtx = !options.dtx |
| 221 | source = LivekitModels.TrackSource.MICROPHONE | 215 | source = LivekitModels.TrackSource.MICROPHONE |
| 222 | }, | 216 | }, |
| 223 | publishListener = publishListener, | 217 | publishListener = publishListener, |
| 224 | ) | 218 | ) |
| 225 | - | ||
| 226 | - if (published) { | ||
| 227 | - publishes[track] = options | ||
| 228 | - } | ||
| 229 | } | 219 | } |
| 230 | 220 | ||
| 231 | suspend fun publishVideoTrack( | 221 | suspend fun publishVideoTrack( |
| @@ -238,8 +228,9 @@ internal constructor( | @@ -238,8 +228,9 @@ internal constructor( | ||
| 238 | val videoLayers = | 228 | val videoLayers = |
| 239 | EncodingUtils.videoLayersFromEncodings(track.dimensions.width, track.dimensions.height, encodings) | 229 | EncodingUtils.videoLayersFromEncodings(track.dimensions.width, track.dimensions.height, encodings) |
| 240 | 230 | ||
| 241 | - val published = publishTrackImpl( | ||
| 242 | - track, | 231 | + publishTrackImpl( |
| 232 | + track = track, | ||
| 233 | + options = options, | ||
| 243 | requestConfig = { | 234 | requestConfig = { |
| 244 | width = track.dimensions.width | 235 | width = track.dimensions.width |
| 245 | height = track.dimensions.height | 236 | height = track.dimensions.height |
| @@ -253,10 +244,6 @@ internal constructor( | @@ -253,10 +244,6 @@ internal constructor( | ||
| 253 | encodings = encodings, | 244 | encodings = encodings, |
| 254 | publishListener = publishListener | 245 | publishListener = publishListener |
| 255 | ) | 246 | ) |
| 256 | - | ||
| 257 | - if (published) { | ||
| 258 | - publishes[track] = options | ||
| 259 | - } | ||
| 260 | } | 247 | } |
| 261 | 248 | ||
| 262 | 249 | ||
| @@ -265,6 +252,7 @@ internal constructor( | @@ -265,6 +252,7 @@ internal constructor( | ||
| 265 | */ | 252 | */ |
| 266 | private suspend fun publishTrackImpl( | 253 | private suspend fun publishTrackImpl( |
| 267 | track: Track, | 254 | track: Track, |
| 255 | + options: TrackPublishOptions, | ||
| 268 | requestConfig: LivekitRtc.AddTrackRequest.Builder.() -> Unit, | 256 | requestConfig: LivekitRtc.AddTrackRequest.Builder.() -> Unit, |
| 269 | encodings: List<RtpParameters.Encoding> = emptyList(), | 257 | encodings: List<RtpParameters.Encoding> = emptyList(), |
| 270 | publishListener: PublishListener? = null | 258 | publishListener: PublishListener? = null |
| @@ -306,7 +294,12 @@ internal constructor( | @@ -306,7 +294,12 @@ internal constructor( | ||
| 306 | 294 | ||
| 307 | // TODO: enable setting preferred codec | 295 | // TODO: enable setting preferred codec |
| 308 | 296 | ||
| 309 | - val publication = LocalTrackPublication(trackInfo, track, this) | 297 | + val publication = LocalTrackPublication( |
| 298 | + info = trackInfo, | ||
| 299 | + track = track, | ||
| 300 | + participant = this, | ||
| 301 | + options = options, | ||
| 302 | + ) | ||
| 310 | addTrackPublication(publication) | 303 | addTrackPublication(publication) |
| 311 | 304 | ||
| 312 | publishListener?.onPublishSuccess(publication) | 305 | publishListener?.onPublishSuccess(publication) |
| @@ -402,15 +395,13 @@ internal constructor( | @@ -402,15 +395,13 @@ internal constructor( | ||
| 402 | engine.updateSubscriptionPermissions(allParticipantsAllowed, participantTrackPermissions) | 395 | engine.updateSubscriptionPermissions(allParticipantsAllowed, participantTrackPermissions) |
| 403 | } | 396 | } |
| 404 | 397 | ||
| 405 | - fun unpublishTrack(track: Track) { | 398 | + fun unpublishTrack(track: Track, stopOnUnpublish: Boolean = true) { |
| 406 | val publication = localTrackPublications.firstOrNull { it.track == track } | 399 | val publication = localTrackPublications.firstOrNull { it.track == track } |
| 407 | if (publication === null) { | 400 | if (publication === null) { |
| 408 | LKLog.d { "this track was never published." } | 401 | LKLog.d { "this track was never published." } |
| 409 | return | 402 | return |
| 410 | } | 403 | } |
| 411 | 404 | ||
| 412 | - publishes.remove(track) | ||
| 413 | - | ||
| 414 | val sid = publication.sid | 405 | val sid = publication.sid |
| 415 | tracks = tracks.toMutableMap().apply { remove(sid) } | 406 | tracks = tracks.toMutableMap().apply { remove(sid) } |
| 416 | 407 | ||
| @@ -423,7 +414,9 @@ internal constructor( | @@ -423,7 +414,9 @@ internal constructor( | ||
| 423 | } | 414 | } |
| 424 | } | 415 | } |
| 425 | } | 416 | } |
| 417 | + if (stopOnUnpublish) { | ||
| 426 | track.stop() | 418 | track.stop() |
| 419 | + } | ||
| 427 | internalListener?.onTrackUnpublished(publication, this) | 420 | internalListener?.onTrackUnpublished(publication, this) |
| 428 | eventBus.postEvent(ParticipantEvent.LocalTrackUnpublished(this, publication), scope) | 421 | eventBus.postEvent(ParticipantEvent.LocalTrackUnpublished(this, publication), scope) |
| 429 | } | 422 | } |
| @@ -536,14 +529,21 @@ internal constructor( | @@ -536,14 +529,21 @@ internal constructor( | ||
| 536 | } | 529 | } |
| 537 | 530 | ||
| 538 | suspend fun republishTracks() { | 531 | suspend fun republishTracks() { |
| 539 | - for ((track, options) in publishes) { | 532 | + val republishes = localTrackPublications |
| 533 | + | ||
| 534 | + for (pub in republishes) { | ||
| 535 | + val track = pub.track ?: continue | ||
| 536 | + unpublishTrack(track, false) | ||
| 537 | + // Cannot publish muted tracks. | ||
| 538 | + if (!pub.muted) { | ||
| 540 | when (track) { | 539 | when (track) { |
| 541 | - is LocalAudioTrack -> publishAudioTrack(track, options as AudioTrackPublishOptions, null) | ||
| 542 | - is LocalVideoTrack -> publishVideoTrack(track, options as VideoTrackPublishOptions, null) | 540 | + is LocalAudioTrack -> publishAudioTrack(track, pub.options as AudioTrackPublishOptions, null) |
| 541 | + is LocalVideoTrack -> publishVideoTrack(track, pub.options as VideoTrackPublishOptions, null) | ||
| 543 | else -> throw IllegalStateException("LocalParticipant has a non local track publish?") | 542 | else -> throw IllegalStateException("LocalParticipant has a non local track publish?") |
| 544 | } | 543 | } |
| 545 | } | 544 | } |
| 546 | } | 545 | } |
| 546 | + } | ||
| 547 | 547 | ||
| 548 | fun cleanup() { | 548 | fun cleanup() { |
| 549 | for (pub in tracks.values) { | 549 | for (pub in tracks.values) { |
| 1 | package io.livekit.android.room.track | 1 | package io.livekit.android.room.track |
| 2 | 2 | ||
| 3 | import io.livekit.android.room.participant.LocalParticipant | 3 | import io.livekit.android.room.participant.LocalParticipant |
| 4 | +import io.livekit.android.room.participant.TrackPublishOptions | ||
| 4 | import livekit.LivekitModels | 5 | import livekit.LivekitModels |
| 5 | 6 | ||
| 6 | class LocalTrackPublication( | 7 | class LocalTrackPublication( |
| 7 | info: LivekitModels.TrackInfo, | 8 | info: LivekitModels.TrackInfo, |
| 8 | track: Track, | 9 | track: Track, |
| 9 | - participant: LocalParticipant | 10 | + participant: LocalParticipant, |
| 11 | + val options: TrackPublishOptions, | ||
| 10 | ) : TrackPublication(info, track, participant) { | 12 | ) : TrackPublication(info, track, participant) { |
| 11 | 13 | ||
| 12 | /** | 14 | /** |
-
请 注册 或 登录 后发表评论