This message was deleted.
# helpdesk
s
This message was deleted.
👍 1
❤️ 1
d
@famous-oxygen-25341 how was the TrackPublication created? could you share the code used for creation? CC: @eager-raincoat-52616
f
@dry-elephant-14928 @eager-raincoat-52616 I made the flow of livekit's audioTracks and videoTracks wrapped as shown below.
Copy code
[TestParicipant class]

    val audioTracks: StateFlow<List<Pair<TestTrackPublication, TestTrack>>>
        get() {
            return participant::audioTracks.flow
                .map {
                    it.map { (trackPublication, track) ->
                      
                        val testTrackPublication = when (trackPublication) {
                            is LocalTrackPublication -> {
                                TestLocalTrackPublication(trackPublication)
                            }

                            is RemoteTrackPublication -> {
                                TestRemoteTrackPublication(trackPublication)
                            }

                            else -> {
                                TestTrackPublication(trackPublication)
                            }
                        }

                        val testTrack = when (track) {
                            is AudioTrack -> {
                                TestAudioTrack(track)
                            }

                            is VideoTrack -> {
                                TestVideoTrack(track)
                            }

                            else -> {
                                TestTrack(track)
                            }
                        }
                        testTrackPublication to testTrack
                    }
                }
                .stateIn(delegateScope, SharingStarted.Eagerly, emptyList())
        }
Copy code
class TestRemoteTrackPublication(private val remoteTrackPublication: RemoteTrackPublication): TestTrackPublication(remoteTrackPublication) {
    override val track: Flow<TestTrack?>
        get() {
            return remoteTrackPublication::track.flow.map {
                TestTrack(it)
            }
        }
}
Copy code
open class TestTrackPublication(private val trackPublication: TrackPublication) {
   val muted: Flow<Boolean>
        get() {
            trackPublication::muted.flow.map {
                 it
             }           
        }

    var source: Track.Source = trackPublication.source
        get() = trackPublication.source

    var kind: Track.Kind = trackPublication.kind
        get() = trackPublication.kind

    var name: String = trackPublication.name

    open val track: Flow<TestTrack?>
        get() {
            return trackPublication::track.flow.map {
                TestTrack(it)
            }
        }
}
I got this error when accessing trackPublication::muted in TestTrackPublication. java.lang.NullPointerException: null cannot be cast to non-null type kotlinx.coroutines.flow.StateFlow<T of io.fflite.webrtc.android.util.FlowDelegateKt.<get-flow>>
Copy code
coroutineScope?.launch {
            // participant is TestParticipant and audioTracks StateFlow<List<Pair<TestTrackPublication, TestTrack>>
            participant.audioTracks 
                .flatMapLatest { tracks ->
                    val audioTrack = tracks.firstOrNull()?.first
                    audioTrack?.muted ?: flowOf(true)
                }
                .collect { muted ->                 
                    viewBinding.muteIndicator.visibility = if (muted == true) View.VISIBLE else View.INVISIBLE
                }
        }
The problem was in the import. I created a FlowDelegate class in another package that is same to the FlowDelegate in livekit. The problem was caused by the .flow from the other package being imported while accessing a property of livekit's class.
👍 2
d
Thanks for the update @famous-oxygen-25341! CC: @eager-raincoat-52616
👍 1