mirror of
https://github.com/livekit/livekit.git
synced 2026-08-28 18:08:17 +00:00
support turn cert itself in config
This commit is contained in:
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
@@ -100,6 +101,8 @@ type TURNConfig struct {
|
||||
Domain string `yaml:"domain"`
|
||||
CertFile string `yaml:"cert_file"`
|
||||
KeyFile string `yaml:"key_file"`
|
||||
Cert string `yaml:"cert"`
|
||||
Key string `yaml:"key"`
|
||||
TLSPort int `yaml:"tls_port"`
|
||||
UDPPort int `yaml:"udp_port"`
|
||||
}
|
||||
@@ -197,6 +200,14 @@ func NewConfig(confString string, c *cli.Context) (*Config, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if conf.TURN.Cert != "" && conf.TURN.CertFile != "" {
|
||||
writeToFile(conf.TURN.CertFile, conf.TURN.Cert, false)
|
||||
}
|
||||
if conf.TURN.Key != "" && conf.TURN.KeyFile != "" {
|
||||
writeToFile(conf.TURN.KeyFile, conf.TURN.Key, false)
|
||||
}
|
||||
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
@@ -257,3 +268,13 @@ func (conf *Config) unmarshalKeys(keys string) error {
|
||||
func GetAudioConfig(conf *Config) AudioConfig {
|
||||
return conf.Audio
|
||||
}
|
||||
|
||||
func writeToFile(path, content string, overwrite bool) {
|
||||
if !overwrite {
|
||||
// check if file exists
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
ioutil.WriteFile(path, []byte(content), 0600)
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ func NewTurnServer(conf *config.Config, authHandler turn.AuthHandler) (*turn.Ser
|
||||
return nil, errors.New("TURN domain required")
|
||||
}
|
||||
|
||||
if IsValidDomain(turnConf.Domain) == false {
|
||||
if !IsValidDomain(turnConf.Domain) {
|
||||
return nil, errors.New("TURN domain is not correct")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate go run github.com/google/wire/cmd/wire
|
||||
//+build !wireinject
|
||||
//go:build !wireinject
|
||||
// +build !wireinject
|
||||
|
||||
package service
|
||||
|
||||
|
||||
Reference in New Issue
Block a user