mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
ICETrickle in config.
This commit is contained in:
parent
cae8201908
commit
c2553b150c
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
type WebRTC struct {
|
type WebRTC struct {
|
||||||
ICELite bool
|
ICELite bool
|
||||||
|
ICETrickle bool
|
||||||
ICEServers []string
|
ICEServers []string
|
||||||
EphemeralMin uint16
|
EphemeralMin uint16
|
||||||
EphemeralMax uint16
|
EphemeralMax uint16
|
||||||
@ -39,11 +40,17 @@ func (WebRTC) Init(cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.PersistentFlags().Bool("icetrickle", true, "configures whether cadidates should be sent asynchronously using Trickle ICE")
|
||||||
|
if err := viper.BindPFlag("icetrickle", cmd.PersistentFlags().Lookup("icetrickle")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WebRTC) Set() {
|
func (s *WebRTC) Set() {
|
||||||
s.ICELite = viper.GetBool("icelite")
|
s.ICELite = viper.GetBool("icelite")
|
||||||
|
s.ICETrickle = viper.GetBool("icetrickle")
|
||||||
s.ICEServers = viper.GetStringSlice("iceserver")
|
s.ICEServers = viper.GetStringSlice("iceserver")
|
||||||
s.NAT1To1IPs = viper.GetStringSlice("nat1to1")
|
s.NAT1To1IPs = viper.GetStringSlice("nat1to1")
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ func (manager *WebRTCManagerCtx) Start() {
|
|||||||
|
|
||||||
manager.logger.Info().
|
manager.logger.Info().
|
||||||
Str("ice_lite", fmt.Sprintf("%t", manager.config.ICELite)).
|
Str("ice_lite", fmt.Sprintf("%t", manager.config.ICELite)).
|
||||||
|
Str("ice_trickle", fmt.Sprintf("%t", manager.config.ICETrickle)).
|
||||||
Str("ice_servers", strings.Join(manager.config.ICEServers, ",")).
|
Str("ice_servers", strings.Join(manager.config.ICEServers, ",")).
|
||||||
Str("ephemeral_port_range", fmt.Sprintf("%d-%d", manager.config.EphemeralMin, manager.config.EphemeralMax)).
|
Str("ephemeral_port_range", fmt.Sprintf("%d-%d", manager.config.EphemeralMin, manager.config.EphemeralMax)).
|
||||||
Str("nat_ips", strings.Join(manager.config.NAT1To1IPs, ",")).
|
Str("nat_ips", strings.Join(manager.config.NAT1To1IPs, ",")).
|
||||||
@ -108,23 +109,25 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (*webrtc.Sess
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Asynchronously send local ICE Candidates
|
// Asynchronously send local ICE Candidates
|
||||||
connection.OnICECandidate(func(candidate *webrtc.ICECandidate) {
|
if manager.config.ICETrickle {
|
||||||
if candidate == nil {
|
connection.OnICECandidate(func(candidate *webrtc.ICECandidate) {
|
||||||
logger.Debug().Msg("all local ice candidates sent")
|
if candidate == nil {
|
||||||
return
|
logger.Debug().Msg("all local ice candidates sent")
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ICECandidateInit := candidate.ToJSON()
|
ICECandidateInit := candidate.ToJSON()
|
||||||
err := session.Send(
|
err := session.Send(
|
||||||
message.SignalCandidate{
|
message.SignalCandidate{
|
||||||
Event: event.SIGNAL_CANDIDATE,
|
Event: event.SIGNAL_CANDIDATE,
|
||||||
ICECandidateInit: &ICECandidateInit,
|
ICECandidateInit: &ICECandidateInit,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn().Err(err).Msg("sending ice candidate failed")
|
logger.Warn().Err(err).Msg("sending ice candidate failed")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if err := manager.registerTracks(connection); err != nil {
|
if err := manager.registerTracks(connection); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -135,8 +138,19 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (*webrtc.Sess
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := connection.SetLocalDescription(offer); err != nil {
|
if !manager.config.ICETrickle {
|
||||||
return nil, err
|
// Create channel that is blocked until ICE Gathering is complete
|
||||||
|
gatherComplete := webrtc.GatheringCompletePromise(connection)
|
||||||
|
|
||||||
|
if err := connection.SetLocalDescription(offer); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
<-gatherComplete
|
||||||
|
} else {
|
||||||
|
if err := connection.SetLocalDescription(offer); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
|
connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
|
||||||
@ -201,7 +215,7 @@ func (manager *WebRTCManagerCtx) apiSettings(logger zerolog.Logger) *webrtc.Sett
|
|||||||
settings.SetEphemeralUDPPortRange(manager.config.EphemeralMin, manager.config.EphemeralMax)
|
settings.SetEphemeralUDPPortRange(manager.config.EphemeralMin, manager.config.EphemeralMax)
|
||||||
settings.SetNAT1To1IPs(manager.config.NAT1To1IPs, webrtc.ICECandidateTypeHost)
|
settings.SetNAT1To1IPs(manager.config.NAT1To1IPs, webrtc.ICECandidateTypeHost)
|
||||||
settings.SetLite(manager.config.ICELite)
|
settings.SetLite(manager.config.ICELite)
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user