-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrtc_config.go
40 lines (33 loc) · 986 Bytes
/
wrtc_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// WebRTC Config
package main
import (
"os"
"github.com/pion/webrtc/v3"
)
// This function loads WebRTC config from env variables
func loadWebRTCConfig() webrtc.Configuration {
peerConnectionConfig := webrtc.Configuration{
ICEServers: make([]webrtc.ICEServer, 0),
}
// STUN server
stunServer := os.Getenv("STUN_SERVER")
if stunServer != "" {
peerConnectionConfig.ICEServers = append(peerConnectionConfig.ICEServers, webrtc.ICEServer{
URLs: []string{stunServer},
})
} else {
peerConnectionConfig.ICEServers = append(peerConnectionConfig.ICEServers, webrtc.ICEServer{
URLs: []string{"stun:stun.l.google.com:19302"},
})
}
// TURN server
turnServer := os.Getenv("TURN_SERVER")
if turnServer != "" {
peerConnectionConfig.ICEServers = append(peerConnectionConfig.ICEServers, webrtc.ICEServer{
URLs: []string{turnServer},
Username: os.Getenv("TURN_USERNAME"),
Credential: os.Getenv("TURN_PASSWORD"),
})
}
return peerConnectionConfig
}