Add nil checks to agent_handlers (#751)

Co-authored-by: Daniel Kessler <dkess@google.com>
This commit is contained in:
Daniel Kessler
2025-01-09 15:48:42 -08:00
committed by GitHub
co-authored by Daniel Kessler
parent 35bb3fb992
commit c9abe8bfe0
+3 -3
View File
@@ -26,19 +26,19 @@ func (a *Agent) OnCandidate(f func(Candidate)) error {
}
func (a *Agent) onSelectedCandidatePairChange(p *CandidatePair) {
if h, ok := a.onSelectedCandidatePairChangeHdlr.Load().(func(Candidate, Candidate)); ok {
if h, ok := a.onSelectedCandidatePairChangeHdlr.Load().(func(Candidate, Candidate)); ok && h != nil {
h(p.Local, p.Remote)
}
}
func (a *Agent) onCandidate(c Candidate) {
if onCandidateHdlr, ok := a.onCandidateHdlr.Load().(func(Candidate)); ok {
if onCandidateHdlr, ok := a.onCandidateHdlr.Load().(func(Candidate)); ok && onCandidateHdlr != nil {
onCandidateHdlr(c)
}
}
func (a *Agent) onConnectionStateChange(s ConnectionState) {
if hdlr, ok := a.onConnectionStateChangeHdlr.Load().(func(ConnectionState)); ok {
if hdlr, ok := a.onConnectionStateChangeHdlr.Load().(func(ConnectionState)); ok && hdlr != nil {
hdlr(s)
}
}