feat: implement remote homeserver handling for LiveKit calls
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user