feat: implement CORS proxy for Matrix homeservers during development and refactor call handling logic
This commit is contained in:
@@ -82,26 +82,12 @@ export function useCallService(): CallContextValue {
|
||||
}
|
||||
|
||||
try {
|
||||
// Get LiveKit service URL from Matrix homeserver well-known
|
||||
const wellKnown = await fetchWellKnownWithRTC(baseUrl);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Call service init - well-known:', wellKnown);
|
||||
const livekitFocus = getLiveKitFocus(wellKnown);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Call service init - LiveKit focus:', livekitFocus);
|
||||
const livekitServiceUrl = livekitFocus?.livekit_service_url;
|
||||
|
||||
if (!livekitServiceUrl) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Call service init - No LiveKit config in well-known, calls not supported');
|
||||
setCallSupported(false);
|
||||
setCallSupportLoading(false);
|
||||
return;
|
||||
}
|
||||
// Initialize CallService without checking user's homeserver
|
||||
// Call support will be determined per-room based on available homeservers
|
||||
console.log('Call service init - Initializing (call support determined per-room)');
|
||||
|
||||
service = new CallService(
|
||||
{
|
||||
livekitServiceUrl,
|
||||
homeserverBaseUrl: baseUrl,
|
||||
accessToken,
|
||||
userId,
|
||||
@@ -112,10 +98,10 @@ export function useCallService(): CallContextValue {
|
||||
|
||||
setCallService(service);
|
||||
setGlobalCallService(service); // Make available globally for Paarrot API
|
||||
setCallSupported(true);
|
||||
setCallSupported(true); // Global flag - actual support checked per-room
|
||||
setCallSupportLoading(false);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Call service init - Success! Calls are supported');
|
||||
console.log('Call service init - Success!');
|
||||
|
||||
unsubscribe = service.on((event: CallEvent) => {
|
||||
// Update state for any event that might change the call state
|
||||
@@ -245,8 +231,62 @@ 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, callService } = useCall();
|
||||
const { activeCall, startCall, endCall, callSupported: globalCallSupported, callSupportLoading: globalCallSupportLoading, callService } = useCall();
|
||||
const mx = useMatrixClient();
|
||||
const [roomCallSupported, setRoomCallSupported] = useState(false);
|
||||
const [roomCallSupportLoading, setRoomCallSupportLoading] = useState(true);
|
||||
|
||||
// Check if calls are supported for this specific room by checking all priority homeservers
|
||||
useEffect(() => {
|
||||
const checkRoomCallSupport = async () => {
|
||||
setRoomCallSupportLoading(true);
|
||||
|
||||
const room = mx.getRoom(roomId);
|
||||
if (!room) {
|
||||
setRoomCallSupported(false);
|
||||
setRoomCallSupportLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get homeserver priority list for this room
|
||||
const homeserverPriority = getLiveKitHomeserverPriority(
|
||||
room,
|
||||
mx.getHomeserverUrl(),
|
||||
mx.getSafeUserId()
|
||||
);
|
||||
|
||||
console.log(`Checking call support for room ${roomId}, homeserver priority:`, homeserverPriority);
|
||||
|
||||
// Check each homeserver in priority order
|
||||
for (const homeserver of homeserverPriority) {
|
||||
try {
|
||||
console.log(`Fetching well-known from ${homeserver}...`);
|
||||
const wellKnown = await fetchWellKnownWithRTC(homeserver);
|
||||
console.log(`Well-known response from ${homeserver}:`, wellKnown);
|
||||
|
||||
const livekitFocus = getLiveKitFocus(wellKnown);
|
||||
console.log(`LiveKit focus from ${homeserver}:`, livekitFocus);
|
||||
|
||||
if (livekitFocus) {
|
||||
console.log(`Call support found for room ${roomId} on homeserver: ${homeserver}`);
|
||||
setRoomCallSupported(true);
|
||||
setRoomCallSupportLoading(false);
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`Failed to check call support on ${homeserver}:`, error);
|
||||
// Continue to next homeserver
|
||||
}
|
||||
}
|
||||
|
||||
// No homeserver supports calls
|
||||
console.log(`No call support found for room ${roomId}`);
|
||||
setRoomCallSupported(false);
|
||||
setRoomCallSupportLoading(false);
|
||||
};
|
||||
|
||||
checkRoomCallSupport();
|
||||
}, [roomId, mx]);
|
||||
|
||||
const isInCall = activeCall?.roomId === roomId;
|
||||
const callState = isInCall ? activeCall.state : CallState.Idle;
|
||||
@@ -287,7 +327,7 @@ export function useRoomCall(roomId: string) {
|
||||
startVoiceCall,
|
||||
startVideoCall,
|
||||
endCall,
|
||||
callSupported,
|
||||
callSupportLoading,
|
||||
callSupported: roomCallSupported,
|
||||
callSupportLoading: roomCallSupportLoading,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user