diff --git a/internal/webrtc/manager.go b/internal/webrtc/manager.go index 01e4f9d1..55355e12 100644 --- a/internal/webrtc/manager.go +++ b/internal/webrtc/manager.go @@ -15,6 +15,7 @@ import ( "demodesk/neko/internal/config" "demodesk/neko/internal/types" + "demodesk/neko/internal/types/codec" "demodesk/neko/internal/types/event" "demodesk/neko/internal/types/message" "demodesk/neko/internal/webrtc/cursor" @@ -117,7 +118,10 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin return nil, types.ErrWebRTCVideoNotFound } - connection, err := manager.newPeerConnection(videoStream.Codec(), logger) + connection, err := manager.newPeerConnection([]codec.RTPCodec{ + videoStream.Codec(), + manager.capture.Audio().Codec(), + }, logger) if err != nil { return nil, err } @@ -244,9 +248,8 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin switch state { case webrtc.PeerConnectionStateConnected: session.SetWebRTCConnected(peer, true) - case webrtc.PeerConnectionStateDisconnected: - fallthrough - case webrtc.PeerConnectionStateFailed: + case webrtc.PeerConnectionStateDisconnected, + webrtc.PeerConnectionStateFailed: connection.Close() case webrtc.PeerConnectionStateClosed: manager.mu.Lock() diff --git a/internal/webrtc/peerconnection.go b/internal/webrtc/peerconnection.go index cab64f2e..15a93c2d 100644 --- a/internal/webrtc/peerconnection.go +++ b/internal/webrtc/peerconnection.go @@ -9,15 +9,24 @@ import ( "github.com/rs/zerolog" ) -func (manager *WebRTCManagerCtx) newPeerConnection(codec codec.RTPCodec, logger zerolog.Logger) (*webrtc.PeerConnection, error) { +func (manager *WebRTCManagerCtx) newPeerConnection(codecs []codec.RTPCodec, logger zerolog.Logger) (*webrtc.PeerConnection, error) { // create media engine - engine, err := manager.mediaEngine(codec) - if err != nil { - return nil, err + engine := &webrtc.MediaEngine{} + for _, codec := range codecs { + if err := codec.Register(engine); err != nil { + return nil, err + } } // create setting engine - settings := manager.settingEngine(logger) + settings := webrtc.SettingEngine{ + LoggerFactory: pionlog.New(logger), + } + + _ = settings.SetEphemeralUDPPortRange(manager.config.EphemeralMin, manager.config.EphemeralMax) + settings.SetICETimeouts(disconnectedTimeout, failedTimeout, keepAliveInterval) + settings.SetNAT1To1IPs(manager.config.NAT1To1IPs, webrtc.ICECandidateTypeHost) + settings.SetLite(manager.config.ICELite) // create interceptor registry registry := &interceptor.Registry{} @@ -37,36 +46,6 @@ func (manager *WebRTCManagerCtx) newPeerConnection(codec codec.RTPCodec, logger return api.NewPeerConnection(configuration) } -func (manager *WebRTCManagerCtx) mediaEngine(codec codec.RTPCodec) (*webrtc.MediaEngine, error) { - engine := &webrtc.MediaEngine{} - - if err := codec.Register(engine); err != nil { - return nil, err - } - - audioCodec := manager.capture.Audio().Codec() - if err := audioCodec.Register(engine); err != nil { - return nil, err - } - - return engine, nil -} - -func (manager *WebRTCManagerCtx) settingEngine(logger zerolog.Logger) webrtc.SettingEngine { - settings := webrtc.SettingEngine{ - LoggerFactory: pionlog.New(logger), - } - - //nolint - settings.SetEphemeralUDPPortRange(manager.config.EphemeralMin, manager.config.EphemeralMax) - settings.SetICETimeouts(disconnectedTimeout, failedTimeout, keepAliveInterval) - settings.SetNAT1To1IPs(manager.config.NAT1To1IPs, webrtc.ICECandidateTypeHost) - //settings.SetSRTPReplayProtectionWindow(512) - settings.SetLite(manager.config.ICELite) - - return settings -} - func (manager *WebRTCManagerCtx) peerConfiguration() webrtc.Configuration { if manager.config.ICELite { return webrtc.Configuration{