Add TURN server support

ipad-testing
Noah 2023-06-13 21:57:31 -07:00
parent 92f1e7ba04
commit 4be18ea3a2
3 changed files with 27 additions and 4 deletions

View File

@ -12,7 +12,7 @@ import (
// Version of the config format - when new fields are added, it will attempt // Version of the config format - when new fields are added, it will attempt
// to write the settings.toml to disk so new defaults populate. // to write the settings.toml to disk so new defaults populate.
var currentVersion = 2 var currentVersion = 3
// Config for your BareRTC app. // Config for your BareRTC app.
type Config struct { type Config struct {
@ -37,9 +37,17 @@ type Config struct {
MaxImageWidth int MaxImageWidth int
PreviewImageWidth int PreviewImageWidth int
TURN TurnConfig
PublicChannels []Channel PublicChannels []Channel
} }
type TurnConfig struct {
URLs []string
Username string
Credential string
}
// GetChannels returns a JavaScript safe array of the default PublicChannels. // GetChannels returns a JavaScript safe array of the default PublicChannels.
func (c Config) GetChannels() template.JS { func (c Config) GetChannels() template.JS {
data, _ := json.Marshal(c.PublicChannels) 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 c.JWT.Strict = true
return c return c

View File

@ -2,9 +2,18 @@
// WebRTC configuration. // WebRTC configuration.
const configuration = { const configuration = {
iceServers: [{ iceServers: TURN.URLs.map(val => {
urls: 'stun:stun.l.google.com:19302' 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 const FileUploadMaxSize = 1024 * 1024 * 8; // 8 MB

View File

@ -1041,6 +1041,7 @@
const PublicChannels = {{.Config.GetChannels}}; const PublicChannels = {{.Config.GetChannels}};
const WebsiteURL = "{{.Config.WebsiteURL}}"; const WebsiteURL = "{{.Config.WebsiteURL}}";
const PermitNSFW = {{AsJS .Config.PermitNSFW}}; const PermitNSFW = {{AsJS .Config.PermitNSFW}};
const TURN = {{.Config.TURN}};
const UserJWTToken = {{.JWTTokenString}}; const UserJWTToken = {{.JWTTokenString}};
const UserJWTValid = {{if .JWTAuthOK}}true{{else}}false{{end}}; const UserJWTValid = {{if .JWTAuthOK}}true{{else}}false{{end}};
const UserJWTClaims = {{.JWTClaims.ToJSON}}; const UserJWTClaims = {{.JWTClaims.ToJSON}};