diff --git a/pkg/config/config.go b/pkg/config/config.go index 37037de..882c7a4 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -12,7 +12,7 @@ import ( // Version of the config format - when new fields are added, it will attempt // to write the settings.toml to disk so new defaults populate. -var currentVersion = 2 +var currentVersion = 3 // Config for your BareRTC app. type Config struct { @@ -37,9 +37,17 @@ type Config struct { MaxImageWidth int PreviewImageWidth int + TURN TurnConfig + PublicChannels []Channel } +type TurnConfig struct { + URLs []string + Username string + Credential string +} + // GetChannels returns a JavaScript safe array of the default PublicChannels. func (c Config) GetChannels() template.JS { data, _ := json.Marshal(c.PublicChannels) @@ -90,6 +98,11 @@ func DefaultConfig() Config { }, }, }, + TURN: TurnConfig{ + URLs: []string{ + "stun:stun.l.google.com:19302", + }, + }, } c.JWT.Strict = true return c diff --git a/web/static/js/BareRTC.js b/web/static/js/BareRTC.js index 8cc4722..5fd47ed 100644 --- a/web/static/js/BareRTC.js +++ b/web/static/js/BareRTC.js @@ -2,9 +2,18 @@ // WebRTC configuration. const configuration = { - iceServers: [{ - urls: 'stun:stun.l.google.com:19302' - }] + iceServers: TURN.URLs.map(val => { + let row = { + urls: val, + }; + + if (val.indexOf('turn:') === 0) { + row.username = TURN.Username; + row.credential = TURN.Credential; + } + + return row; + }) }; const FileUploadMaxSize = 1024 * 1024 * 8; // 8 MB diff --git a/web/templates/chat.html b/web/templates/chat.html index 69367fa..5736e3d 100644 --- a/web/templates/chat.html +++ b/web/templates/chat.html @@ -1041,6 +1041,7 @@ const PublicChannels = {{.Config.GetChannels}}; const WebsiteURL = "{{.Config.WebsiteURL}}"; const PermitNSFW = {{AsJS .Config.PermitNSFW}}; +const TURN = {{.Config.TURN}}; const UserJWTToken = {{.JWTTokenString}}; const UserJWTValid = {{if .JWTAuthOK}}true{{else}}false{{end}}; const UserJWTClaims = {{.JWTClaims.ToJSON}};