add memberId as adress

This commit is contained in:
Timo K
2026-06-25 13:20:48 +02:00
parent a2d609d7cb
commit 16c0214769
5 changed files with 37 additions and 9 deletions

View File

@@ -170,7 +170,7 @@ export const createLocalMembership$ = ({
logger: parentLogger, logger: parentLogger,
muteStates, muteStates,
matrixRTCSession, matrixRTCSession,
roomId: roomId, roomId,
}: Props): { }: Props): {
/** /**
* This request to start audio and video tracks. * This request to start audio and video tracks.

View File

@@ -180,9 +180,28 @@ export const createLocalTransport$ = ({
distinctUntilChanged(areLivekitTransportsEqual), distinctUntilChanged(areLivekitTransportsEqual),
); );
let lockedTransportAddress: string | undefined = undefined;
const preferredTransport$ = combineLatest([preferredConfig$, delayId$]).pipe( const preferredTransport$ = combineLatest([preferredConfig$, delayId$]).pipe(
switchMap(async ([transport, delayId]) => { switchMap(async ([transport, delayId]) => {
try { try {
// We want to copy over the address from the first member on the same sfu.
if (lockedTransportAddress === undefined) {
const firstMemberOnSameSfu = memberships$.value.value.find(
(m) =>
m.transports[0].type === "livekit" &&
m.transports[0].livekit_service_url ===
transport.livekit_service_url,
);
const copiedFromMemberOnSameSfuAddress = (
firstMemberOnSameSfu?.transports[0] as LivekitTransportConfig
)?.address;
const defaultAddress = roomId + ownMembershipIdentity.memberId;
lockedTransportAddress = copiedFromMemberOnSameSfuAddress ?? defaultAddress;
}
transport.address = lockedTransportAddress;
logger.info(
`Update preferredTransport$ ${transport.livekit_service_url} ${transport.address} with delayId ${delayId}`,
);
return await doOpenIdAndJWTFromUrl( return await doOpenIdAndJWTFromUrl(
transport, transport,
forceJwtEndpoint, forceJwtEndpoint,
@@ -308,11 +327,12 @@ async function doOpenIdAndJWTFromUrl(
OpenIDClientParts, OpenIDClientParts,
delayId?: string, delayId?: string,
): Promise<LocalTransportWithSFUConfig> { ): Promise<LocalTransportWithSFUConfig> {
const sfuAddress = transport.address ?? roomId;
const sfuConfig = await getSFUConfigWithOpenID( const sfuConfig = await getSFUConfigWithOpenID(
client, client,
membership, membership,
transport.livekit_service_url, transport.livekit_service_url,
roomId, sfuAddress,
{ {
forceJwtEndpoint: forceJwtEndpoint, forceJwtEndpoint: forceJwtEndpoint,
delayEndpointBaseUrl: client.baseUrl, delayEndpointBaseUrl: client.baseUrl,

View File

@@ -138,7 +138,7 @@ export class Connection {
// TODO: can we just keep the ConnectionOpts object instead of spreading? // TODO: can we just keep the ConnectionOpts object instead of spreading?
private readonly client: OpenIDClientParts; private readonly client: OpenIDClientParts;
private readonly roomId: string; private readonly sfuAddress: string;
private readonly logger: Logger; private readonly logger: Logger;
private readonly ownMembershipIdentity: CallMembershipIdentityParts; private readonly ownMembershipIdentity: CallMembershipIdentityParts;
private readonly existingSFUConfig?: SFUConfig; private readonly existingSFUConfig?: SFUConfig;
@@ -152,12 +152,12 @@ export class Connection {
public constructor(opts: ConnectionOpts, logger: Logger) { public constructor(opts: ConnectionOpts, logger: Logger) {
this.ownMembershipIdentity = opts.ownMembershipIdentity; this.ownMembershipIdentity = opts.ownMembershipIdentity;
this.existingSFUConfig = opts.existingSFUConfig; this.existingSFUConfig = opts.existingSFUConfig;
this.roomId = opts.roomId; this.sfuAddress = opts.transport.address ?? opts.roomId;
this.logger = logger.getChild( this.logger = logger.getChild(
"[Connection " + opts.transport.livekit_service_url + "]", "[Connection " + opts.transport.livekit_service_url + "]",
); );
this.logger.info( this.logger.info(
`constructor: ${opts.transport.livekit_service_url} roomId: ${this.roomId} withSfuConfig?: ${opts.existingSFUConfig ? JSON.stringify(opts.existingSFUConfig) : "undefined"}`, `constructor: ${opts.transport.livekit_service_url} sfuAddress: ${this.sfuAddress} withSfuConfig?: ${opts.existingSFUConfig ? JSON.stringify(opts.existingSFUConfig) : "undefined"}`,
); );
const { transport, client, scope } = opts; const { transport, client, scope } = opts;
@@ -284,7 +284,7 @@ export class Connection {
this.client, this.client,
this.ownMembershipIdentity, this.ownMembershipIdentity,
this.transport.livekit_service_url, this.transport.livekit_service_url,
this.roomId, this.sfuAddress,
// dont pass any custom opts for the subscribe only connections // dont pass any custom opts for the subscribe only connections
{}, {},
this.logger, this.logger,

View File

@@ -45,7 +45,9 @@ export class ConnectionManagerData {
private getKey(transport: LivekitTransportConfig): string { private getKey(transport: LivekitTransportConfig): string {
// This is enough as a key because the ConnectionManager is already scoped by room. // This is enough as a key because the ConnectionManager is already scoped by room.
// We also do not need to consider the slotId at this point since each `MatrixRTCSession` is already scoped by `slotDescription: {id, application}`. // We also do not need to consider the slotId at this point since each `MatrixRTCSession` is already scoped by `slotDescription: {id, application}`.
return transport.livekit_service_url; return (
transport.livekit_service_url +"|"+ (transport.address ?? "default_address")
);
} }
public getConnections(): Connection[] { public getConnections(): Connection[] {
@@ -171,6 +173,7 @@ export function createConnectionManager$({
keys: [ keys: [
transport.transport.livekit_service_url, transport.transport.livekit_service_url,
transport.sfuConfig, transport.sfuConfig,
transport.transport.address,
], ],
data: undefined, data: undefined,
}; };
@@ -179,18 +182,20 @@ export function createConnectionManager$({
keys: [ keys: [
transport.livekit_service_url, transport.livekit_service_url,
undefined as SFUConfig | undefined, undefined as SFUConfig | undefined,
transport.address,
], ],
data: undefined, data: undefined,
}; };
} }
} }
}, },
(scope, _data$, serviceUrl, sfuConfig) => { (scope, _data$, serviceUrl, sfuConfig, address) => {
const connection = connectionFactory.createConnection( const connection = connectionFactory.createConnection(
scope, scope,
{ {
type: "livekit", type: "livekit",
livekit_service_url: serviceUrl, livekit_service_url: serviceUrl,
address,
}, },
ownMembershipIdentity, ownMembershipIdentity,
logger, logger,

View File

@@ -157,7 +157,10 @@ export function areLivekitTransportsEqual<T extends LivekitTransportConfig>(
t2: T | null, t2: T | null,
): boolean { ): boolean {
if (t1 && t2) { if (t1 && t2) {
return t1.livekit_service_url === t2.livekit_service_url; return (
t1.livekit_service_url === t2.livekit_service_url &&
t1.address === t2.address
);
} }
return !t1 && !t2; return !t1 && !t2;
} }