mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2026-03-14 14:35:44 +01:00
Store time when join room was successfull in session, not when it ended.
This commit is contained in:
parent
b2934836a9
commit
348e7b3360
5 changed files with 20 additions and 14 deletions
|
|
@ -329,14 +329,14 @@ func (s *ClientSession) ParsedUserData() (api.StringMap, error) {
|
|||
return s.parseUserData()
|
||||
}
|
||||
|
||||
func (s *ClientSession) SetRoom(room *Room) {
|
||||
func (s *ClientSession) SetRoom(room *Room, joinTime time.Time) {
|
||||
s.room.Store(room)
|
||||
s.onRoomSet(room != nil)
|
||||
s.onRoomSet(room != nil, joinTime)
|
||||
}
|
||||
|
||||
func (s *ClientSession) onRoomSet(hasRoom bool) {
|
||||
func (s *ClientSession) onRoomSet(hasRoom bool, joinTime time.Time) {
|
||||
if hasRoom {
|
||||
s.roomJoinTime.Store(time.Now().UnixNano())
|
||||
s.roomJoinTime.Store(joinTime.UnixNano())
|
||||
} else {
|
||||
s.roomJoinTime.Store(0)
|
||||
}
|
||||
|
|
@ -361,7 +361,7 @@ func (s *ClientSession) SetFederationClient(federation *FederationClient) {
|
|||
defer s.mu.Unlock()
|
||||
|
||||
s.doLeaveRoom(true)
|
||||
s.onRoomSet(federation != nil)
|
||||
s.onRoomSet(federation != nil, time.Now())
|
||||
|
||||
if prev := s.federation.Swap(federation); prev != nil && prev != federation {
|
||||
prev.Close()
|
||||
|
|
@ -561,7 +561,7 @@ func (s *ClientSession) doLeaveRoom(notify bool) *Room {
|
|||
}
|
||||
|
||||
s.doUnsubscribeRoomEvents(notify)
|
||||
s.SetRoom(nil)
|
||||
s.SetRoom(nil, time.Time{})
|
||||
s.releaseMcuObjects()
|
||||
room.RemoveSession(s)
|
||||
return room
|
||||
|
|
|
|||
11
hub.go
11
hub.go
|
|
@ -1848,8 +1848,10 @@ func (h *Hub) processRoom(sess Session, message *api.ClientMessage) {
|
|||
}
|
||||
|
||||
var room talk.BackendClientResponse
|
||||
var joinRoomTime time.Time
|
||||
if session.ClientType() == api.HelloClientTypeInternal {
|
||||
// Internal clients can join any room.
|
||||
joinRoomTime = time.Now()
|
||||
room = talk.BackendClientResponse{
|
||||
Type: "room",
|
||||
Room: &talk.BackendClientRoomResponse{
|
||||
|
|
@ -1876,6 +1878,7 @@ func (h *Hub) processRoom(sess Session, message *api.ClientMessage) {
|
|||
|
||||
// TODO(jojo): Validate response
|
||||
|
||||
joinRoomTime = time.Now()
|
||||
if message.Room.SessionId != "" {
|
||||
// There can only be one connection per Nextcloud Talk session,
|
||||
// disconnect any other connections without sending a "leave" event.
|
||||
|
|
@ -1886,7 +1889,7 @@ func (h *Hub) processRoom(sess Session, message *api.ClientMessage) {
|
|||
}
|
||||
}
|
||||
|
||||
h.processJoinRoom(session, message, &room)
|
||||
h.processJoinRoom(session, message, &room, joinRoomTime)
|
||||
}
|
||||
|
||||
func (h *Hub) publishFederatedSessions() (int, *sync.WaitGroup) {
|
||||
|
|
@ -2005,7 +2008,7 @@ func (h *Hub) createRoomLocked(id string, properties json.RawMessage, backend *t
|
|||
return room, nil
|
||||
}
|
||||
|
||||
func (h *Hub) processJoinRoom(session *ClientSession, message *api.ClientMessage, room *talk.BackendClientResponse) {
|
||||
func (h *Hub) processJoinRoom(session *ClientSession, message *api.ClientMessage, room *talk.BackendClientResponse, joinTime time.Time) {
|
||||
if room.Type == "error" {
|
||||
session.SendMessage(message.NewErrorServerMessage(room.Error))
|
||||
return
|
||||
|
|
@ -2051,7 +2054,7 @@ func (h *Hub) processJoinRoom(session *ClientSession, message *api.ClientMessage
|
|||
delete(h.dialoutSessions, session)
|
||||
}
|
||||
h.mu.Unlock()
|
||||
session.SetRoom(r)
|
||||
session.SetRoom(r, joinTime)
|
||||
if room.Room.Permissions != nil {
|
||||
session.SetPermissions(*room.Room.Permissions)
|
||||
}
|
||||
|
|
@ -2540,7 +2543,7 @@ func (h *Hub) processInternalMsg(sess Session, message *api.ClientMessage) {
|
|||
statsHubSessionsTotal.WithLabelValues(session.Backend().Id(), string(sess.ClientType())).Inc()
|
||||
h.logger.Printf("Session %s added virtual session %s with initial flags %d", session.PublicId(), sess.PublicId(), sess.Flags())
|
||||
session.AddVirtualSession(sess)
|
||||
sess.SetRoom(room)
|
||||
sess.SetRoom(room, time.Now())
|
||||
room.AddSession(sess, nil)
|
||||
case "updatesession":
|
||||
msg := msg.UpdateSession
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"encoding/json"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -82,7 +83,7 @@ func (s *DummySession) ParsedBackendUrl() *url.URL {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *DummySession) SetRoom(room *Room) {
|
||||
func (s *DummySession) SetRoom(room *Room, joinTime time.Time) {
|
||||
}
|
||||
|
||||
func (s *DummySession) GetRoom() *Room {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"encoding/json"
|
||||
"net/url"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/talk"
|
||||
|
|
@ -46,7 +47,7 @@ type Session interface {
|
|||
BackendUrl() string
|
||||
ParsedBackendUrl() *url.URL
|
||||
|
||||
SetRoom(room *Room)
|
||||
SetRoom(room *Room, joinTime time.Time)
|
||||
GetRoom() *Room
|
||||
LeaveRoom(notify bool) *Room
|
||||
IsInRoom(id string) bool
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"errors"
|
||||
"net/url"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/async/events"
|
||||
|
|
@ -169,7 +170,7 @@ func (s *VirtualSession) ParsedUserData() (api.StringMap, error) {
|
|||
return s.parseUserData()
|
||||
}
|
||||
|
||||
func (s *VirtualSession) SetRoom(room *Room) {
|
||||
func (s *VirtualSession) SetRoom(room *Room, joinTime time.Time) {
|
||||
s.room.Store(room)
|
||||
if room != nil {
|
||||
if err := s.hub.roomSessions.SetRoomSession(s, api.RoomSessionId(s.PublicId())); err != nil {
|
||||
|
|
@ -195,7 +196,7 @@ func (s *VirtualSession) LeaveRoom(notify bool) *Room {
|
|||
return nil
|
||||
}
|
||||
|
||||
s.SetRoom(nil)
|
||||
s.SetRoom(nil, time.Time{})
|
||||
room.RemoveSession(s)
|
||||
return room
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue