correctly send participant updates
This commit is contained in:
@@ -184,6 +184,7 @@ func (c *RTCClient) Run() error {
|
|||||||
case *livekit.SignalResponse_Join:
|
case *livekit.SignalResponse_Join:
|
||||||
c.AppendLog("join accepted, sending offer..")
|
c.AppendLog("join accepted, sending offer..")
|
||||||
c.localParticipant = msg.Join.Participant
|
c.localParticipant = msg.Join.Participant
|
||||||
|
c.AppendLog("other participants", "count", len(msg.Join.OtherParticipants))
|
||||||
|
|
||||||
// Create an offer to send to the other process
|
// Create an offer to send to the other process
|
||||||
offer, err := c.PeerConn.CreateOffer(nil)
|
offer, err := c.PeerConn.CreateOffer(nil)
|
||||||
@@ -240,6 +241,10 @@ func (c *RTCClient) Run() error {
|
|||||||
if err := c.PeerConn.AddICECandidate(*candidateInit); err != nil {
|
if err := c.PeerConn.AddICECandidate(*candidateInit); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
case *livekit.SignalResponse_Update:
|
||||||
|
for _, p := range msg.Update.Participants {
|
||||||
|
c.AppendLog("participant update", "id", p.Id, "state", p.State.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,10 +119,12 @@ func (p *Participant) State() livekit.ParticipantInfo_State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Participant) ToProto() *livekit.ParticipantInfo {
|
func (p *Participant) ToProto() *livekit.ParticipantInfo {
|
||||||
return &livekit.ParticipantInfo{
|
info := &livekit.ParticipantInfo{
|
||||||
Id: p.id,
|
Id: p.id,
|
||||||
Name: p.name,
|
Name: p.name,
|
||||||
|
State: p.state,
|
||||||
}
|
}
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
// Answer an offer from remote participant
|
// Answer an offer from remote participant
|
||||||
@@ -280,6 +282,7 @@ func (p *Participant) updateState(state livekit.ParticipantInfo_State) {
|
|||||||
}
|
}
|
||||||
oldState := p.state
|
oldState := p.state
|
||||||
p.state = state
|
p.state = state
|
||||||
|
|
||||||
if p.OnStateChange != nil {
|
if p.OnStateChange != nil {
|
||||||
go func() {
|
go func() {
|
||||||
p.OnStateChange(p, oldState)
|
p.OnStateChange(p, oldState)
|
||||||
|
|||||||
+6
-3
@@ -60,13 +60,16 @@ func (r *Room) Join(participant *Participant) error {
|
|||||||
r.lock.Lock()
|
r.lock.Lock()
|
||||||
defer r.lock.Unlock()
|
defer r.lock.Unlock()
|
||||||
|
|
||||||
participant.OnPeerTrack = r.onTrackAdded
|
log := logger.GetLogger()
|
||||||
|
|
||||||
|
// it's important to set this before connection, we don't want to miss out on any tracks
|
||||||
|
participant.OnPeerTrack = r.onTrackAdded
|
||||||
participant.OnStateChange = func(p *Participant, oldState livekit.ParticipantInfo_State) {
|
participant.OnStateChange = func(p *Participant, oldState livekit.ParticipantInfo_State) {
|
||||||
|
log.Debugw("participant state changed", "state", p.state, "participant", p.id)
|
||||||
r.broadcastParticipantState(p)
|
r.broadcastParticipantState(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.GetLogger().Infow("new participant joined",
|
log.Infow("new participant joined",
|
||||||
"id", participant.ID(),
|
"id", participant.ID(),
|
||||||
"name", participant.Name(),
|
"name", participant.Name(),
|
||||||
"roomId", r.Id)
|
"roomId", r.Id)
|
||||||
@@ -137,7 +140,7 @@ func (r *Room) broadcastParticipantState(p *Participant) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err := p.SendParticipantUpdate(updates)
|
err := op.SendParticipantUpdate(updates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.GetLogger().Errorw("could not send update to participant",
|
logger.GetLogger().Errorw("could not send update to participant",
|
||||||
"participant", p.id,
|
"participant", p.id,
|
||||||
|
|||||||
+3
-3
@@ -5,9 +5,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RoomPrefix = "R-"
|
RoomPrefix = "RM_"
|
||||||
NodePrefix = "N-"
|
NodePrefix = "ND_"
|
||||||
ParticipantPrefix = "P-"
|
ParticipantPrefix = "PA_"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewGuid(prefix string) string {
|
func NewGuid(prefix string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user