Dependent participants should not trigger count towards FirstJoinedAt (#3448)

* Dependent participants should not trigger count towards FirstJoinedAt

According to the API, empty timeout should be honored as long as no
independent participant joins the room. If we counted Agents and Egress
as part of FirstJoinedAt, it would have the side effect of using
departureTimeout instead of emptyTimeout for idle calculations.

* use Room logger
This commit is contained in:
David Zhao
2025-02-19 22:57:40 -08:00
committed by GitHub
parent 3167266495
commit 1c69a9eeed
2 changed files with 14 additions and 5 deletions
+10 -4
View File
@@ -440,7 +440,7 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
}
}
if r.FirstJoinedAt() == 0 {
if r.FirstJoinedAt() == 0 && !participant.IsDependent() {
r.joinedAt.Store(time.Now().Unix())
}
@@ -871,36 +871,42 @@ func (r *Room) IsClosed() bool {
}
// CloseIfEmpty closes the room if all participants had left, or it's still empty past timeout
func (r *Room) CloseIfEmpty() {
func (r *Room) CloseIfEmpty() string {
r.lock.Lock()
if r.IsClosed() || r.holds.Load() > 0 {
r.lock.Unlock()
return
return ""
}
for _, p := range r.participants {
if !p.IsDependent() {
r.lock.Unlock()
return
return ""
}
}
var timeout uint32
var elapsed int64
reason := ""
if r.FirstJoinedAt() > 0 && r.LastLeftAt() > 0 {
elapsed = time.Now().Unix() - r.LastLeftAt()
// need to give time in case participant is reconnecting
timeout = r.protoRoom.DepartureTimeout
reason = "departure timeout"
} else {
elapsed = time.Now().Unix() - r.protoRoom.CreationTime
timeout = r.protoRoom.EmptyTimeout
reason = "empty timeout"
}
r.lock.Unlock()
if elapsed >= int64(timeout) {
r.Close(types.ParticipantCloseReasonRoomClosed)
return reason
}
return ""
}
func (r *Room) Close(reason types.ParticipantCloseReason) {
+4 -1
View File
@@ -197,7 +197,10 @@ func (r *RoomManager) CloseIdleRooms() {
r.lock.RUnlock()
for _, room := range rooms {
room.CloseIfEmpty()
reason := room.CloseIfEmpty()
if reason != "" {
room.Logger.Infow("closing idle room", "reason", reason)
}
}
}