diff --git a/backend_server.go b/backend_server.go index 1705f8e..9b01387 100644 --- a/backend_server.go +++ b/backend_server.go @@ -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.")) } - var session *ClientSession - for s := range b.hub.dialoutSessions { - if s.GetClient() != nil { - session = s - break - } - } + session := b.hub.GetDialoutSession(roomid, backend) if session == nil { return returnDialoutError(http.StatusNotFound, NewError("no_client_available", "No available client found to trigger dialout.")) } diff --git a/hub.go b/hub.go index f57687b..d6c3086 100644 --- a/hub.go +++ b/hub.go @@ -581,6 +581,24 @@ func (h *Hub) GetSessionByPublicId(sessionId string) 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) { for s := range h.expiredSessions { if s.IsExpired(now) {