updating service field type for future flexibility

This commit is contained in:
Roland Osborne 2024-06-03 12:39:03 -07:00
parent 66c4d5255c
commit 094be15b05
8 changed files with 25 additions and 23 deletions

View File

@ -4120,7 +4120,7 @@ components:
enableIce:
type: boolean
iceService:
type: boolean
type: string
iceUrl:
type: string
iceUsername:
@ -4903,7 +4903,7 @@ components:
type: integer
format: int32
iceService:
type: boolean
type: string
iceUrl:
type: string
iceUsername:

View File

@ -40,7 +40,7 @@ func AddCall(w http.ResponseWriter, r *http.Request) {
return
}
iceService := getBoolConfigValue(CNFIceService, false);
iceService := getStrConfigValue(CNFIceService, "");
iceURL := getStrConfigValue(CNFIceUrl, "")
iceUsername := getStrConfigValue(CNFIceUsername, "")
icePassword := getStrConfigValue(CNFIcePassword, "")

View File

@ -25,7 +25,7 @@ func GetNodeConfig(w http.ResponseWriter, r *http.Request) {
config.KeyType = getStrConfigValue(CNFKeyType, APPRSA2048)
config.PushSupported = getBoolConfigValue(CNFPushSupported, true)
config.EnableIce = getBoolConfigValue(CNFEnableIce, false)
config.IceService = getBoolConfigValue(CNFIceService, false)
config.IceService = getStrConfigValue(CNFIceService, "")
config.IceURL = getStrConfigValue(CNFIceUrl, "")
config.IceUsername = getStrConfigValue(CNFIceUsername, "")
config.IcePassword = getStrConfigValue(CNFIcePassword, "")

View File

@ -109,11 +109,11 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
return res
}
// upsert ice service used
// upsert ice service name
if res := tx.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "config_id"}},
DoUpdates: clause.AssignmentColumns([]string{"bool_value"}),
}).Create(&store.Config{ConfigID: CNFIceService, BoolValue: config.IceService}).Error; res != nil {
DoUpdates: clause.AssignmentColumns([]string{"str_value"}),
}).Create(&store.Config{ConfigID: CNFIceService, StrValue: config.IceService}).Error; res != nil {
return res
}

View File

