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
// 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

View File

@ -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

View File

@ -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}};