Check backend when searching for session to use for dialout.

This commit is contained in:
Joachim Bauch 2023-10-31 08:33:46 +01:00
parent 29d10f3723
commit c72c821687
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 19 additions and 7 deletions

View file

@ -685,13 +685,7 @@ func (b *BackendServer) startDialout(roomid string, backend *Backend, request *B
return returnDialoutError(http.StatusBadRequest, NewError("invalid_roomid", "The room id must be numeric.")) return returnDialoutError(http.StatusBadRequest, NewError("invalid_roomid", "The room id must be numeric."))
} }
var session *ClientSession session := b.hub.GetDialoutSession(roomid, backend)
for s := range b.hub.dialoutSessions {
if s.GetClient() != nil {
session = s
break
}
}
if session == nil { if session == nil {
return returnDialoutError(http.StatusNotFound, NewError("no_client_available", "No available client found to trigger dialout.")) return returnDialoutError(http.StatusNotFound, NewError("no_client_available", "No available client found to trigger dialout."))
} }

18
hub.go
View file

@ -581,6 +581,24 @@ func (h *Hub) GetSessionByPublicId(sessionId string) Session {
return session return session
} }
func (h *Hub) GetDialoutSession(roomId string, backend *Backend) *ClientSession {
url := backend.Url()
h.mu.RLock()
defer h.mu.RUnlock()
for session := range h.dialoutSessions {
if session.backend.Url() != url {
continue
}
if session.GetClient() != nil {
return session
}
}
return nil
}
func (h *Hub) checkExpiredSessions(now time.Time) { func (h *Hub) checkExpiredSessions(now time.Time) {
for s := range h.expiredSessions { for s := range h.expiredSessions {
if s.IsExpired(now) { if s.IsExpired(now) {