From c9abe8bfe02352889c03ed1e74adf9e1a6fdbc86 Mon Sep 17 00:00:00 2001 From: Daniel Kessler Date: Thu, 9 Jan 2025 15:48:42 -0800 Subject: [PATCH] Add nil checks to agent_handlers (#751) Co-authored-by: Daniel Kessler --- agent_handlers.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agent_handlers.go b/agent_handlers.go index 0c02277..c245f0c 100644 --- a/agent_handlers.go +++ b/agent_handlers.go @@ -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) } }