From 71a7914eecbe323e19f6df7c2ccdff80a7f59eaa Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sat, 5 Dec 2020 17:53:33 -0800 Subject: [PATCH] send event when participant disconnects --- pkg/rtc/room.go | 2 ++ pkg/service/rtc.go | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/rtc/room.go b/pkg/rtc/room.go index 5e96d330b..bb6aa63f2 100644 --- a/pkg/rtc/room.go +++ b/pkg/rtc/room.go @@ -108,6 +108,8 @@ func (r *Room) RemoveParticipant(id string) { if p, ok := r.participants[id]; ok { // also stop connection if needed p.Close() + // update clients + r.broadcastParticipantState(p) } delete(r.participants, id) diff --git a/pkg/service/rtc.go b/pkg/service/rtc.go index fe218a1ff..3569c5926 100644 --- a/pkg/service/rtc.go +++ b/pkg/service/rtc.go @@ -85,6 +85,8 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) { } defer func() { + // remove peer from room upon disconnection + room.RemoveParticipant(participant.ID()) participant.Close() log.Infow("WS connection closed") }() @@ -108,10 +110,6 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Errorw("could not handle join", "err", err, "participant", participant.ID()) return } - defer func() { - // remove peer from room upon disconnection - room.RemoveParticipant(participant.ID()) - }() case *livekit.SignalRequest_Negotiate: if participant.State() == livekit.ParticipantInfo_JOINING { log.Errorw("cannot negotiate before peer offer", "participant", participant.ID())