Fix UDPMux logger

If no logger is passed in, it will be created.
Error running webrtc/examples/ice-single-port :
invalid memory address or nil pointer dereference
This commit is contained in:
cgojin
2021-04-27 14:13:03 +08:00
committed by Jin Gong
parent c4d5d1c670
commit 1f4e18f401
3 changed files with 6 additions and 3 deletions
+1
View File
@@ -64,6 +64,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
* [Will Forcey](https://github.com/wawesomeNOGUI)
* [David Zhao](https://github.com/davidzhao)
* [Juliusz Chroboczek](https://github.com/jech)
* [Jin Gong](https://github.com/cgojin)
### License
MIT License - see [LICENSE](LICENSE) for full text
+4
View File
@@ -47,6 +47,10 @@ type UDPMuxParams struct {
// NewUDPMuxDefault creates an implementation of UDPMux
func NewUDPMuxDefault(params UDPMuxParams) *UDPMuxDefault {
if params.Logger == nil {
params.Logger = logging.NewDefaultLoggerFactory().NewLogger("ice")
}
m := &UDPMuxDefault{
addressMap: map[string]*udpMuxedConn{},
params: params,
+1 -3
View File
@@ -12,7 +12,6 @@ import (
"testing"
"time"
"github.com/pion/logging"
"github.com/pion/stun"
"github.com/pion/transport/test"
"github.com/stretchr/testify/require"
@@ -28,9 +27,8 @@ func TestUDPMux(t *testing.T) {
conn, err := net.ListenUDP(udp, &net.UDPAddr{})
require.NoError(t, err)
loggerFactory := logging.NewDefaultLoggerFactory()
udpMux := NewUDPMuxDefault(UDPMuxParams{
Logger: loggerFactory.NewLogger("ice"),
Logger: nil,
UDPConn: conn,
})