Support for SFUs

Mostly just using the right js-sdk, then adding temporary config for
which SFU to use until we can get it from the homeserver.
This commit is contained in:
David Baker
2022-12-21 18:01:58 +00:00
parent 0880faf312
commit 3220d06616
6 changed files with 41 additions and 14 deletions

View File

@@ -33,7 +33,6 @@ import { ErrorView } from "./FullScreenView";
import {
initClient,
CryptoStoreIntegrityError,
fallbackICEServerAllowed,
} from "./matrix-utils";
import { widget } from "./widget";
import { PosthogAnalytics, RegistrationType } from "./PosthogAnalytics";
@@ -143,7 +142,6 @@ export const ClientProvider: FC<Props> = ({ children }) => {
accessToken: access_token,
userId: user_id,
deviceId: device_id,
fallbackICEServerAllowed: fallbackICEServerAllowed,
},
true
),
@@ -159,7 +157,6 @@ export const ClientProvider: FC<Props> = ({ children }) => {
accessToken: access_token,
userId: user_id,
deviceId: device_id,
fallbackICEServerAllowed: fallbackICEServerAllowed,
},
false // Don't need the crypto store just to log out
);

View File

@@ -28,6 +28,15 @@ export interface ConfigOptions {
server_name: string;
};
};
/**
* Sets the client's preferred SFU
* TEMPORARY: Will be removed in favour of getting SFUs from the homeserver
*/
temp_sfu?: {
user_id: string;
device_id: string;
};
}
// Overrides members from ConfigOptions that are always provided by the

View File

@@ -76,17 +76,22 @@ export async function initClient(
indexedDB = window.indexedDB;
} catch (e) {}
const storeOpts = {} as ICreateClientOpts;
// options we always pass to the client (stuff that we need in order to work)
const baseOpts = {
fallbackICEServerAllowed: fallbackICEServerAllowed,
localSfuUserId: Config.get().temp_sfu.user_id,
localSfuDeviceId: Config.get().temp_sfu.device_id,
} as ICreateClientOpts;
if (indexedDB && localStorage && !import.meta.env.DEV) {
storeOpts.store = new IndexedDBStore({
baseOpts.store = new IndexedDBStore({
indexedDB: window.indexedDB,
localStorage,
dbName: SYNC_STORE_NAME,
workerFactory: () => new IndexedDBWorker(),
});
} else if (localStorage) {
storeOpts.store = new MemoryStore({ localStorage });
baseOpts.store = new MemoryStore({ localStorage });
}
// Check whether we have crypto data store. If we are restoring a session
@@ -118,14 +123,14 @@ export async function initClient(
}
if (indexedDB) {
storeOpts.cryptoStore = new IndexedDBCryptoStore(
baseOpts.cryptoStore = new IndexedDBCryptoStore(
indexedDB,
CRYPTO_STORE_NAME
);
} else if (localStorage) {
storeOpts.cryptoStore = new LocalStorageCryptoStore(localStorage);
baseOpts.cryptoStore = new LocalStorageCryptoStore(localStorage);
} else {
storeOpts.cryptoStore = new MemoryCryptoStore();
baseOpts.cryptoStore = new MemoryCryptoStore();
}
// XXX: we read from the URL params in RoomPage too:
@@ -139,7 +144,7 @@ export async function initClient(
}
const client = createClient({
...storeOpts,
...baseOpts,
...clientOptions,
useAuthorizationHeader: true,
// Use a relatively low timeout for API calls: this is a realtime app