subscribe new participant after JOINED, to ensure negotiate requests aren't missed

This commit is contained in:
David Zhao
2020-12-13 23:08:20 -08:00
parent af0c9dfdf0
commit ac83bf4c78
7 changed files with 253 additions and 73 deletions
+16 -14
View File
@@ -67,6 +67,22 @@ func (r *Room) Join(participant *Participant) error {
participant.OnStateChange = func(p *Participant, oldState livekit.ParticipantInfo_State) {
log.Debugw("participant state changed", "state", p.state, "participant", p.id)
r.broadcastParticipantState(p)
if oldState == livekit.ParticipantInfo_JOINING && p.state == livekit.ParticipantInfo_JOINED {
// subscribe participant to existing tracks
for _, p := range r.participants {
if p.id == participant.id {
// don't send to itself
continue
}
if err := p.AddSubscriber(participant); err != nil {
// TODO: log error? or disconnect?
logger.GetLogger().Errorw("could not subscribe to participant",
"dstParticipant", participant.ID(),
"srcParticipant", p.ID())
}
}
}
}
log.Infow("new participant joined",
@@ -74,20 +90,6 @@ func (r *Room) Join(participant *Participant) error {
"name", participant.Name(),
"roomId", r.Sid)
// subscribe participant to existing tracks
for _, p := range r.participants {
if p.id == participant.id {
// don't send to itself
continue
}
if err := p.AddSubscriber(participant); err != nil {
// TODO: log error? or disconnect?
logger.GetLogger().Errorw("could not subscribe to participant",
"dstParticipant", participant.ID(),
"srcParticipant", p.ID())
}
}
r.participants[participant.ID()] = participant
// gather other participants and send join response