feat: implement remote homeserver handling for LiveKit calls

This commit is contained in:
2026-04-20 21:09:22 +10:00
parent a3dac17b7c
commit 9161c4bde2
5 changed files with 216 additions and 16 deletions

View File

@@ -2,7 +2,7 @@ import { createContext, useContext, useState, useCallback, useEffect, useMemo }
import { useMatrixClient } from '../../hooks/useMatrixClient';
import { CallService } from './CallService';
import { ActiveCall, CallEvent, CallEventType, CallState, CallType } from './types';
import { fetchWellKnownWithRTC, getLiveKitFocus } from './useRtcConfig';
import { fetchWellKnownWithRTC, getLiveKitFocus, getLiveKitHomeserverPriority } from './useRtcConfig';
interface CallContextValue {
callService: CallService | null;
@@ -245,10 +245,36 @@ export function useCallService(): CallContextValue {
* Hook to check if a call is active in a specific room
*/
export function useRoomCall(roomId: string) {
const { activeCall, startCall, endCall, callSupported, callSupportLoading } = useCall();
const { activeCall, startCall, endCall, callSupported, callSupportLoading, callService } = useCall();
const mx = useMatrixClient();
const isInCall = activeCall?.roomId === roomId;
const callState = isInCall ? activeCall.state : CallState.Idle;
const isUsingRemoteHomeserver = isInCall ? callService?.isUsingRemoteHomeserver() ?? false : false;
// Check if a remote homeserver WOULD be used (pre-call check)
const wouldUseRemoteHomeserver = useMemo(() => {
if (isInCall) return isUsingRemoteHomeserver;
const room = mx.getRoom(roomId);
if (!room) return false;
const homeserverPriority = getLiveKitHomeserverPriority(
room,
mx.getHomeserverUrl(),
mx.getSafeUserId()
);
// Check if first priority is different from user's homeserver
const userHomeserverDomain = mx.getHomeserverUrl()
.replace('https://', '')
.replace('http://', '');
const firstPriorityDomain = homeserverPriority[0]
?.replace('https://', '')
.replace('http://', '');
return firstPriorityDomain !== userHomeserverDomain;
}, [isInCall, isUsingRemoteHomeserver, mx, roomId]);
const startVoiceCall = useCallback(() => startCall(roomId, CallType.Voice), [roomId, startCall]);
const startVideoCall = useCallback(() => startCall(roomId, CallType.Video), [roomId, startCall]);
@@ -257,6 +283,7 @@ export function useRoomCall(roomId: string) {
isInCall,
callState,
activeCall: isInCall ? activeCall : null,
isUsingRemoteHomeserver: wouldUseRemoteHomeserver,
startVoiceCall,
startVideoCall,
endCall,