Try to protect against crash from dereferencing a NULL in go-proxy

Follow up to ff8f385

Similar to c834c76
This commit is contained in:
Arlo Breault 2018-03-14 00:15:13 -04:00
parent c834c76fc5
commit f2abf5b60c

View file

@ -71,7 +71,9 @@ func (c *webRTCConn) Read(b []byte) (int, error) {
func (c *webRTCConn) Write(b []byte) (int, error) {
// log.Printf("webrtc Write %d %+q", len(b), string(b))
log.Printf("Write %d bytes --> WebRTC", len(b))
c.dc.Send(b)
if c.dc != nil {
c.dc.Send(b)
}
return len(b), nil
}
@ -254,12 +256,15 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
pr, pw := io.Pipe()
conn := &webRTCConn{pc: pc, dc: dc, pr: pr}
dc.OnOpen = func() {
log.Println("OnOpen channel")
}
dc.OnClose = func() {
log.Println("OnClose channel")
pw.Close()
conn.dc = nil
pc.DeleteDataChannel(dc)
}
dc.OnMessage = func(msg []byte) {
@ -273,7 +278,6 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
}
}
conn := &webRTCConn{pc: pc, dc: dc, pr: pr}
go datachannelHandler(conn, conn.RemoteAddr())
}