正在显示
3 个修改的文件
包含
45 行增加
和
4 行删除
| @@ -76,7 +76,7 @@ constructor( | @@ -76,7 +76,7 @@ constructor( | ||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | val lp = localParticipantFactory.create(response.participant) | 78 | val lp = localParticipantFactory.create(response.participant) |
| 79 | - lp.listener = this | 79 | + lp.internalListener = this |
| 80 | localParticipant = lp | 80 | localParticipant = lp |
| 81 | if (response.otherParticipantsList.isNotEmpty()) { | 81 | if (response.otherParticipantsList.isNotEmpty()) { |
| 82 | response.otherParticipantsList.forEach { | 82 | response.otherParticipantsList.forEach { |
| @@ -366,7 +366,7 @@ constructor( | @@ -366,7 +366,7 @@ constructor( | ||
| 366 | listener?.onFailedToConnect(this, error) | 366 | listener?.onFailedToConnect(this, error) |
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | - //------------------------------- RemoteParticipant.Listener --------------------------------// | 369 | + //------------------------------- ParticipantListener --------------------------------// |
| 370 | /** | 370 | /** |
| 371 | * This is called for both Local and Remote participants | 371 | * This is called for both Local and Remote participants |
| 372 | * @suppress | 372 | * @suppress |
| @@ -402,6 +402,20 @@ constructor( | @@ -402,6 +402,20 @@ constructor( | ||
| 402 | /** | 402 | /** |
| 403 | * @suppress | 403 | * @suppress |
| 404 | */ | 404 | */ |
| 405 | + override fun onTrackPublished(publication: LocalTrackPublication, participant: LocalParticipant) { | ||
| 406 | + listener?.onTrackPublished(publication, participant, this) | ||
| 407 | + } | ||
| 408 | + | ||
| 409 | + /** | ||
| 410 | + * @suppress | ||
| 411 | + */ | ||
| 412 | + override fun onTrackUnpublished(publication: LocalTrackPublication, participant: LocalParticipant) { | ||
| 413 | + listener?.onTrackUnpublished(publication, participant, this) | ||
| 414 | + } | ||
| 415 | + | ||
| 416 | + /** | ||
| 417 | + * @suppress | ||
| 418 | + */ | ||
| 405 | override fun onTrackSubscribed(track: Track, publication: RemoteTrackPublication, participant: RemoteParticipant) { | 419 | override fun onTrackSubscribed(track: Track, publication: RemoteTrackPublication, participant: RemoteParticipant) { |
| 406 | listener?.onTrackSubscribed(track, publication, participant, this) | 420 | listener?.onTrackSubscribed(track, publication, participant, this) |
| 407 | } | 421 | } |
| @@ -531,6 +545,16 @@ interface RoomListener { | @@ -531,6 +545,16 @@ interface RoomListener { | ||
| 531 | fun onTrackUnpublished(publication: TrackPublication, participant: RemoteParticipant, room: Room) {} | 545 | fun onTrackUnpublished(publication: TrackPublication, participant: RemoteParticipant, room: Room) {} |
| 532 | 546 | ||
| 533 | /** | 547 | /** |
| 548 | + * When a new track is published to room after the local participant has joined. | ||
| 549 | + */ | ||
| 550 | + fun onTrackPublished(publication: LocalTrackPublication, participant: LocalParticipant, room: Room) {} | ||
| 551 | + | ||
| 552 | + /** | ||
| 553 | + * [LocalParticipant] has unpublished a track | ||
| 554 | + */ | ||
| 555 | + fun onTrackUnpublished(publication: LocalTrackPublication, participant: LocalParticipant, room: Room) {} | ||
| 556 | + | ||
| 557 | + /** | ||
| 534 | * The [LocalParticipant] has subscribed to a new track. This event will always fire as | 558 | * The [LocalParticipant] has subscribed to a new track. This event will always fire as |
| 535 | * long as new tracks are ready for use. | 559 | * long as new tracks are ready for use. |
| 536 | */ | 560 | */ |
| @@ -34,7 +34,9 @@ internal constructor( | @@ -34,7 +34,9 @@ internal constructor( | ||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | private val localTrackPublications | 36 | private val localTrackPublications |
| 37 | - get() = tracks.values.toList() | 37 | + get() = tracks.values |
| 38 | + .mapNotNull { it as? LocalTrackPublication } | ||
| 39 | + .toList() | ||
| 38 | 40 | ||
| 39 | /** | 41 | /** |
| 40 | * Creates an audio track, recording audio through the microphone with the given [options]. | 42 | * Creates an audio track, recording audio through the microphone with the given [options]. |
| @@ -133,6 +135,7 @@ internal constructor( | @@ -133,6 +135,7 @@ internal constructor( | ||
| 133 | val publication = LocalTrackPublication(trackInfo, track, this) | 135 | val publication = LocalTrackPublication(trackInfo, track, this) |
| 134 | addTrackPublication(publication) | 136 | addTrackPublication(publication) |
| 135 | publishListener?.onPublishSuccess(publication) | 137 | publishListener?.onPublishSuccess(publication) |
| 138 | + internalListener?.onTrackPublished(publication, this) | ||
| 136 | } | 139 | } |
| 137 | 140 | ||
| 138 | suspend fun publishVideoTrack( | 141 | suspend fun publishVideoTrack( |
| @@ -180,6 +183,7 @@ internal constructor( | @@ -180,6 +183,7 @@ internal constructor( | ||
| 180 | val publication = LocalTrackPublication(trackInfo, track, this) | 183 | val publication = LocalTrackPublication(trackInfo, track, this) |
| 181 | addTrackPublication(publication) | 184 | addTrackPublication(publication) |
| 182 | publishListener?.onPublishSuccess(publication) | 185 | publishListener?.onPublishSuccess(publication) |
| 186 | + internalListener?.onTrackPublished(publication, this) | ||
| 183 | } | 187 | } |
| 184 | 188 | ||
| 185 | private fun computeVideoEncodings( | 189 | private fun computeVideoEncodings( |
| @@ -282,7 +286,8 @@ internal constructor( | @@ -282,7 +286,8 @@ internal constructor( | ||
| 282 | when (publication.kind) { | 286 | when (publication.kind) { |
| 283 | Track.Kind.AUDIO -> audioTracks.remove(sid) | 287 | Track.Kind.AUDIO -> audioTracks.remove(sid) |
| 284 | Track.Kind.VIDEO -> videoTracks.remove(sid) | 288 | Track.Kind.VIDEO -> videoTracks.remove(sid) |
| 285 | - else -> {} | 289 | + else -> { |
| 290 | + } | ||
| 286 | } | 291 | } |
| 287 | val senders = engine.publisher.peerConnection.senders ?: return | 292 | val senders = engine.publisher.peerConnection.senders ?: return |
| 288 | for (sender in senders) { | 293 | for (sender in senders) { |
| @@ -292,6 +297,7 @@ internal constructor( | @@ -292,6 +297,7 @@ internal constructor( | ||
| 292 | } | 297 | } |
| 293 | } | 298 | } |
| 294 | track.stop() | 299 | track.stop() |
| 300 | + internalListener?.onTrackUnpublished(publication, this) | ||
| 295 | } | 301 | } |
| 296 | 302 | ||
| 297 | /** | 303 | /** |
| @@ -123,6 +123,17 @@ interface ParticipantListener { | @@ -123,6 +123,17 @@ interface ParticipantListener { | ||
| 123 | fun onTrackUnmuted(publication: TrackPublication, participant: Participant) {} | 123 | fun onTrackUnmuted(publication: TrackPublication, participant: Participant) {} |
| 124 | 124 | ||
| 125 | 125 | ||
| 126 | + // local participants | ||
| 127 | + /** | ||
| 128 | + * When a new track is published by the local participant. | ||
| 129 | + */ | ||
| 130 | + fun onTrackPublished(publication: LocalTrackPublication, participant: LocalParticipant) {} | ||
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * A [LocalParticipant] has unpublished a track | ||
| 134 | + */ | ||
| 135 | + fun onTrackUnpublished(publication: LocalTrackPublication, participant: LocalParticipant) {} | ||
| 136 | + | ||
| 126 | // remote participants | 137 | // remote participants |
| 127 | /** | 138 | /** |
| 128 | * When a new track is published to room after the local participant has joined. | 139 | * When a new track is published to room after the local participant has joined. |
-
请 注册 或 登录 后发表评论