Use a TTL of 1 hour for ICE config cache (#873)
This commit is contained in:
@@ -25,8 +25,14 @@ const (
|
|||||||
roomPurgeSeconds = 24 * 60 * 60
|
roomPurgeSeconds = 24 * 60 * 60
|
||||||
tokenRefreshInterval = 5 * time.Minute
|
tokenRefreshInterval = 5 * time.Minute
|
||||||
tokenDefaultTTL = 10 * time.Minute
|
tokenDefaultTTL = 10 * time.Minute
|
||||||
|
iceConfigTTL = 60 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type iceConfigCacheEntry struct {
|
||||||
|
iceConfig types.IceConfig
|
||||||
|
modifiedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
// RoomManager manages rooms and its interaction with participants.
|
// RoomManager manages rooms and its interaction with participants.
|
||||||
// It's responsible for creating, deleting rooms, as well as running sessions for participants
|
// It's responsible for creating, deleting rooms, as well as running sessions for participants
|
||||||
type RoomManager struct {
|
type RoomManager struct {
|
||||||
@@ -42,7 +48,7 @@ type RoomManager struct {
|
|||||||
|
|
||||||
rooms map[livekit.RoomName]*rtc.Room
|
rooms map[livekit.RoomName]*rtc.Room
|
||||||
|
|
||||||
iceConfigCache map[livekit.ParticipantIdentity]types.IceConfig
|
iceConfigCache map[livekit.ParticipantIdentity]*iceConfigCacheEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLocalRoomManager(
|
func NewLocalRoomManager(
|
||||||
@@ -70,7 +76,7 @@ func NewLocalRoomManager(
|
|||||||
|
|
||||||
rooms: make(map[livekit.RoomName]*rtc.Room),
|
rooms: make(map[livekit.RoomName]*rtc.Room),
|
||||||
|
|
||||||
iceConfigCache: make(map[livekit.ParticipantIdentity]types.IceConfig),
|
iceConfigCache: make(map[livekit.ParticipantIdentity]*iceConfigCacheEntry),
|
||||||
}
|
}
|
||||||
|
|
||||||
// hook up to router
|
// hook up to router
|
||||||
@@ -317,7 +323,10 @@ func (r *RoomManager) StartSession(
|
|||||||
})
|
})
|
||||||
participant.OnICEConfigChanged(func(participant types.LocalParticipant, iceConfig types.IceConfig) {
|
participant.OnICEConfigChanged(func(participant types.LocalParticipant, iceConfig types.IceConfig) {
|
||||||
r.lock.Lock()
|
r.lock.Lock()
|
||||||
r.iceConfigCache[participant.Identity()] = iceConfig
|
r.iceConfigCache[participant.Identity()] = &iceConfigCacheEntry{
|
||||||
|
iceConfig: iceConfig,
|
||||||
|
modifiedAt: time.Now(),
|
||||||
|
}
|
||||||
r.lock.Unlock()
|
r.lock.Unlock()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -629,15 +638,16 @@ func (r *RoomManager) refreshToken(participant types.LocalParticipant) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RoomManager) setIceConfig(participant types.LocalParticipant) {
|
func (r *RoomManager) setIceConfig(participant types.LocalParticipant) {
|
||||||
r.lock.RLock()
|
r.lock.Lock()
|
||||||
iceConfig, ok := r.iceConfigCache[participant.Identity()]
|
iceConfigCacheEntry, ok := r.iceConfigCache[participant.Identity()]
|
||||||
if !ok {
|
if !ok || time.Since(iceConfigCacheEntry.modifiedAt) > iceConfigTTL {
|
||||||
r.lock.RUnlock()
|
delete(r.iceConfigCache, participant.Identity())
|
||||||
|
r.lock.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.lock.RUnlock()
|
r.lock.Unlock()
|
||||||
|
|
||||||
participant.SetICEConfig(iceConfig)
|
participant.SetICEConfig(iceConfigCacheEntry.iceConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user