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
+21
View File
@@ -152,6 +152,7 @@ type ParticipantImpl struct {
pendingDataChannels []*livekit.DataChannelInfo
onClose func(types.LocalParticipant, map[livekit.TrackID]livekit.ParticipantID)
onClaimsChanged func(participant types.LocalParticipant)
onICEConfigChanged func(participant types.LocalParticipant, iceConfig types.IceConfig)
activeCounter atomic.Int32
firstConnected atomic.Bool
@@ -538,7 +539,9 @@ func (p *ParticipantImpl) OnClose(callback func(types.LocalParticipant, map[live
}
func (p *ParticipantImpl) OnClaimsChanged(callback func(types.LocalParticipant)) {
p.lock.Lock()
p.onClaimsChanged = callback
p.lock.Unlock()
}
// HandleOffer an offer from remote participant, used when clients make the initial connection
@@ -856,6 +859,18 @@ func (p *ParticipantImpl) ICERestart(iceConfig *types.IceConfig) error {
})
}
func (p *ParticipantImpl) OnICEConfigChanged(f func(participant types.LocalParticipant, iceConfig types.IceConfig)) {
p.lock.Lock()
p.onICEConfigChanged = f
p.lock.Unlock()
}
func (p *ParticipantImpl) SetICEConfig(iceConfig types.IceConfig) {
p.lock.Lock()
p.iceConfig = iceConfig
p.lock.Unlock()
}
//
// signal connection methods
//
@@ -1328,7 +1343,13 @@ func (p *ParticipantImpl) handleConnectionFailed(isPrimary bool) {
p.lock.Lock()
p.iceConfig.PreferSubTcp = true
p.iceConfig.PreferPubTcp = true
onICEConfigChanged := p.onICEConfigChanged
iceConfig := p.iceConfig
p.lock.Unlock()
if onICEConfigChanged != nil {
onICEConfigChanged(p, iceConfig)
}
}
}