Cache ICE config in room manager. (#872)

* Cache ICE config in room manager.

* mage generate

* Read ICE config within lock
This commit is contained in:
Raja Subramanian
2022-08-05 12:49:19 +05:30
committed by GitHub
parent 339181a534
commit 3f16018b62
4 changed files with 128 additions and 2 deletions
+24
View File
@@ -41,6 +41,8 @@ type RoomManager struct {
clientConfManager clientconfiguration.ClientConfigurationManager
rooms map[livekit.RoomName]*rtc.Room
iceConfigCache map[livekit.ParticipantIdentity]types.IceConfig
}
func NewLocalRoomManager(
@@ -67,6 +69,8 @@ func NewLocalRoomManager(
clientConfManager: clientConfManager,
rooms: make(map[livekit.RoomName]*rtc.Room),
iceConfigCache: make(map[livekit.ParticipantIdentity]types.IceConfig),
}
// hook up to router
@@ -264,6 +268,7 @@ func (r *RoomManager) StartSession(
if err != nil {
return err
}
r.setIceConfig(participant)
// join room
opts := rtc.ParticipantOptions{
@@ -310,6 +315,11 @@ func (r *RoomManager) StartSession(
logger.Errorw("could not refresh token", err)
}
})
participant.OnICEConfigChanged(func(participant types.LocalParticipant, iceConfig types.IceConfig) {
r.lock.Lock()
r.iceConfigCache[participant.Identity()] = iceConfig
r.lock.Unlock()
})
go r.rtcSessionWorker(room, participant, requestSource)
return nil
@@ -618,6 +628,20 @@ func (r *RoomManager) refreshToken(participant types.LocalParticipant) error {
return nil
}
func (r *RoomManager) setIceConfig(participant types.LocalParticipant) {
r.lock.RLock()
iceConfig, ok := r.iceConfigCache[participant.Identity()]
if !ok {
r.lock.RUnlock()
return
}
r.lock.RUnlock()
participant.SetICEConfig(iceConfig)
}
// ------------------------------------
func iceServerForStunServers(servers []string) *livekit.ICEServer {
iceServer := &livekit.ICEServer{}
for _, stunServer := range servers {