MCPcopy
hub / github.com/livekit/livekit / CloseIfEmpty

Method CloseIfEmpty

pkg/rtc/room.go:772–806  ·  view source on GitHub ↗

CloseIfEmpty closes the room if all participants had left, or it's still empty past timeout

()

Source from the content-addressed store, hash-verified

770
771// CloseIfEmpty closes the room if all participants had left, or it's still empty past timeout
772func (r *Room) CloseIfEmpty() {
773 r.lock.Lock()
774
775 if r.IsClosed() || r.holds.Load() > 0 {
776 r.lock.Unlock()
777 return
778 }
779
780 for _, p := range r.participants {
781 if !p.IsDependent() {
782 r.lock.Unlock()
783 return
784 }
785 }
786
787 var timeout uint32
788 var elapsed int64
789 var reason string
790 if r.FirstJoinedAt() > 0 && r.LastLeftAt() > 0 {
791 elapsed = time.Now().Unix() - r.LastLeftAt()
792 // need to give time in case participant is reconnecting
793 timeout = r.protoRoom.DepartureTimeout
794 reason = "departure timeout"
795 } else {
796 elapsed = time.Now().Unix() - r.protoRoom.CreationTime
797 timeout = r.protoRoom.EmptyTimeout
798 reason = "empty timeout"
799 }
800 r.lock.Unlock()
801
802 if elapsed >= int64(timeout) {
803 r.Close(types.ParticipantCloseReasonRoomClosed)
804 r.logger.Infow("closing idle room", "reason", reason)
805 }
806}
807
808func (r *Room) Close(reason types.ParticipantCloseReason) {
809 r.lock.Lock()

Callers 2

CloseIdleRoomsMethod · 0.80
TestRoomClosureFunction · 0.80

Calls 6

IsClosedMethod · 0.95
FirstJoinedAtMethod · 0.95
LastLeftAtMethod · 0.95
CloseMethod · 0.95
LoadMethod · 0.65
IsDependentMethod · 0.65

Tested by 1

TestRoomClosureFunction · 0.64