mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
peer configuration multiple codecs.
This commit is contained in:
parent
fa168a53c9
commit
beac1cb088
@ -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()
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user