From 094be15b05fcdcdecdb0c83b9ec6249319a18ea1 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Mon, 3 Jun 2024 12:39:03 -0700 Subject: [PATCH] updating service field type for future flexibility --- doc/api.oa3 | 4 ++-- net/server/internal/api_addCall.go | 2 +- net/server/internal/api_getNodeConfig.go | 2 +- net/server/internal/api_setNodeConfig.go | 6 +++--- net/server/internal/iceUtil.go | 6 +++--- net/server/internal/models.go | 4 ++-- net/web/src/dashboard/Dashboard.jsx | 10 +++++----- net/web/src/dashboard/useDashboard.hook.js | 14 ++++++++------ 8 files changed, 25 insertions(+), 23 deletions(-) diff --git a/doc/api.oa3 b/doc/api.oa3 index d3068e71..918602e2 100644 --- a/doc/api.oa3 +++ b/doc/api.oa3 @@ -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: diff --git a/net/server/internal/api_addCall.go b/net/server/internal/api_addCall.go index 24e4a227..b94fa904 100644 --- a/net/server/internal/api_addCall.go +++ b/net/server/internal/api_addCall.go @@ -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, "") diff --git a/net/server/internal/api_getNodeConfig.go b/net/server/internal/api_getNodeConfig.go index 795310b4..bc023aee 100644 --- a/net/server/internal/api_getNodeConfig.go +++ b/net/server/internal/api_getNodeConfig.go @@ -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, "") diff --git a/net/server/internal/api_setNodeConfig.go b/net/server/internal/api_setNodeConfig.go index e9b02b34..e170c9e8 100644 --- a/net/server/internal/api_setNodeConfig.go +++ b/net/server/internal/api_setNodeConfig.go @@ -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 } diff --git a/net/server/internal/iceUtil.go b/net/server/internal/iceUtil.go index f1026b87..a0b0b1c1 100644 --- a/net/server/internal/iceUtil.go +++ b/net/server/internal/iceUtil.go @@ -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 diff --git a/net/server/internal/models.go b/net/server/internal/models.go index 265212b2..b64ed1e8 100644 --- a/net/server/internal/models.go +++ b/net/server/internal/models.go @@ -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"` diff --git a/net/web/src/dashboard/Dashboard.jsx b/net/web/src/dashboard/Dashboard.jsx index 721916b1..997f62a4 100644 --- a/net/web/src/dashboard/Dashboard.jsx +++ b/net/web/src/dashboard/Dashboard.jsx @@ -270,11 +270,11 @@ export function Dashboard() {
{state.strings.enableService}
- actions.setIceService(e)} size="small" - defaultChecked={false} checked={state.iceService} /> + actions.setIceServiceFlag(e)} size="small" + defaultChecked={false} checked={state.iceServiceFlag} />
- { !state.iceService && ( + { !state.iceServiceFlag && (
{state.strings.serverUrl}
actions.setIceUrl(e.target.value)} @@ -282,12 +282,12 @@ export function Dashboard() {
)}
-
{state.iceService ? 'TURN_KEY_ID' : state.strings.webUsername}
+
{state.iceServiceFlag ? 'TURN_KEY_ID' : state.strings.webUsername}
actions.setIceUsername(e.target.value)} value={state.iceUsername} />
-
{state.iceService ? 'TURN_KEY_API_TOKEN' : state.strings.webPassword}
+
{state.iceServiceFlag ? 'TURN_KEY_API_TOKEN' : state.strings.webPassword}
actions.setIcePassword(e.target.value)} value={state.icePassword} />
diff --git a/net/web/src/dashboard/useDashboard.hook.js b/net/web/src/dashboard/useDashboard.hook.js index 55439aa5..a0d790ec 100644 --- a/net/web/src/dashboard/useDashboard.hook.js +++ b/net/web/src/dashboard/useDashboard.hook.js @@ -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);