@@ -28,6 +28,7 @@ import {
2828 InlineField ,
2929 Label ,
3030 RadioControl ,
31+ Text ,
3132} from "@vector-im/compound-web" ;
3233
3334import { FieldRow , InputField } from "../input/Input" ;
@@ -41,11 +42,11 @@ import {
4142 matrixRTCMode as matrixRTCModeSetting ,
4243 customLivekitUrl as customLivekitUrlSetting ,
4344 MatrixRTCMode ,
44- useSettingWithLastUpdateReason ,
4545} from "./settings" ;
4646import type { Room as LivekitRoom } from "livekit-client" ;
4747import styles from "./DeveloperSettingsTab.module.css" ;
4848import { useUrlParams } from "../UrlParams" ;
49+ import { getSFUConfigWithOpenID } from "../livekit/openIDSFU" ;
4950
5051interface Props {
5152 client : MatrixClient ;
@@ -93,8 +94,11 @@ export const DeveloperSettingsTab: FC<Props> = ({
9394 alwaysShowIphoneEarpieceSetting ,
9495 ) ;
9596
96- const [ customLivekitUrl , setCustomLivekitUrl , customLivekitUrlUpdateReason ] =
97- useSettingWithLastUpdateReason ( customLivekitUrlSetting ) ;
97+ const [ customLivekitUrlUpdateError , setCustomLivekitUrlUpdateError ] =
98+ useState < string | null > ( null ) ;
99+ const [ customLivekitUrl , setCustomLivekitUrl ] = useSetting (
100+ customLivekitUrlSetting ,
101+ ) ;
98102 const [ customLivekitUrlTextBuffer , setCustomLivekitUrlTextBuffer ] =
99103 useState ( customLivekitUrl ) ;
100104 useEffect ( ( ) => {
@@ -217,11 +221,11 @@ export const DeveloperSettingsTab: FC<Props> = ({
217221 /> { " " }
218222 </ FieldRow >
219223 < EditInPlace
224+ serverInvalid = { customLivekitUrlUpdateError !== null }
220225 onSubmit = { ( e ) => e . preventDefault ( ) }
221226 helpLabel = {
222227 customLivekitUrl === null
223- ? t ( "developer_mode.custom_livekit_url.from_config" ) +
224- ( customLivekitUrlUpdateReason ?? "" )
228+ ? t ( "developer_mode.custom_livekit_url.from_config" )
225229 : t ( "developer_mode.custom_livekit_url.current_url" ) +
226230 customLivekitUrl
227231 }
@@ -230,14 +234,36 @@ export const DeveloperSettingsTab: FC<Props> = ({
230234 savingLabel = { t ( "developer_mode.custom_livekit_url.saving" ) }
231235 cancelButtonLabel = { t ( "developer_mode.custom_livekit_url.reset" ) }
232236 onSave = { useCallback (
233- ( e : React . FormEvent < HTMLFormElement > ) => {
234- setCustomLivekitUrl (
235- customLivekitUrlTextBuffer === ""
236- ? null
237- : customLivekitUrlTextBuffer ,
238- ) ;
237+ async ( e : React . FormEvent < HTMLFormElement > ) : Promise < void > => {
238+ if (
239+ customLivekitUrlTextBuffer === "" ||
240+ customLivekitUrlTextBuffer === null
241+ ) {
242+ setCustomLivekitUrl ( null ) ;
243+ return Promise . resolve ( ) ;
244+ }
245+
246+ try {
247+ logger . debug ( "try setting" ) ;
248+ await getSFUConfigWithOpenID (
249+ client ,
250+ customLivekitUrlTextBuffer ,
251+ "Test-room-alias-" + Date . now ( ) . toString ( ) + client . getUserId ( ) ,
252+ ) ;
253+ logger . debug ( "done setting! Success" ) ;
254+ setCustomLivekitUrlUpdateError ( null ) ;
255+ setCustomLivekitUrl ( customLivekitUrlTextBuffer ) ;
256+ } catch ( e ) {
257+ logger . error ( "failed setting" , e ) ;
258+ setCustomLivekitUrlUpdateError ( "invalid URL (did not update)" ) ;
259+ // automatically unset the error after 4 seconds (2 seconds will be for the save label)
260+ setTimeout ( ( ) => {
261+ logger . debug ( "unsetting error" ) ;
262+ setCustomLivekitUrlUpdateError ( null ) ;
263+ } , 2000 ) ;
264+ }
239265 } ,
240- [ setCustomLivekitUrl , customLivekitUrlTextBuffer ] ,
266+ [ customLivekitUrlTextBuffer , setCustomLivekitUrl , client ] ,
241267 ) }
242268 value = { customLivekitUrlTextBuffer ?? "" }
243269 onChange = { useCallback (
@@ -252,7 +278,13 @@ export const DeveloperSettingsTab: FC<Props> = ({
252278 } ,
253279 [ setCustomLivekitUrl ] ,
254280 ) }
255- />
281+ >
282+ { customLivekitUrlUpdateError !== null && (
283+ < Text size = "sm" priority = "low" >
284+ { customLivekitUrlUpdateError }
285+ </ Text >
286+ ) }
287+ </ EditInPlace >
256288 < Heading as = "h3" type = "body" weight = "semibold" size = "lg" >
257289 { t ( "developer_mode.matrixRTCMode.title" ) }
258290 </ Heading >
0 commit comments