Skip to content

Commit

Permalink
webrtc: disable UDP when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Jan 19, 2025
1 parent 4d98628 commit c3f0fb7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions internal/protocols/webrtc/peer_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TracksAreValid(medias []*sdp.MediaDescription) error {
}

if !videoTrack && !audioTrack {
return fmt.Errorf("no valid tracks count")
return fmt.Errorf("no valid tracks found")

Check warning on line 59 in internal/protocols/webrtc/peer_connection.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/peer_connection.go#L59

Added line #L59 was not covered by tests
}

return nil
Expand Down Expand Up @@ -99,6 +99,8 @@ type PeerConnection struct {
func (co *PeerConnection) Start() error {
settingsEngine := webrtc.SettingEngine{}

settingsEngine.SetIncludeLoopbackCandidate(true)

settingsEngine.SetInterfaceFilter(func(iface string) bool {
return co.IPsFromInterfaces && (len(co.IPsFromInterfacesList) == 0 ||
stringInSlice(iface, co.IPsFromInterfacesList))
Expand All @@ -107,26 +109,33 @@ func (co *PeerConnection) Start() error {
settingsEngine.SetAdditionalHosts(co.AdditionalHosts)

var networkTypes []webrtc.NetworkType
enableUDP := false

// always enable UDP in order to support STUN/TURN
networkTypes = append(networkTypes, webrtc.NetworkTypeUDP4)
// UDP is always needed when there's a STUN/TURN server.
if len(co.ICEServers) != 0 {
enableUDP = true
}

Check warning on line 117 in internal/protocols/webrtc/peer_connection.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/peer_connection.go#L116-L117

Added lines #L116 - L117 were not covered by tests

if co.ICEUDPMux != nil {
enableUDP = true

Check warning on line 120 in internal/protocols/webrtc/peer_connection.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/peer_connection.go#L120

Added line #L120 was not covered by tests
settingsEngine.SetICEUDPMux(co.ICEUDPMux)
}

if co.LocalRandomUDP {
enableUDP = true
settingsEngine.SetLocalRandomUDP(true)
}

if co.ICETCPMux != nil {
settingsEngine.SetICETCPMux(co.ICETCPMux)
networkTypes = append(networkTypes, webrtc.NetworkTypeTCP4)
settingsEngine.SetICETCPMux(co.ICETCPMux)

Check warning on line 131 in internal/protocols/webrtc/peer_connection.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/peer_connection.go#L131

Added line #L131 was not covered by tests
}

settingsEngine.SetNetworkTypes(networkTypes)
if enableUDP {
networkTypes = append(networkTypes, webrtc.NetworkTypeUDP4)
}

settingsEngine.SetIncludeLoopbackCandidate(true)
settingsEngine.SetNetworkTypes(networkTypes)

mediaEngine := &webrtc.MediaEngine{}

Expand Down

0 comments on commit c3f0fb7

Please sign in to comment.