using shared proto types for participant state
This commit is contained in:
+6
-14
@@ -14,14 +14,6 @@ import (
|
||||
"github.com/livekit/livekit-server/proto/livekit"
|
||||
)
|
||||
|
||||
type ParticipantState string
|
||||
|
||||
const (
|
||||
ParticipantStateConnecting ParticipantState = "connecting" // websocket connected, but no offer yet
|
||||
ParticipantStateJoined ParticipantState = "joined" // sent offer, establishing ICE
|
||||
ParticipantStateActive ParticipantState = "active" // ice connected
|
||||
)
|
||||
|
||||
type Participant struct {
|
||||
id string
|
||||
conn *webrtc.PeerConnection
|
||||
@@ -29,7 +21,7 @@ type Participant struct {
|
||||
cancel context.CancelFunc
|
||||
mediaEngine *MediaEngine
|
||||
name string
|
||||
state ParticipantState
|
||||
state livekit.ParticipantInfo_State
|
||||
|
||||
lock sync.RWMutex
|
||||
receiverConfig ReceiverConfig
|
||||
@@ -63,7 +55,7 @@ func NewParticipant(conf *WebRTCConfig, name string) (*Participant, error) {
|
||||
conn: pc,
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
state: ParticipantStateConnecting,
|
||||
state: livekit.ParticipantInfo_JOINING,
|
||||
lock: sync.RWMutex{},
|
||||
receiverConfig: conf.receiver,
|
||||
tracks: make([]*Track, 0),
|
||||
@@ -86,7 +78,7 @@ func NewParticipant(conf *WebRTCConfig, name string) (*Participant, error) {
|
||||
pc.OnICEConnectionStateChange(func(state webrtc.ICEConnectionState) {
|
||||
logger.GetLogger().Debugw("ICE connection state changed", "state", state.String())
|
||||
if state == webrtc.ICEConnectionStateConnected {
|
||||
participant.state = ParticipantStateActive
|
||||
participant.state = livekit.ParticipantInfo_ACTIVE
|
||||
}
|
||||
})
|
||||
|
||||
@@ -103,7 +95,7 @@ func (p *Participant) Name() string {
|
||||
return p.name
|
||||
}
|
||||
|
||||
func (p *Participant) State() ParticipantState {
|
||||
func (p *Participant) State() livekit.ParticipantInfo_State {
|
||||
return p.state
|
||||
}
|
||||
|
||||
@@ -122,8 +114,8 @@ func (p *Participant) Answer(sdp webrtc.SessionDescription) (answer webrtc.Sessi
|
||||
// return
|
||||
//}
|
||||
|
||||
if p.state == ParticipantStateConnecting {
|
||||
p.state = ParticipantStateJoined
|
||||
if p.state == livekit.ParticipantInfo_JOINING {
|
||||
p.state = livekit.ParticipantInfo_JOINED
|
||||
}
|
||||
|
||||
if err = p.SetRemoteDescription(sdp); err != nil {
|
||||
|
||||
+2
-2
@@ -114,7 +114,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
room.RemoveParticipant(participant.ID())
|
||||
}()
|
||||
case *livekit.SignalRequest_Negotiate:
|
||||
if participant.State() == rtc.ParticipantStateConnecting {
|
||||
if participant.State() == livekit.ParticipantInfo_JOINING {
|
||||
log.Errorw("cannot negotiate before peer offer", "participant", participant.ID())
|
||||
//conn.WriteJSON(jsonError(http.StatusNotAcceptable, "cannot negotiate before peer offer"))
|
||||
return
|
||||
@@ -127,7 +127,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
case *livekit.SignalRequest_Trickle:
|
||||
if participant.State() == rtc.ParticipantStateConnecting {
|
||||
if participant.State() == livekit.ParticipantInfo_JOINING {
|
||||
log.Errorw("cannot trickle before peer offer", "participant", participant.ID())
|
||||
//conn.WriteJSON(jsonError(http.StatusNotAcceptable, "cannot trickle before peer offer"))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user