Seong-eun Jin
Committed by GitHub

Fixed primarySpeaker videoTrack, mute observer (#98)

* Add private keyword

* Set primarySpeaker muteIndicator visibility

* Fixed primarySpeaker videoTrack, mute observer
@@ -77,33 +77,19 @@ class CallActivity : AppCompatActivity() { @@ -77,33 +77,19 @@ class CallActivity : AppCompatActivity() {
77 // Observe primary speaker changes 77 // Observe primary speaker changes
78 emitAll(viewModel.primarySpeaker) 78 emitAll(viewModel.primarySpeaker)
79 }.flatMapLatest { primarySpeaker -> 79 }.flatMapLatest { primarySpeaker ->
80 - // Update new primary speaker identity  
81 - binding.identityText.text = primarySpeaker?.identity  
82 -  
83 - if (primarySpeaker != null) {  
84 - primarySpeaker::audioTracks.flow  
85 - .flatMapLatest { tracks ->  
86 - val audioTrack = tracks.firstOrNull()?.first  
87 - if (audioTrack != null) {  
88 - audioTrack::muted.flow  
89 - } else {  
90 - flowOf(true)  
91 - }  
92 - }  
93 - .collect { muted ->  
94 - binding.muteIndicator.visibility = if (muted) View.VISIBLE else View.INVISIBLE  
95 - }  
96 - }  
97 -  
98 - // observe videoTracks changes.  
99 if (primarySpeaker != null) { 80 if (primarySpeaker != null) {
100 - primarySpeaker::videoTracks.flow  
101 - .map { primarySpeaker to it } 81 + flowOf(primarySpeaker)
102 } else { 82 } else {
103 emptyFlow() 83 emptyFlow()
104 } 84 }
105 - }.flatMapLatest { (participant, videoTracks) -> 85 + }.collect { participant ->
  86 + // Update new primary speaker identity
  87 + binding.identityText.text = participant.identity
106 88
  89 + // observe videoTracks changes.
  90 + val videoTrackFlow = participant::videoTracks.flow
  91 + .map { participant to it }
  92 + .flatMapLatest { (participant, videoTracks) ->
107 // Prioritize any screenshare streams. 93 // Prioritize any screenshare streams.
108 val trackPublication = participant.getTrackPublication(Track.Source.SCREEN_SHARE) 94 val trackPublication = participant.getTrackPublication(Track.Source.SCREEN_SHARE)
109 ?: participant.getTrackPublication(Track.Source.CAMERA) 95 ?: participant.getTrackPublication(Track.Source.CAMERA)
@@ -111,7 +97,22 @@ class CallActivity : AppCompatActivity() { @@ -111,7 +97,22 @@ class CallActivity : AppCompatActivity() {
111 ?: return@flatMapLatest emptyFlow() 97 ?: return@flatMapLatest emptyFlow()
112 98
113 trackPublication::track.flow 99 trackPublication::track.flow
114 - }.collect { videoTrack -> 100 + }
  101 +
  102 + // observe audioTracks changes.
  103 + val mutedFlow = participant::audioTracks.flow
  104 + .flatMapLatest { tracks ->
  105 + val audioTrack = tracks.firstOrNull()?.first
  106 + if (audioTrack != null) {
  107 + audioTrack::muted.flow
  108 + } else {
  109 + flowOf(true)
  110 + }
  111 + }
  112 +
  113 + combine(videoTrackFlow, mutedFlow) { videoTrack, muted ->
  114 + videoTrack to muted
  115 + }.collect { (videoTrack, muted) ->
115 // Cleanup old video track 116 // Cleanup old video track
116 val oldVideoTrack = binding.speakerVideoView.tag as? VideoTrack 117 val oldVideoTrack = binding.speakerVideoView.tag as? VideoTrack
117 oldVideoTrack?.removeRenderer(binding.speakerVideoView) 118 oldVideoTrack?.removeRenderer(binding.speakerVideoView)
@@ -124,6 +125,9 @@ class CallActivity : AppCompatActivity() { @@ -124,6 +125,9 @@ class CallActivity : AppCompatActivity() {
124 binding.speakerVideoView.visibility = View.INVISIBLE 125 binding.speakerVideoView.visibility = View.INVISIBLE
125 } 126 }
126 binding.speakerVideoView.tag = videoTrack 127 binding.speakerVideoView.tag = videoTrack
  128 +
  129 + binding.muteIndicator.visibility = if (muted) View.VISIBLE else View.INVISIBLE
  130 + }
127 } 131 }
128 } 132 }
129 133