mirror of
https://github.com/element-hq/element-web.git
synced 2026-01-11 19:56:47 +00:00
Ensure we react to RTC transport changes in useRoomCall (#31691)
Some checks are pending
Build / Build on macos-14 (push) Waiting to run
Build / Build on ubuntu-24.04 (push) Waiting to run
Build / Build on windows-2022 (push) Waiting to run
Build and Deploy develop / Build & Deploy develop.element.io (push) Waiting to run
Deploy documentation / GitHub Pages (push) Waiting to run
Static Analysis / Typescript Syntax Check (push) Waiting to run
Static Analysis / i18n Check (Element Web) (push) Waiting to run
Static Analysis / i18n Check (Shared Components) (push) Waiting to run
Static Analysis / Rethemendex Check (push) Waiting to run
Static Analysis / ESLint (push) Waiting to run
Static Analysis / Style Lint (push) Waiting to run
Static Analysis / Workflow Lint (push) Waiting to run
Static Analysis / Analyse Dead Code (push) Waiting to run
Deploy documentation / deploy (push) Blocked by required conditions
Shared Component Visual Tests / Run Visual Tests (push) Waiting to run
Some checks are pending
Build / Build on macos-14 (push) Waiting to run
Build / Build on ubuntu-24.04 (push) Waiting to run
Build / Build on windows-2022 (push) Waiting to run
Build and Deploy develop / Build & Deploy develop.element.io (push) Waiting to run
Deploy documentation / GitHub Pages (push) Waiting to run
Static Analysis / Typescript Syntax Check (push) Waiting to run
Static Analysis / i18n Check (Element Web) (push) Waiting to run
Static Analysis / i18n Check (Shared Components) (push) Waiting to run
Static Analysis / Rethemendex Check (push) Waiting to run
Static Analysis / ESLint (push) Waiting to run
Static Analysis / Style Lint (push) Waiting to run
Static Analysis / Workflow Lint (push) Waiting to run
Static Analysis / Analyse Dead Code (push) Waiting to run
Deploy documentation / deploy (push) Blocked by required conditions
Shared Component Visual Tests / Run Visual Tests (push) Waiting to run
This commit is contained in:
parent
7ad6b4b411
commit
06f70d1d7c
3 changed files with 30 additions and 3 deletions
|
|
@ -116,9 +116,12 @@ export const useRoomCall = (
|
|||
return SdkConfig.get("element_call").use_exclusively;
|
||||
}, []);
|
||||
|
||||
const serverIsConfiguredForElementCall = CallStore.instance
|
||||
.getConfiguredRTCTransports()
|
||||
.some((s) => s.type === "livekit" && s.livekit_service_url);
|
||||
const serverIsConfiguredForElementCall = useEventEmitterState(
|
||||
CallStore.instance,
|
||||
CallStoreEvent.TransportsUpdated,
|
||||
() =>
|
||||
CallStore.instance.getConfiguredRTCTransports().some((s) => s.type === "livekit" && s.livekit_service_url),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (useElementCallExclusively && !serverIsConfiguredForElementCall) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ export enum CallStoreEvent {
|
|||
Call = "call",
|
||||
// Signals a change in the active calls
|
||||
ConnectedCalls = "connected_calls",
|
||||
// Signals a change in the configured RTC transports.
|
||||
TransportsUpdated = "transports_updated",
|
||||
}
|
||||
|
||||
export class CallStore extends AsyncStoreWithClient<EmptyObject> {
|
||||
|
|
@ -53,6 +55,7 @@ export class CallStore extends AsyncStoreWithClient<EmptyObject> {
|
|||
*/
|
||||
protected async fetchTransports(): Promise<void> {
|
||||
if (!this.matrixClient) return;
|
||||
this.configuredMatrixRTCTransports.clear();
|
||||
// Prefer checking the proper endpoint for transports.
|
||||
try {
|
||||
const transports = await this.matrixClient._unstable_getRTCTransports();
|
||||
|
|
@ -70,6 +73,7 @@ export class CallStore extends AsyncStoreWithClient<EmptyObject> {
|
|||
if (Array.isArray(foci)) {
|
||||
foci.forEach((foci) => this.configuredMatrixRTCTransports.add(foci));
|
||||
}
|
||||
this.emit(CallStoreEvent.TransportsUpdated);
|
||||
}
|
||||
|
||||
protected async onReady(): Promise<any> {
|
||||
|
|
|
|||
|
|
@ -129,5 +129,25 @@ describe("useRoomCall", () => {
|
|||
expect(result.current.callOptions).toEqual([PlatformCallType.ElementCall, PlatformCallType.LegacyCall]),
|
||||
);
|
||||
});
|
||||
it("Ensure handler reacts to transport changes", async () => {
|
||||
// Clear all transports
|
||||
client._unstable_getRTCTransports.mockResolvedValue([]);
|
||||
client.getClientWellKnown.mockReturnValue({});
|
||||
|
||||
await setupAsyncStoreWithClient(CallStore.instance, client);
|
||||
const { result } = render();
|
||||
|
||||
// Ensure Element Call is not a call option.
|
||||
expect(result.current.callOptions).toEqual([PlatformCallType.LegacyCall]);
|
||||
|
||||
// Now enable a transport and ensure that useRoomCall picks it up reactively.
|
||||
client._unstable_getRTCTransports.mockResolvedValue([
|
||||
{ type: "livekit", livekit_service_url: "https://example.org" },
|
||||
]);
|
||||
await setupAsyncStoreWithClient(CallStore.instance, client);
|
||||
await waitFor(() =>
|
||||
expect(result.current.callOptions).toEqual([PlatformCallType.ElementCall, PlatformCallType.LegacyCall]),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue