Files
element-call-Github/src/room/useRoomName.ts
T
Timo K.andClaude Fable 5.1 6ae4f0539a Leave the page title to the page
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>
2026-09-08 13:53:50 +02:00

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]),
);
}