Skip to content

Commit

Permalink
Add APPEND_CANDIDATE
Browse files Browse the repository at this point in the history
Performs SDP munging so users can insert arbitrary candidates
  • Loading branch information
Sean-Der committed Jul 8, 2024
1 parent 0752132 commit f562696
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ The backend can be configured with the following environment variables.
- `SSL_CERT` - Path to SSL certificate if using Broadcast Box's HTTP Server
- `SSL_KEY` - Path to SSL key if using Broadcast Box's HTTP Server

- `NAT_1_TO_1_IP` - Announce IPs that don't belong to local machine (like Public IP). delineated by ','
- `NAT_1_TO_1_IP` - Announce IPs that don't belong to local machine (like Public IP). delineated by '|'
- `INCLUDE_PUBLIC_IP_IN_NAT_1_TO_1_IP` - Like `NAT_1_TO_1_IP` but autoconfigured
- `INTERFACE_FILTER` - Only use a certain interface for UDP traffic
- `NAT_ICE_CANDIDATE_TYPE` - By default setting a NAT_1_TO_1_IP overrides. Set this to `srflx` to instead append IPs
Expand All @@ -216,6 +216,8 @@ The backend can be configured with the following environment variables.
- `TCP_MUX_ADDRESS` - If you wish to make WebRTC traffic available via TCP.
- `TCP_MUX_FORCE` - If you wish to make WebRTC traffic only available via TCP.

- `APPEND_CANDIDATE` - Append candidates to Offer that ICE Agent did not generate. Worse version of `NAT_1_TO_1_IP`

## Network Test on Start

When running in Docker Broadcast Box runs a network tests on startup. This tests that WebRTC traffic can be established
Expand Down
14 changes: 12 additions & 2 deletions internal/webrtc/webrtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,15 @@ func createSettingEngine(isWHIP bool, udpMuxCache map[int]*ice.MultiUDPMuxDefaul
udpMuxOpts []ice.UDPMuxFromPortOption
err error
)
networkTypes := []webrtc.NetworkType{webrtc.NetworkTypeUDP4, webrtc.NetworkTypeUDP6}
networkTypes := []webrtc.NetworkType{webrtc.NetworkTypeUDP4}
udpMuxOpts = append(udpMuxOpts, ice.UDPMuxFromPortWithNetworks(ice.NetworkTypeUDP4))

if os.Getenv("INCLUDE_PUBLIC_IP_IN_NAT_1_TO_1_IP") != "" {
NAT1To1IPs = append(NAT1To1IPs, getPublicIP())
}

if os.Getenv("NAT_1_TO_1_IP") != "" {
NAT1To1IPs = append(NAT1To1IPs, strings.Split(os.Getenv("NAT_1_TO_1_IP"), ",")...)
NAT1To1IPs = append(NAT1To1IPs, strings.Split(os.Getenv("NAT_1_TO_1_IP"), "|")...)
}

natICECandidateType := webrtc.ICECandidateTypeHost
Expand Down Expand Up @@ -348,6 +349,15 @@ func newPeerConnection(api *webrtc.API) (*webrtc.PeerConnection, error) {
return api.NewPeerConnection(cfg)
}

func appendOffer(in string) string {
if extraCandidate := os.Getenv("APPEND_CANDIDATE"); extraCandidate != "" {
index := strings.Index(in, "a=end-of-candidates")
in = in[:index] + extraCandidate + in[index:]
}

return in
}

func Configure() {
streamMap = map[string]*stream{}

Expand Down
2 changes: 1 addition & 1 deletion internal/webrtc/whep.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func WHEP(offer, streamKey string) (string, string, error) {
timestamp: 50000,
}
stream.whepSessions[whepSessionId].currentLayer.Store("")
return peerConnection.LocalDescription().SDP, whepSessionId, nil
return appendOffer(peerConnection.LocalDescription().SDP), whepSessionId, nil
}

func (w *whepSession) sendVideoPacket(rtpPkt *rtp.Packet, layer string, timeDiff int64, sequenceDiff int, codec videoTrackCodec) {
Expand Down
2 changes: 1 addition & 1 deletion internal/webrtc/whip.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ func WHIP(offer, streamKey string) (string, error) {
}

<-gatherComplete
return peerConnection.LocalDescription().SDP, nil
return appendOffer(peerConnection.LocalDescription().SDP), nil
}

0 comments on commit f562696

Please sign in to comment.