Track.kt
1.9 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package io.livekit.android.room.track
import livekit.LivekitModels
import org.webrtc.DataChannel
import org.webrtc.MediaStreamTrack
open class Track(name: String, kind: LivekitModels.TrackType) {
var name = name
internal set
var kind = kind
internal set
var state: State = State.NONE
enum class State {
ENDED, LIVE, NONE;
}
open fun stop() {
// subclasses override to provide stop behavior
}
companion object {
fun stateFromRTCMediaTrackState(trackState: MediaStreamTrack.State): State {
return when (trackState) {
MediaStreamTrack.State.ENDED -> State.ENDED
MediaStreamTrack.State.LIVE -> State.LIVE
}
}
fun stateFromRTCDataChannelState(dataChannelState: DataChannel.State): State {
return when (dataChannelState) {
DataChannel.State.CONNECTING,
DataChannel.State.OPEN -> {
State.LIVE
}
DataChannel.State.CLOSING,
DataChannel.State.CLOSED -> {
State.ENDED
}
}
}
}
}
sealed class TrackException(message: String? = null, cause: Throwable? = null) :
Exception(message, cause) {
class InvalidTrackTypeException(message: String? = null, cause: Throwable? = null) :
TrackException(message, cause)
class DuplicateTrackException(message: String? = null, cause: Throwable? = null) :
TrackException(message, cause)
class InvalidTrackStateException(message: String? = null, cause: Throwable? = null) :
TrackException(message, cause)
class MediaException(message: String? = null, cause: Throwable? = null) :
TrackException(message, cause)
class PublishException(message: String? = null, cause: Throwable? = null) :
TrackException(message, cause)
}