mirror of
https://github.com/livekit/livekit.git
synced 2026-04-05 12:26:07 +00:00
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package streamallocator
|
|
|
|
import (
|
|
"github.com/livekit/protocol/livekit"
|
|
)
|
|
|
|
// ------------------------------------------------
|
|
|
|
type StreamState int
|
|
|
|
const (
|
|
StreamStateActive StreamState = iota
|
|
StreamStatePaused
|
|
)
|
|
|
|
func (s StreamState) String() string {
|
|
switch s {
|
|
case StreamStateActive:
|
|
return "active"
|
|
case StreamStatePaused:
|
|
return "paused"
|
|
default:
|
|
return "unknown"
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------
|
|
|
|
type StreamStateInfo struct {
|
|
ParticipantID livekit.ParticipantID
|
|
TrackID livekit.TrackID
|
|
State StreamState
|
|
}
|
|
|
|
type StreamStateUpdate struct {
|
|
StreamStates []*StreamStateInfo
|
|
}
|
|
|
|
func NewStreamStateUpdate() *StreamStateUpdate {
|
|
return &StreamStateUpdate{}
|
|
}
|
|
|
|
func (s *StreamStateUpdate) HandleStreamingChange(isPaused bool, track *Track) {
|
|
if isPaused {
|
|
s.StreamStates = append(s.StreamStates, &StreamStateInfo{
|
|
ParticipantID: track.PublisherID(),
|
|
TrackID: track.ID(),
|
|
State: StreamStatePaused,
|
|
})
|
|
} else {
|
|
s.StreamStates = append(s.StreamStates, &StreamStateInfo{
|
|
ParticipantID: track.PublisherID(),
|
|
TrackID: track.ID(),
|
|
State: StreamStateActive,
|
|
})
|
|
}
|
|
}
|
|
|
|
func (s *StreamStateUpdate) Empty() bool {
|
|
return len(s.StreamStates) == 0
|
|
}
|
|
|
|
// ------------------------------------------------
|