Make STUN server configurable

This commit is contained in:
Alexandre Iooss 2020-09-29 17:27:19 +02:00
parent 1c98754624
commit 95f4b81f01
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
6 changed files with 24 additions and 15 deletions

View File

@ -10,7 +10,7 @@ auth:
# Example to bypass login, dangerous!
#backend: bypass
#
# Example of LDAP server login
#backend: ldap
#ldap:
@ -41,3 +41,7 @@ webrtc:
# UDP port range used to stream
minPortUDP: 10000
maxPortUDP: 10005
# STUN servers, you should host your own Coturn instance
STUNServers:
- stun:stun.l.google.com:19302

View File

@ -55,6 +55,10 @@ func loadConfiguration() {
viper.SetDefault("Web.Favicon", "/favicon.ico")
viper.SetDefault("WebRTC.MinPortUDP", 10000)
viper.SetDefault("WebRTC.MaxPortUDP", 10005)
viper.SetDefault("WebRTC.STUNServers", []string{"stun:stun.l.google.com:19302"})
// Copy STUN configuration to clients
viper.Set("Web.STUNServers", viper.Get("WebRTC.STUNServers"))
}
func main() {

View File

@ -18,6 +18,8 @@ import (
type Options struct {
MinPortUDP uint16
MaxPortUDP uint16
STUNServers []string
}
// SessionDescription contains SDP data
@ -65,11 +67,7 @@ func newPeerHandler(remoteSdp webrtc.SessionDescription, cfg *Options) webrtc.Se
webrtc.WithSettingEngine(settingsEngine),
)
peerConnection, err := api.NewPeerConnection(webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
URLs: []string{"stun:stun.l.google.com:19302"},
},
},
ICEServers: []webrtc.ICEServer{{URLs: cfg.STUNServers}},
})
if err != nil {
log.Println("Failed to initiate peer connection", err)

View File

@ -3,12 +3,7 @@ let peerConnection;
startPeerConnection = () => {
// Init peer connection
peerConnection = new RTCPeerConnection({
iceServers: [
{
// FIXME: let admin customize the stun server
urls: 'stun:stun.l.google.com:19302'
}
]
iceServers: [{ urls: stunServers }]
})
// On connection change, change indicator color
@ -80,6 +75,3 @@ startPeerConnection = () => {
}
}
}
// Start
startPeerConnection()

View File

@ -36,4 +36,12 @@
<script src="/static/js/sideWidget.js"></script>
<script src="/static/js/viewer.js"></script>
<script>
const stunServers = [
{{range $id, $value := .Cfg.STUNServers}}
'{{$value}}',
{{end}}
]
startPeerConnection()
</script>
{{end}}

View File

@ -20,6 +20,9 @@ type Options struct {
Hostname string
Favicon string
WidgetURL string
// Copied from WebRTC configuration
STUNServers []string
}
var (