cleaner resync

This commit is contained in:
David Zhao
2021-02-07 22:44:25 -08:00
parent d13a962afd
commit e30c9f706c
3 changed files with 39 additions and 20 deletions
+10 -9
View File
@@ -146,18 +146,19 @@ func (r *Room) Join(participant types.Participant) error {
func (r *Room) RemoveParticipant(identity string) {
r.lock.Lock()
defer r.lock.Unlock()
if p, ok := r.participants[identity]; ok {
// avoid blocking lock
go func() {
Recover()
// also stop connection if needed
p.Close()
}()
p, ok := r.participants[identity]
if !ok {
return
}
delete(r.participants, identity)
p.OnTrackUpdated(nil)
p.OnTrackPublished(nil)
p.OnStateChange(nil)
// close participant as well
go p.Close()
if len(r.participants) == 0 {
r.leftAt.Store(time.Now().Unix())
}