LocalTrackPublication.kt
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package io.livekit.android.room.track
import io.livekit.android.room.participant.LocalParticipant
import livekit.LivekitModels
class LocalTrackPublication(
info: LivekitModels.TrackInfo,
track: Track? = null,
participant: LocalParticipant
) : TrackPublication(info, track, participant) {
/**
* Mute or unmute the current track. Muting the track would stop audio or video from being
* transmitted to the server, and notify other participants in the room.
*/
fun setMuted(muted: Boolean) {
if (muted == this.muted) {
return
}
val mediaTrack = track as? MediaTrack ?: return
mediaTrack.rtcTrack.setEnabled(!muted)
this.muted = muted
// send updates to server
val participant = this.participant as? LocalParticipant ?: return
participant.engine.updateMuteStatus(sid, muted)
if (muted) {
participant.listener?.onTrackMuted(this, participant)
participant.internalListener?.onTrackMuted(this, participant)
} else {
participant.listener?.onTrackUnmuted(this, participant)
participant.internalListener?.onTrackUnmuted(this, participant)
}
}
}