Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"livekit-client": "^2.18.1",
"lodash-es": "^4.17.21",
"loglevel": "^1.9.1",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#toger5/address-for-transport",
"matrix-widget-api": "^1.16.1",
"node-stdlib-browser": "^1.3.1",
"normalize.css": "^8.0.1",
Expand Down
19 changes: 12 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ allowBuilds:
"@swc/core": true
"core-js": true
"esbuild": true
"matrix-js-sdk@https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/8019fb027ab9c445d2e8e925e00268b93f4c85c1": true
"matrix-js-sdk@https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/8c95727b6278fe7942c20d0b9485f984dd0694b7": true
"protobufjs": true
overrides:
Expand Down
2 changes: 1 addition & 1 deletion src/state/CallViewModel/localMember/LocalMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const createLocalMembership$ = ({
logger: parentLogger,
muteStates,
matrixRTCSession,
roomId: roomId,
roomId,
}: Props): {
/**
* This request to start audio and video tracks.
Expand Down
22 changes: 21 additions & 1 deletion src/state/CallViewModel/localMember/LocalTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,28 @@ export const createLocalTransport$ = ({
distinctUntilChanged(areLivekitTransportsEqual),
);

let lockedTransportAddress: string | undefined = undefined;
const preferredTransport$ = combineLatest([preferredConfig$, delayId$]).pipe(
switchMap(async ([transport, delayId]) => {
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(
transport,
forceJwtEndpoint,
Expand Down Expand Up @@ -308,11 +327,12 @@ async function doOpenIdAndJWTFromUrl(
OpenIDClientParts,
delayId?: string,
): Promise<LocalTransportWithSFUConfig> {
const sfuAddress = transport.address ?? roomId;
const sfuConfig = await getSFUConfigWithOpenID(
client,
membership,
transport.livekit_service_url,
roomId,
sfuAddress,
{
forceJwtEndpoint: forceJwtEndpoint,
delayEndpointBaseUrl: client.baseUrl,
Expand Down
8 changes: 4 additions & 4 deletions src/state/CallViewModel/remoteMembers/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class Connection {

// TODO: can we just keep the ConnectionOpts object instead of spreading?
private readonly client: OpenIDClientParts;
private readonly roomId: string;
private readonly sfuAddress: string;
private readonly logger: Logger;
private readonly ownMembershipIdentity: CallMembershipIdentityParts;
private readonly existingSFUConfig?: SFUConfig;
Expand All @@ -152,12 +152,12 @@ export class Connection {
public constructor(opts: ConnectionOpts, logger: Logger) {
this.ownMembershipIdentity = opts.ownMembershipIdentity;
this.existingSFUConfig = opts.existingSFUConfig;
this.roomId = opts.roomId;
this.sfuAddress = opts.transport.address ?? opts.roomId;
this.logger = logger.getChild(
"[Connection " + opts.transport.livekit_service_url + "]",
);
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;

Expand Down Expand Up @@ -284,7 +284,7 @@ export class Connection {
this.client,
this.ownMembershipIdentity,
this.transport.livekit_service_url,
this.roomId,
this.sfuAddress,
// dont pass any custom opts for the subscribe only connections
{},
this.logger,
Expand Down
9 changes: 7 additions & 2 deletions src/state/CallViewModel/remoteMembers/ConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export class ConnectionManagerData {
private getKey(transport: LivekitTransportConfig): string {
// 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}`.
return transport.livekit_service_url;
return (
transport.livekit_service_url +"|"+ (transport.address ?? "default_address")
);
}

public getConnections(): Connection[] {
Expand Down Expand Up @@ -171,6 +173,7 @@ export function createConnectionManager$({
keys: [
transport.transport.livekit_service_url,
transport.sfuConfig,
transport.transport.address,
],
data: undefined,
};
Expand All @@ -179,18 +182,20 @@ export function createConnectionManager$({
keys: [
transport.livekit_service_url,
undefined as SFUConfig | undefined,
transport.address,
],
data: undefined,
};
}
}
},
(scope, _data$, serviceUrl, sfuConfig) => {
(scope, _data$, serviceUrl, sfuConfig, address) => {
const connection = connectionFactory.createConnection(
scope,
{
type: "livekit",
livekit_service_url: serviceUrl,
address,
},
ownMembershipIdentity,
logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ export function areLivekitTransportsEqual<T extends LivekitTransportConfig>(
t2: T | null,
): boolean {
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;
}
Loading