feat: enhance call handling by prioritizing homeservers based on active call members
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
|||||||
fetchLiveKitJWTFromServers,
|
fetchLiveKitJWTFromServers,
|
||||||
getLiveKitHomeserverPriority,
|
getLiveKitHomeserverPriority,
|
||||||
} from './useRtcConfig';
|
} from './useRtcConfig';
|
||||||
|
import { getActiveCallMembers } from './useRoomCallMembers';
|
||||||
import { getAudioSettings, SCREEN_SHARE_RESOLUTIONS, SCREEN_SHARE_BITRATES } from '../settings/audio/Audio';
|
import { getAudioSettings, SCREEN_SHARE_RESOLUTIONS, SCREEN_SHARE_BITRATES } from '../settings/audio/Audio';
|
||||||
import { getCallSounds, CallSoundType } from './CallSounds';
|
import { getCallSounds, CallSoundType } from './CallSounds';
|
||||||
|
|
||||||
@@ -306,6 +307,16 @@ export class CallService {
|
|||||||
throw new Error(`Room ${roomId} not found`);
|
throw new Error(`Room ${roomId} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if there's already an active call
|
||||||
|
const activeCallMembers = getActiveCallMembers(room);
|
||||||
|
const isJoiningExistingCall = activeCallMembers.length > 0;
|
||||||
|
|
||||||
|
if (isJoiningExistingCall) {
|
||||||
|
console.log(`Joining existing call with ${activeCallMembers.length} participant(s)`);
|
||||||
|
} else {
|
||||||
|
console.log('Starting new call');
|
||||||
|
}
|
||||||
|
|
||||||
const homeserverPriority = getLiveKitHomeserverPriority(
|
const homeserverPriority = getLiveKitHomeserverPriority(
|
||||||
room,
|
room,
|
||||||
this.config.homeserverBaseUrl,
|
this.config.homeserverBaseUrl,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export interface CallMember {
|
|||||||
* @param room - The Matrix room to check
|
* @param room - The Matrix room to check
|
||||||
* @returns Array of active call members
|
* @returns Array of active call members
|
||||||
*/
|
*/
|
||||||
function getActiveCallMembers(room: Room): CallMember[] {
|
export function getActiveCallMembers(room: Room): CallMember[] {
|
||||||
const members: CallMember[] = [];
|
const members: CallMember[] = [];
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useMatrixClient } from '../../hooks/useMatrixClient';
|
|||||||
import { LiveKitFocus, LiveKitJWTResponse, OpenIdToken, WellKnownWithRTC } from './types';
|
import { LiveKitFocus, LiveKitJWTResponse, OpenIdToken, WellKnownWithRTC } from './types';
|
||||||
import { getMxIdServer } from '../../utils/matrix';
|
import { getMxIdServer } from '../../utils/matrix';
|
||||||
import { guessDmRoomUserId } from '../../utils/matrix';
|
import { guessDmRoomUserId } from '../../utils/matrix';
|
||||||
|
import { getActiveCallMembers } from './useRoomCallMembers';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get room server from room ID (format: !roomid:server.com)
|
* Get room server from room ID (format: !roomid:server.com)
|
||||||
@@ -14,7 +15,8 @@ function getRoomServer(roomId: string): string | undefined {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine which homeservers to try for LiveKit JWT, in priority order
|
* Determine which homeservers to try for LiveKit JWT, in priority order
|
||||||
* @param room - Room to start call in
|
* Prioritizes servers where active call members are located when joining existing calls
|
||||||
|
* @param room - Room to start/join call in
|
||||||
* @param userHomeserver - User's homeserver
|
* @param userHomeserver - User's homeserver
|
||||||
* @param myUserId - Current user's Matrix ID
|
* @param myUserId - Current user's Matrix ID
|
||||||
* @returns Array of homeserver base URLs to try in order
|
* @returns Array of homeserver base URLs to try in order
|
||||||
@@ -28,6 +30,35 @@ export function getLiveKitHomeserverPriority(
|
|||||||
const memberCount = room.getMembers().length;
|
const memberCount = room.getMembers().length;
|
||||||
const isDM = memberCount <= 2;
|
const isDM = memberCount <= 2;
|
||||||
|
|
||||||
|
// Check for active call members
|
||||||
|
const activeCallMembers = getActiveCallMembers(room);
|
||||||
|
const hasActiveCall = activeCallMembers.length > 0;
|
||||||
|
|
||||||
|
if (hasActiveCall) {
|
||||||
|
// Joining existing call - prioritize room's homeserver (where call is hosted)
|
||||||
|
const roomServer = getRoomServer(room.roomId);
|
||||||
|
if (roomServer) {
|
||||||
|
servers.push(`https://${roomServer}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add user's homeserver as fallback
|
||||||
|
const userDomain = userHomeserver.replace('https://', '').replace('http://', '');
|
||||||
|
if (!roomServer || roomServer !== userDomain) {
|
||||||
|
servers.push(userHomeserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For DMs, also try other member's homeserver
|
||||||
|
if (isDM) {
|
||||||
|
const otherUserId = guessDmRoomUserId(room, myUserId);
|
||||||
|
if (otherUserId && otherUserId !== myUserId) {
|
||||||
|
const otherServer = getMxIdServer(otherUserId);
|
||||||
|
if (otherServer && otherServer !== userDomain && otherServer !== roomServer) {
|
||||||
|
servers.push(`https://${otherServer}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Starting new call - use original priority logic
|
||||||
if (isDM) {
|
if (isDM) {
|
||||||
// For DMs: user's homeserver first, then other member's homeserver
|
// For DMs: user's homeserver first, then other member's homeserver
|
||||||
servers.push(userHomeserver);
|
servers.push(userHomeserver);
|
||||||
@@ -35,7 +66,8 @@ export function getLiveKitHomeserverPriority(
|
|||||||
const otherUserId = guessDmRoomUserId(room, myUserId);
|
const otherUserId = guessDmRoomUserId(room, myUserId);
|
||||||
if (otherUserId && otherUserId !== myUserId) {
|
if (otherUserId && otherUserId !== myUserId) {
|
||||||
const otherServer = getMxIdServer(otherUserId);
|
const otherServer = getMxIdServer(otherUserId);
|
||||||
if (otherServer && otherServer !== userHomeserver) {
|
const userDomain = userHomeserver.replace('https://', '').replace('http://', '');
|
||||||
|
if (otherServer && otherServer !== userDomain) {
|
||||||
servers.push(`https://${otherServer}`);
|
servers.push(`https://${otherServer}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,10 +79,12 @@ export function getLiveKitHomeserverPriority(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to user's homeserver if different
|
// Fallback to user's homeserver if different
|
||||||
if (!roomServer || roomServer !== userHomeserver.replace('https://', '').replace('http://', '')) {
|
const userDomain = userHomeserver.replace('https://', '').replace('http://', '');
|
||||||
|
if (!roomServer || roomServer !== userDomain) {
|
||||||
servers.push(userHomeserver);
|
servers.push(userHomeserver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return servers;
|
return servers;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user