fixup merge
This commit is contained in:
@@ -101,12 +101,7 @@ export async function createMatrixRTCSdk(
|
|||||||
const mediaDevices = new MediaDevices(scope);
|
const mediaDevices = new MediaDevices(scope);
|
||||||
const muteStates = new MuteStates(scope, mediaDevices, constant(true));
|
const muteStates = new MuteStates(scope, mediaDevices, constant(true));
|
||||||
const slot = { application, id };
|
const slot = { application, id };
|
||||||
const rtcSession = new MatrixRTCSession(
|
const rtcSession = new MatrixRTCSession(client, room, slot);
|
||||||
client,
|
|
||||||
room,
|
|
||||||
MatrixRTCSession.sessionMembershipsForSlot(room, slot),
|
|
||||||
slot,
|
|
||||||
);
|
|
||||||
const callViewModel = createCallViewModel$(
|
const callViewModel = createCallViewModel$(
|
||||||
scope,
|
scope,
|
||||||
rtcSession,
|
rtcSession,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import fetchMock from "fetch-mock";
|
|||||||
|
|
||||||
import { getSFUConfigWithOpenID, type OpenIDClientParts } from "./openIDSFU";
|
import { getSFUConfigWithOpenID, type OpenIDClientParts } from "./openIDSFU";
|
||||||
import { testJWTToken } from "../utils/test-fixtures";
|
import { testJWTToken } from "../utils/test-fixtures";
|
||||||
|
import { ownMemberMock } from "../utils/test";
|
||||||
|
|
||||||
const sfuUrl = "https://sfu.example.org";
|
const sfuUrl = "https://sfu.example.org";
|
||||||
|
|
||||||
@@ -42,7 +43,9 @@ describe("getSFUConfigWithOpenID", () => {
|
|||||||
});
|
});
|
||||||
const config = await getSFUConfigWithOpenID(
|
const config = await getSFUConfigWithOpenID(
|
||||||
matrixClient,
|
matrixClient,
|
||||||
|
ownMemberMock,
|
||||||
"https://sfu.example.org",
|
"https://sfu.example.org",
|
||||||
|
false,
|
||||||
"!example_room_id",
|
"!example_room_id",
|
||||||
);
|
);
|
||||||
expect(config).toEqual({
|
expect(config).toEqual({
|
||||||
@@ -63,7 +66,9 @@ describe("getSFUConfigWithOpenID", () => {
|
|||||||
try {
|
try {
|
||||||
await getSFUConfigWithOpenID(
|
await getSFUConfigWithOpenID(
|
||||||
matrixClient,
|
matrixClient,
|
||||||
|
ownMemberMock,
|
||||||
"https://sfu.example.org",
|
"https://sfu.example.org",
|
||||||
|
false,
|
||||||
"!example_room_id",
|
"!example_room_id",
|
||||||
);
|
);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@@ -98,7 +103,9 @@ describe("getSFUConfigWithOpenID", () => {
|
|||||||
});
|
});
|
||||||
const config = await getSFUConfigWithOpenID(
|
const config = await getSFUConfigWithOpenID(
|
||||||
matrixClient,
|
matrixClient,
|
||||||
|
ownMemberMock,
|
||||||
"https://sfu.example.org",
|
"https://sfu.example.org",
|
||||||
|
false,
|
||||||
"!example_room_id",
|
"!example_room_id",
|
||||||
);
|
);
|
||||||
expect(config).toEqual({
|
expect(config).toEqual({
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ describe("LocalTransport", () => {
|
|||||||
useOldestMember$: constant(false),
|
useOldestMember$: constant(false),
|
||||||
memberships$: constant(new Epoch<CallMembership[]>([])),
|
memberships$: constant(new Epoch<CallMembership[]>([])),
|
||||||
client: {
|
client: {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
_unstable_getRTCTransports: async () => Promise.resolve([]),
|
||||||
getDomain: () => "",
|
getDomain: () => "",
|
||||||
baseUrl: "example.org",
|
baseUrl: "example.org",
|
||||||
// These won't be called in this error path but satisfy the type
|
// These won't be called in this error path but satisfy the type
|
||||||
@@ -130,6 +132,8 @@ describe("LocalTransport", () => {
|
|||||||
useOldestMember$: constant(false),
|
useOldestMember$: constant(false),
|
||||||
memberships$: constant(new Epoch<CallMembership[]>([])),
|
memberships$: constant(new Epoch<CallMembership[]>([])),
|
||||||
client: {
|
client: {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
_unstable_getRTCTransports: async () => Promise.resolve([]),
|
||||||
getDomain: () => "",
|
getDomain: () => "",
|
||||||
getOpenIdToken: vi.fn(),
|
getOpenIdToken: vi.fn(),
|
||||||
getDeviceId: vi.fn(),
|
getDeviceId: vi.fn(),
|
||||||
@@ -140,7 +144,12 @@ describe("LocalTransport", () => {
|
|||||||
delayId$: constant("delay_id_mock"),
|
delayId$: constant("delay_id_mock"),
|
||||||
});
|
});
|
||||||
|
|
||||||
openIdResolver.resolve?.({ url: "https://lk.example.org", jwt: "jwt" });
|
openIdResolver.resolve?.({
|
||||||
|
url: "https://lk.example.org",
|
||||||
|
jwt: "jwt",
|
||||||
|
livekitAlias: "!room:example.org",
|
||||||
|
livekitIdentity: ownMemberMock.userId + ":" + ownMemberMock.deviceId,
|
||||||
|
});
|
||||||
expect(localTransport$.value).toBe(null);
|
expect(localTransport$.value).toBe(null);
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
// final
|
// final
|
||||||
@@ -203,11 +212,15 @@ describe("LocalTransport", () => {
|
|||||||
mockConfig({});
|
mockConfig({});
|
||||||
customLivekitUrl.setValue(customLivekitUrl.defaultValue);
|
customLivekitUrl.setValue(customLivekitUrl.defaultValue);
|
||||||
localTransportOpts = {
|
localTransportOpts = {
|
||||||
|
ownMembershipIdentity: ownMemberMock,
|
||||||
scope,
|
scope,
|
||||||
roomId: "!example_room_id",
|
roomId: "!example_room_id",
|
||||||
useOldestMember$: constant(false),
|
useOldestMember$: constant(false),
|
||||||
|
useOldJwtEndpoint$: constant(false),
|
||||||
|
delayId$: constant(null),
|
||||||
memberships$: constant(new Epoch<CallMembership[]>([])),
|
memberships$: constant(new Epoch<CallMembership[]>([])),
|
||||||
client: {
|
client: {
|
||||||
|
baseUrl: "https://example.org",
|
||||||
getDomain: vi.fn().mockReturnValue(""),
|
getDomain: vi.fn().mockReturnValue(""),
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
_unstable_getRTCTransports: vi.fn().mockResolvedValue([]),
|
_unstable_getRTCTransports: vi.fn().mockResolvedValue([]),
|
||||||
@@ -317,11 +330,15 @@ describe("LocalTransport", () => {
|
|||||||
it("throws if no options are available", async () => {
|
it("throws if no options are available", async () => {
|
||||||
const localTransport$ = createLocalTransport$({
|
const localTransport$ = createLocalTransport$({
|
||||||
scope,
|
scope,
|
||||||
|
ownMembershipIdentity: ownMemberMock,
|
||||||
roomId: "!example_room_id",
|
roomId: "!example_room_id",
|
||||||
useOldestMember$: constant(false),
|
useOldestMember$: constant(false),
|
||||||
|
useOldJwtEndpoint$: constant(false),
|
||||||
|
delayId$: constant(null),
|
||||||
memberships$: constant(new Epoch<CallMembership[]>([])),
|
memberships$: constant(new Epoch<CallMembership[]>([])),
|
||||||
client: {
|
client: {
|
||||||
getDomain: () => "",
|
getDomain: () => "",
|
||||||
|
baseUrl: "https://example.org",
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
_unstable_getRTCTransports: async () => Promise.resolve([]),
|
_unstable_getRTCTransports: async () => Promise.resolve([]),
|
||||||
// These won't be called in this error path but satisfy the type
|
// These won't be called in this error path but satisfy the type
|
||||||
|
|||||||
@@ -178,7 +178,6 @@ async function makeTransport(
|
|||||||
forceOldJwtEndpoint: boolean,
|
forceOldJwtEndpoint: boolean,
|
||||||
delayId?: string,
|
delayId?: string,
|
||||||
): Promise<LivekitTransport & { forceOldJwtEndpoint: boolean }> {
|
): Promise<LivekitTransport & { forceOldJwtEndpoint: boolean }> {
|
||||||
let transport: LivekitTransport | undefined;
|
|
||||||
logger.trace("Searching for a preferred transport");
|
logger.trace("Searching for a preferred transport");
|
||||||
|
|
||||||
// We will call `getSFUConfigWithOpenID` once per transport here as it's our
|
// We will call `getSFUConfigWithOpenID` once per transport here as it's our
|
||||||
@@ -194,32 +193,47 @@ async function makeTransport(
|
|||||||
logger.info("Using LiveKit transport from dev tools: ", urlFromDevSettings);
|
logger.info("Using LiveKit transport from dev tools: ", urlFromDevSettings);
|
||||||
// Validate that the SFU is up. Otherwise, we want to fail on this
|
// Validate that the SFU is up. Otherwise, we want to fail on this
|
||||||
// as we don't permit other SFUs.
|
// as we don't permit other SFUs.
|
||||||
const config = await getSFUConfigWithOpenID(
|
// This will call the jwt/sfu/get endpoint to pre create the livekit room.
|
||||||
|
const { livekitAlias } = await getSFUConfigWithOpenID(
|
||||||
client,
|
client,
|
||||||
|
membership,
|
||||||
urlFromDevSettings,
|
urlFromDevSettings,
|
||||||
|
forceOldJwtEndpoint,
|
||||||
roomId,
|
roomId,
|
||||||
|
client.baseUrl,
|
||||||
|
delayId,
|
||||||
|
logger,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
type: "livekit",
|
type: "livekit",
|
||||||
livekit_service_url: urlFromDevSettings,
|
livekit_service_url: urlFromDevSettings,
|
||||||
livekit_alias: config.livekitAlias,
|
livekit_alias: livekitAlias,
|
||||||
|
forceOldJwtEndpoint,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFirstUsableTransport(
|
async function getFirstUsableTransport(
|
||||||
transports: Transport[],
|
transports: Transport[],
|
||||||
): Promise<LivekitTransport | null> {
|
): Promise<(LivekitTransport & { forceOldJwtEndpoint: boolean }) | null> {
|
||||||
for (const potentialTransport of transports) {
|
for (const potentialTransport of transports) {
|
||||||
if (isLivekitTransportConfig(potentialTransport)) {
|
if (isLivekitTransportConfig(potentialTransport)) {
|
||||||
try {
|
try {
|
||||||
|
// This will call the jwt/sfu/get endpoint to pre create the livekit room.
|
||||||
const { livekitAlias } = await getSFUConfigWithOpenID(
|
const { livekitAlias } = await getSFUConfigWithOpenID(
|
||||||
client,
|
client,
|
||||||
|
membership,
|
||||||
potentialTransport.livekit_service_url,
|
potentialTransport.livekit_service_url,
|
||||||
|
forceOldJwtEndpoint,
|
||||||
roomId,
|
roomId,
|
||||||
|
client.baseUrl,
|
||||||
|
delayId,
|
||||||
|
logger,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...potentialTransport,
|
...potentialTransport,
|
||||||
livekit_alias: livekitAlias,
|
livekit_alias: livekitAlias,
|
||||||
|
forceOldJwtEndpoint,
|
||||||
};
|
};
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
if (ex instanceof FailToGetOpenIdToken) {
|
if (ex instanceof FailToGetOpenIdToken) {
|
||||||
@@ -283,10 +297,16 @@ async function makeTransport(
|
|||||||
const urlFromConf = Config.get().livekit?.livekit_service_url;
|
const urlFromConf = Config.get().livekit?.livekit_service_url;
|
||||||
if (urlFromConf) {
|
if (urlFromConf) {
|
||||||
try {
|
try {
|
||||||
|
// This will call the jwt/sfu/get endpoint to pre create the livekit room.
|
||||||
const { livekitAlias } = await getSFUConfigWithOpenID(
|
const { livekitAlias } = await getSFUConfigWithOpenID(
|
||||||
client,
|
client,
|
||||||
|
membership,
|
||||||
urlFromConf,
|
urlFromConf,
|
||||||
|
forceOldJwtEndpoint,
|
||||||
roomId,
|
roomId,
|
||||||
|
client.baseUrl,
|
||||||
|
delayId,
|
||||||
|
logger,
|
||||||
);
|
);
|
||||||
const selectedTransport: LivekitTransport = {
|
const selectedTransport: LivekitTransport = {
|
||||||
type: "livekit",
|
type: "livekit",
|
||||||
@@ -294,7 +314,7 @@ async function makeTransport(
|
|||||||
livekit_alias: livekitAlias,
|
livekit_alias: livekitAlias,
|
||||||
};
|
};
|
||||||
logger.info("Using config SFU", selectedTransport);
|
logger.info("Using config SFU", selectedTransport);
|
||||||
return selectedTransport;
|
return { ...selectedTransport, forceOldJwtEndpoint };
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
if (ex instanceof FailToGetOpenIdToken) {
|
if (ex instanceof FailToGetOpenIdToken) {
|
||||||
throw ex;
|
throw ex;
|
||||||
@@ -303,19 +323,6 @@ async function makeTransport(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!transport) throw new MatrixRTCTransportMissingError(domain ?? "");
|
// If we do not have returned a transport by now we throw an error
|
||||||
|
throw new MatrixRTCTransportMissingError(domain ?? "");
|
||||||
// this will call the jwt/sfu/get endpoint to pre create the livekit room.
|
|
||||||
await getSFUConfigWithOpenID(
|
|
||||||
client,
|
|
||||||
membership,
|
|
||||||
transport.livekit_service_url,
|
|
||||||
forceOldJwtEndpoint,
|
|
||||||
transport.livekit_alias,
|
|
||||||
client.baseUrl,
|
|
||||||
delayId,
|
|
||||||
logger,
|
|
||||||
);
|
|
||||||
|
|
||||||
return { ...transport, forceOldJwtEndpoint };
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user