From 94f2a735b6c197facddd69ca56bfb0f076e6bf3a Mon Sep 17 00:00:00 2001 From: billfort Date: Fri, 10 May 2024 13:59:19 +0800 Subject: [PATCH] Check if nil before close WebRTC channels Signed-off-by: billfort --- api/webrtc/webrtc.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/api/webrtc/webrtc.go b/api/webrtc/webrtc.go index 7afa1e2f..18a1876d 100644 --- a/api/webrtc/webrtc.go +++ b/api/webrtc/webrtc.go @@ -375,9 +375,15 @@ func (c *Peer) SetReadLimit(l int64) { } func (c *Peer) Close() error { - close(c.OnSdp) - close(c.OnMessage) - close(c.OnOfferConnected) + if c.OnSdp != nil { + close(c.OnSdp) + } + if c.OnMessage != nil { + close(c.OnMessage) + } + if c.OnOfferConnected != nil { + close(c.OnOfferConnected) + } if c.dc != nil { if err := c.dc.Close(); err != nil { return err