Track.kt
1.8 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
package io.livekit.android.room.track
import org.webrtc.DataChannel
import org.webrtc.MediaStreamTrack
class Track(name: String, state: State) {
var name = name
internal set
var state = state
internal set
inline class Sid(val sid: String)
inline class Cid(val cid: String)
enum class Priority {
STANDARD, HIGH, LOW;
}
enum class State {
ENDED, LIVE, NONE;
}
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?, cause: Throwable?) : Exception(message, cause) {
class InvalidTrackTypeException(message: String?, cause: Throwable?) :
TrackException(message, cause)
class DuplicateTrackException(message: String?, cause: Throwable?) :
TrackException(message, cause)
class InvalidTrackStateException(message: String?, cause: Throwable?) :
TrackException(message, cause)
class MediaException(message: String?, cause: Throwable?) : TrackException(message, cause)
class PublishException(message: String?, cause: Throwable?) : TrackException(message, cause)
}