feat: implement remote homeserver handling for LiveKit calls
This commit is contained in:
@@ -22,7 +22,14 @@ import {
|
||||
LiveKitJWTResponse,
|
||||
CallMemberEventContent,
|
||||
} from './types';
|
||||
import { fetchLiveKitJWT, fetchWellKnownWithRTC, getLiveKitFocus, requestOpenIdToken } from './useRtcConfig';
|
||||
import {
|
||||
fetchLiveKitJWT,
|
||||
fetchWellKnownWithRTC,
|
||||
getLiveKitFocus,
|
||||
requestOpenIdToken,
|
||||
fetchLiveKitJWTFromServers,
|
||||
getLiveKitHomeserverPriority,
|
||||
} from './useRtcConfig';
|
||||
import { getAudioSettings, SCREEN_SHARE_RESOLUTIONS, SCREEN_SHARE_BITRATES } from '../settings/audio/Audio';
|
||||
import { getCallSounds, CallSoundType } from './CallSounds';
|
||||
|
||||
@@ -293,23 +300,48 @@ export class CallService {
|
||||
});
|
||||
|
||||
try {
|
||||
// Step 1: Get an OpenID token from the Matrix homeserver
|
||||
const openIdToken = await requestOpenIdToken(
|
||||
// Step 1: Get room and determine which homeservers to try
|
||||
const room = this.matrixClient.getRoom(roomId);
|
||||
if (!room) {
|
||||
throw new Error(`Room ${roomId} not found`);
|
||||
}
|
||||
|
||||
const homeserverPriority = getLiveKitHomeserverPriority(
|
||||
room,
|
||||
this.config.homeserverBaseUrl,
|
||||
this.config.userId,
|
||||
this.config.accessToken
|
||||
this.config.userId
|
||||
);
|
||||
|
||||
// Step 2: Exchange OpenID token for LiveKit JWT
|
||||
console.log('Requesting LiveKit JWT for Matrix room:', roomId);
|
||||
this.livekitJwt = await fetchLiveKitJWT(
|
||||
this.config.livekitServiceUrl,
|
||||
console.log('Trying homeservers in order:', homeserverPriority);
|
||||
|
||||
// Step 2: Try fetching LiveKit JWT from homeservers in priority order
|
||||
const result = await fetchLiveKitJWTFromServers(
|
||||
homeserverPriority,
|
||||
roomId,
|
||||
this.config.userId,
|
||||
this.config.deviceId,
|
||||
openIdToken
|
||||
this.config.accessToken
|
||||
);
|
||||
|
||||
if (!result) {
|
||||
throw new Error('Failed to get LiveKit JWT from any homeserver');
|
||||
}
|
||||
|
||||
this.livekitJwt = result.jwt;
|
||||
|
||||
// Track if using remote homeserver
|
||||
const userHomeserverDomain = this.config.homeserverBaseUrl
|
||||
.replace('https://', '')
|
||||
.replace('http://', '');
|
||||
const usedHomeserverDomain = result.homeserver
|
||||
.replace('https://', '')
|
||||
.replace('http://', '');
|
||||
|
||||
if (usedHomeserverDomain !== userHomeserverDomain) {
|
||||
this.activeCall!.livekitHomeserver = result.homeserver;
|
||||
console.log(`Using remote homeserver for LiveKit: ${result.homeserver}`);
|
||||
}
|
||||
|
||||
console.log('Got LiveKit JWT, connecting to:', this.livekitJwt.url);
|
||||
console.log('LiveKit JWT response:', JSON.stringify(this.livekitJwt));
|
||||
|
||||
@@ -918,6 +950,22 @@ export class CallService {
|
||||
return this.livekitRoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current call is using a remote homeserver for LiveKit
|
||||
* @returns true if using a different homeserver than the user's
|
||||
*/
|
||||
isUsingRemoteHomeserver(): boolean {
|
||||
return !!this.activeCall?.livekitHomeserver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the homeserver being used for LiveKit (if remote)
|
||||
* @returns The remote homeserver URL, or undefined if using user's homeserver
|
||||
*/
|
||||
getLiveKitHomeserver(): string | undefined {
|
||||
return this.activeCall?.livekitHomeserver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts screen sharing with configurable resolution and bitrate
|
||||
* @returns true if screen share started successfully
|
||||
|
||||
Reference in New Issue
Block a user