diff --git a/internal/webrtc/manager.go b/internal/webrtc/manager.go index d33cd212..75a99393 100644 --- a/internal/webrtc/manager.go +++ b/internal/webrtc/manager.go @@ -19,6 +19,7 @@ import ( "demodesk/neko/internal/types/event" "demodesk/neko/internal/types/message" "demodesk/neko/internal/webrtc/cursor" + "demodesk/neko/internal/webrtc/pionlog" ) // the duration without network activity before a Agent is considered disconnected. Default is 5 Seconds @@ -237,10 +238,9 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin peer := &WebRTCPeerCtx{ logger: logger, - api: api, connection: connection, - changeVideo: changeVideo, dataChannel: dataChannel, + changeVideo: changeVideo, iceTrickle: manager.config.ICETrickle, } @@ -373,9 +373,7 @@ func (manager *WebRTCManagerCtx) mediaEngine(videoID string) (*webrtc.MediaEngin func (manager *WebRTCManagerCtx) apiSettings(logger zerolog.Logger) webrtc.SettingEngine { settings := webrtc.SettingEngine{ - LoggerFactory: loggerFactory{ - logger: logger, - }, + LoggerFactory: pionlog.New(logger), } //nolint diff --git a/internal/webrtc/peer.go b/internal/webrtc/peer.go index 49c787fa..3f030826 100644 --- a/internal/webrtc/peer.go +++ b/internal/webrtc/peer.go @@ -10,7 +10,6 @@ import ( type WebRTCPeerCtx struct { mu sync.Mutex logger zerolog.Logger - api *webrtc.API connection *webrtc.PeerConnection dataChannel *webrtc.DataChannel changeVideo func(videoID string) error diff --git a/internal/webrtc/pionlog/factory.go b/internal/webrtc/pionlog/factory.go new file mode 100644 index 00000000..5a3a6beb --- /dev/null +++ b/internal/webrtc/pionlog/factory.go @@ -0,0 +1,27 @@ +package pionlog + +import ( + "github.com/pion/logging" + "github.com/rs/zerolog" +) + +func New(logger zerolog.Logger) Factory { + return Factory{ + Logger: logger.With().Str("submodule", "pion").Logger(), + } +} + +type Factory struct { + Logger zerolog.Logger +} + +func (l Factory) NewLogger(subsystem string) logging.LeveledLogger { + if subsystem == "sctp" { + return nulllog{} + } + + return logger{ + subsystem: subsystem, + logger: l.Logger.With().Str("subsystem", subsystem).Logger(), + } +} diff --git a/internal/webrtc/logger.go b/internal/webrtc/pionlog/logger.go similarity index 57% rename from internal/webrtc/logger.go rename to internal/webrtc/pionlog/logger.go index 92f57a82..7e48d90e 100644 --- a/internal/webrtc/logger.go +++ b/internal/webrtc/pionlog/logger.go @@ -1,26 +1,12 @@ -package webrtc +package pionlog import ( "fmt" "strings" - "github.com/pion/logging" "github.com/rs/zerolog" ) -type nulllog struct{} - -func (l nulllog) Trace(msg string) {} -func (l nulllog) Tracef(format string, args ...interface{}) {} -func (l nulllog) Debug(msg string) {} -func (l nulllog) Debugf(format string, args ...interface{}) {} -func (l nulllog) Info(msg string) {} -func (l nulllog) Infof(format string, args ...interface{}) {} -func (l nulllog) Warn(msg string) {} -func (l nulllog) Warnf(format string, args ...interface{}) {} -func (l nulllog) Error(msg string) {} -func (l nulllog) Errorf(format string, args ...interface{}) {} - type logger struct { logger zerolog.Logger subsystem string @@ -69,18 +55,3 @@ func (l logger) Errorf(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) l.logger.Error().Msg(strings.TrimSpace(msg)) } - -type loggerFactory struct { - logger zerolog.Logger -} - -func (l loggerFactory) NewLogger(subsystem string) logging.LeveledLogger { - if subsystem == "sctp" { - return nulllog{} - } - - return logger{ - subsystem: subsystem, - logger: l.logger.With().Str("submodule", "pion").Str("subsystem", subsystem).Logger(), - } -} diff --git a/internal/webrtc/pionlog/nullog.go b/internal/webrtc/pionlog/nullog.go new file mode 100644 index 00000000..4b9c9e90 --- /dev/null +++ b/internal/webrtc/pionlog/nullog.go @@ -0,0 +1,14 @@ +package pionlog + +type nulllog struct{} + +func (l nulllog) Trace(msg string) {} +func (l nulllog) Tracef(format string, args ...interface{}) {} +func (l nulllog) Debug(msg string) {} +func (l nulllog) Debugf(format string, args ...interface{}) {} +func (l nulllog) Info(msg string) {} +func (l nulllog) Infof(format string, args ...interface{}) {} +func (l nulllog) Warn(msg string) {} +func (l nulllog) Warnf(format string, args ...interface{}) {} +func (l nulllog) Error(msg string) {} +func (l nulllog) Errorf(format string, args ...interface{}) {}