Skip to content

Commit c9abe8b

Browse files
dkessDaniel Kessler
and
Daniel Kessler
authored
Add nil checks to agent_handlers (#751)
Co-authored-by: Daniel Kessler <[email protected]>
1 parent 35bb3fb commit c9abe8b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

agent_handlers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ func (a *Agent) OnCandidate(f func(Candidate)) error {
2626
}
2727

2828
func (a *Agent) onSelectedCandidatePairChange(p *CandidatePair) {
29-
if h, ok := a.onSelectedCandidatePairChangeHdlr.Load().(func(Candidate, Candidate)); ok {
29+
if h, ok := a.onSelectedCandidatePairChangeHdlr.Load().(func(Candidate, Candidate)); ok && h != nil {
3030
h(p.Local, p.Remote)
3131
}
3232
}
3333

3434
func (a *Agent) onCandidate(c Candidate) {
35-
if onCandidateHdlr, ok := a.onCandidateHdlr.Load().(func(Candidate)); ok {
35+
if onCandidateHdlr, ok := a.onCandidateHdlr.Load().(func(Candidate)); ok && onCandidateHdlr != nil {
3636
onCandidateHdlr(c)
3737
}
3838
}
3939

4040
func (a *Agent) onConnectionStateChange(s ConnectionState) {
41-
if hdlr, ok := a.onConnectionStateChangeHdlr.Load().(func(ConnectionState)); ok {
41+
if hdlr, ok := a.onConnectionStateChangeHdlr.Load().(func(ConnectionState)); ok && hdlr != nil {
4242
hdlr(s)
4343
}
4444
}

0 commit comments

Comments
 (0)