Skip to content

Commit 3c6696b

Browse files
committed
feat: Add STUN servers to enable P2P
This exposes a `--stun-server` option for listing STUN servers. By default it uses the Google STUN server, but this is not required.
1 parent 8ff0c8b commit 3c6696b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cli/server.go

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/coreos/go-systemd/daemon"
2121
"github.com/google/go-github/v43/github"
2222
"github.com/pion/turn/v2"
23+
"github.com/pion/webrtc/v3"
2324
"github.com/spf13/cobra"
2425
"golang.org/x/oauth2"
2526
xgithub "golang.org/x/oauth2/github"
@@ -67,6 +68,7 @@ func server() *cobra.Command {
6768
tlsMinVersion string
6869
turnRelayAddress string
6970
skipTunnel bool
71+
stunServers []string
7072
traceDatadog bool
7173
secureAuthCookie bool
7274
sshKeygenAlgorithmRaw string
@@ -176,8 +178,15 @@ func server() *cobra.Command {
176178
return xerrors.Errorf("create turn server: %w", err)
177179
}
178180

181+
iceServers := make([]webrtc.ICEServer, 0)
182+
for _, stunServer := range stunServers {
183+
iceServers = append(iceServers, webrtc.ICEServer{
184+
URLs: []string{stunServer},
185+
})
186+
}
179187
options := &coderd.Options{
180188
AccessURL: accessURLParsed,
189+
ICEServers: iceServers,
181190
Logger: logger.Named("coderd"),
182191
Database: databasefake.New(),
183192
Pubsub: database.NewPubsubInMemory(),
@@ -411,6 +420,9 @@ func server() *cobra.Command {
411420
`Specifies the minimum supported version of TLS. Accepted values are "tls10", "tls11", "tls12" or "tls13"`)
412421
cliflag.BoolVarP(root.Flags(), &skipTunnel, "skip-tunnel", "", "CODER_DEV_SKIP_TUNNEL", false, "Skip serving dev mode through an exposed tunnel for simple setup.")
413422
_ = root.Flags().MarkHidden("skip-tunnel")
423+
cliflag.StringArrayVarP(root.Flags(), &stunServers, "stun-server", "", "CODER_STUN_SERVERS", []string{
424+
"stun:stun.l.google.com:19302",
425+
}, "Specify URLs for STUN servers to enable P2P connections.")
414426
cliflag.BoolVarP(root.Flags(), &traceDatadog, "trace-datadog", "", "CODER_TRACE_DATADOG", false, "Send tracing data to a datadog agent")
415427
cliflag.StringVarP(root.Flags(), &turnRelayAddress, "turn-relay-address", "", "CODER_TURN_RELAY_ADDRESS", "127.0.0.1",
416428
"Specifies the address to bind TURN connections.")

0 commit comments

Comments
 (0)