forked from github/cinny
Show call support error and disable join button (#2748)
* allow user to end call if error when loading * show call support missing error if livekit server is not provided * prevent joining from nav item double click if no livekit support
This commit is contained in:
32
src/app/pages/client/AutoDiscovery.tsx
Normal file
32
src/app/pages/client/AutoDiscovery.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import React, { ReactNode, useCallback, useMemo } from 'react';
|
||||
import { AutoDiscoveryInfoProvider } from '../../hooks/useAutoDiscoveryInfo';
|
||||
import { AsyncStatus, useAsyncCallbackValue } from '../../hooks/useAsyncCallback';
|
||||
import { autoDiscovery, AutoDiscoveryInfo } from '../../cs-api';
|
||||
import { getMxIdServer } from '../../utils/matrix';
|
||||
|
||||
type AutoDiscoveryProps = {
|
||||
userId: string;
|
||||
baseUrl: string;
|
||||
children: ReactNode;
|
||||
};
|
||||
export function AutoDiscovery({ userId, baseUrl, children }: AutoDiscoveryProps) {
|
||||
const [state] = useAsyncCallbackValue(
|
||||
useCallback(async () => {
|
||||
const server = getMxIdServer(userId);
|
||||
return autoDiscovery(fetch, server ?? userId);
|
||||
}, [userId])
|
||||
);
|
||||
|
||||
const [, info] = state.status === AsyncStatus.Success ? state.data : [];
|
||||
|
||||
const fallback: AutoDiscoveryInfo = useMemo(
|
||||
() => ({
|
||||
'm.homeserver': {
|
||||
base_url: baseUrl,
|
||||
},
|
||||
}),
|
||||
[baseUrl]
|
||||
);
|
||||
|
||||
return <AutoDiscoveryInfoProvider value={info ?? fallback}>{children}</AutoDiscoveryInfoProvider>;
|
||||
}
|
||||
Reference in New Issue
Block a user