correctly send participant updates

This commit is contained in:
David Zhao
2020-12-02 00:53:16 -08:00
parent a6c4db2cb3
commit bca8090b41
4 changed files with 20 additions and 9 deletions

View File

@@ -184,6 +184,7 @@ func (c *RTCClient) Run() error {
case *livekit.SignalResponse_Join:
c.AppendLog("join accepted, sending offer..")
c.localParticipant = msg.Join.Participant
c.AppendLog("other participants", "count", len(msg.Join.OtherParticipants))
// Create an offer to send to the other process
offer, err := c.PeerConn.CreateOffer(nil)
@@ -240,6 +241,10 @@ func (c *RTCClient) Run() error {
if err := c.PeerConn.AddICECandidate(*candidateInit); err != nil {
return err
}
case *livekit.SignalResponse_Update:
for _, p := range msg.Update.Participants {
c.AppendLog("participant update", "id", p.Id, "state", p.State.String())
}
}
}

View File

@@ -119,10 +119,12 @@ func (p *Participant) State() livekit.ParticipantInfo_State {
}
func (p *Participant) ToProto() *livekit.ParticipantInfo {
return &livekit.ParticipantInfo{
Id: p.id,
Name: p.name,
info := &livekit.ParticipantInfo{
Id: p.id,
Name: p.name,
State: p.state,
}
return info
}
// Answer an offer from remote participant
@@ -280,6 +282,7 @@ func (p *Participant) updateState(state livekit.ParticipantInfo_State) {
}
oldState := p.state
p.state = state
if p.OnStateChange != nil {
go func() {
p.OnStateChange(p, oldState)

View File

@@ -60,13 +60,16 @@ func (r *Room) Join(participant *Participant) error {
r.lock.Lock()
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) {
log.Debugw("participant state changed", "state", p.state, "participant", p.id)
r.broadcastParticipantState(p)
}
logger.GetLogger().Infow("new participant joined",
log.Infow("new participant joined",
"id", participant.ID(),
"name", participant.Name(),
"roomId", r.Id)
@@ -137,7 +140,7 @@ func (r *Room) broadcastParticipantState(p *Participant) {
continue
}
err := p.SendParticipantUpdate(updates)
err := op.SendParticipantUpdate(updates)
if err != nil {
logger.GetLogger().Errorw("could not send update to participant",
"participant", p.id,

View File

@@ -5,9 +5,9 @@ import (
)
const (
RoomPrefix = "R-"
NodePrefix = "N-"
ParticipantPrefix = "P-"
RoomPrefix = "RM_"
NodePrefix = "ND_"
ParticipantPrefix = "PA_"
)
func NewGuid(prefix string) string {