@ -8,9 +8,9 @@ import (
"strings"
)
func getIce(service bool, urls string, username string, credential string) ([]IceURL, error) {
func getIce(service string, urls string, username string, credential string) ([]IceURL, error) {
if service {
if service != "" {
gen := "https://rtc.live.cloudflare.com/v1/turn/keys/" + username + "/credentials/generate"
req, err := http.NewRequest(http.MethodPost, gen, bytes.NewBuffer([]byte("{\"ttl\": 86400}")))
if err != nil {
@ -46,7 +46,7 @@ func getIce(service bool, urls string, username string, credential string) ([]Ic
}, nil
}
func getDefaultIce(ice []IceURL) IceURL, error {
func getDefaultIce(ice []IceURL) IceURL {
for _, url := range ice {
if strings.HasSuffix(url.URLs, "?transport=udp") {
return url

View File

@ -375,7 +375,7 @@ type NodeConfig struct {
EnableIce bool `json:"enableIce"`
IceService bool `json:"iceService"`
IceService string `json:"iceService"`
IceURL string `json:"iceUrl"`
@ -567,7 +567,7 @@ type Call struct {
KeepAlive int32 `json:"keepAlive"`
IceService bool `json:"iceService"`
IceService string `json:"iceService"`
Ice []IceURL `json:"ice,omitEmpty"`

View File

@ -270,11 +270,11 @@ export function Dashboard() {
<Tooltip placement="topLeft" title={state.strings.serviceHint}>
<div className="field">
<div>{state.strings.enableService}</div>
<Switch onChange={(e) => actions.setIceService(e)} size="small"
defaultChecked={false} checked={state.iceService} />
<Switch onChange={(e) => actions.setIceServiceFlag(e)} size="small"
defaultChecked={false} checked={state.iceServiceFlag} />
</div>
</Tooltip>
{ !state.iceService && (
{ !state.iceServiceFlag && (
<div className="field">
<div>{state.strings.serverUrl}</div>
<Input placeholder={state.strings.urlHint} onChange={(e) => actions.setIceUrl(e.target.value)}
@ -282,12 +282,12 @@ export function Dashboard() {
</div>
)}
<div className="field">
<div>{state.iceService ? 'TURN_KEY_ID' : state.strings.webUsername}</div>
<div>{state.iceServiceFlag ? 'TURN_KEY_ID' : state.strings.webUsername}</div>
<Input placeholder={state.strings.username} onChange={(e) => actions.setIceUsername(e.target.value)}
value={state.iceUsername} />
</div>
<div className="field">
<div>{state.iceService ? 'TURN_KEY_API_TOKEN' : state.strings.webPassword}</div>
<div>{state.iceServiceFlag ? 'TURN_KEY_API_TOKEN' : state.strings.webPassword}</div>
<Input placeholder={state.strings.password} onChange={(e) => actions.setIcePassword(e.target.value)}
value={state.icePassword} />
</div>

View File

@ -27,7 +27,7 @@ export function useDashboard(token) {
enableVideo: null,
enableBinary: null,
enableIce: null,
iceService: null,
iceServiceFlag: null,
iceUrl: null,
iceUsername: null,
icePassword: null,
@ -129,9 +129,9 @@ export function useDashboard(token) {
setEnableIce: (enableIce) => {
updateState({ enableIce });
},
setIceService: (iceService) => {
const iceUrl = iceService ? 'https://rtc.live.cloudflare.com/v1/turn/keys/%%TURN_KEY_ID%%/credentials/generate' : '';
updateState({ iceService, iceUrl });
setIceServiceFlag: (iceServiceFlag) => {
const iceUrl = iceServiceFlag ? 'https://rtc.live.cloudflare.com/v1/turn/keys/%%TURN_KEY_ID%%/credentials/generate' : '';
updateState({ iceServiceFlag, iceUrl });
},
setIceUrl: (iceUrl) => {
updateState({ iceUrl });
@ -186,8 +186,9 @@ export function useDashboard(token) {
if (!state.busy) {
updateState({ busy: true });
try {
const { domain, keyType, accountStorage, pushSupported, transformSupported, allowUnsealed, enableImage, enableAudio, enableVideo, enableBinary, enableIce, iceService, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit } = state;
const { domain, keyType, accountStorage, pushSupported, transformSupported, allowUnsealed, enableImage, enableAudio, enableVideo, enableBinary, enableIce, iceServiceFlag, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit } = state;
const storage = accountStorage * 1073741824;
const iceService = iceServiceFlag ? 'cloudflare' : '';
const config = { domain, accountStorage: storage, keyType, enableImage, enableAudio, enableVideo, enableBinary, pushSupported, transformSupported, allowUnsealed, enableIce, iceService, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit };
await setNodeConfig(app.state.adminToken, config);
updateState({ busy: false, showSettings: false });
@ -206,8 +207,9 @@ export function useDashboard(token) {
const enabled = await getAdminMFAuth(app.state.adminToken);
const config = await getNodeConfig(app.state.adminToken);
const { accountStorage, domain, keyType, pushSupported, transformSupported, allowUnsealed, enableImage, enableAudio, enableVideo, enableBinary, enableIce, iceService, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit } = config;
const iceServiceFlag = iceService === 'cloudflare';
const storage = Math.ceil(accountStorage / 1073741824);
updateState({ mfAuthSet: true, mfaAuthEnabled: enabled, configError: false, domain, accountStorage: storage, keyType, enableImage, enableAudio, enableVideo, enableBinary, pushSupported, transformSupported, allowUnsealed, enableIce, iceService, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit });
updateState({ mfAuthSet: true, mfaAuthEnabled: enabled, configError: false, domain, accountStorage: storage, keyType, enableImage, enableAudio, enableVideo, enableBinary, pushSupported, transformSupported, allowUnsealed, enableIce, iceServiceFlag, iceUrl, iceUsername, icePassword, enableOpenAccess, openAccessLimit });
}
catch(err) {
console.log(err);