mirror of
https://github.com/vector-im/element-call.git
synced 2026-09-10 21:55:19 +00:00
The call and the lobby each set `document.title`, so a component embedded in a host renamed the host's tab to "Element Call | <room>". The title belongs to whoever owns the page: the standalone app's RoomPage now sets it, for whichever room it has got as far as knowing about, and the call itself no longer touches it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
33 lines
945 B
TypeScript
33 lines
945 B
TypeScript
/*
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import { type Room, RoomEvent } from "matrix-js-sdk";
|
|
import { useCallback, useSyncExternalStore } from "react";
|
|
|
|
/**
|
|
* The room's name, kept up to date. Null when there is no room yet, for a
|
|
* caller that only sometimes has one.
|
|
*/
|
|
export function useRoomName(room: Room): string;
|
|
export function useRoomName(room: Room | null): string | null;
|
|
export function useRoomName(room: Room | null): string | null {
|
|
const subscribe = useCallback(
|
|
(onChange: () => void) => {
|
|
if (room === null) return (): void => {};
|
|
room.on(RoomEvent.Name, onChange);
|
|
return (): void => {
|
|
room.off(RoomEvent.Name, onChange);
|
|
};
|
|
},
|
|
[room],
|
|
);
|
|
return useSyncExternalStore(
|
|
subscribe,
|
|
useCallback(() => room?.name ?? null, [room]),
|
|
);
|
|
}
|