Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show your own name on your tile #2530

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion public/locales/en-GB/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
"exit_full_screen": "Exit full screen",
"full_screen": "Full screen",
"mute_for_me": "Mute for me",
"sfu_participant_local": "You",
"volume": "Volume"
}
}
21 changes: 2 additions & 19 deletions src/state/MediaViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,14 @@ import {
startWith,
switchMap,
} from "rxjs";
import { useTranslation } from "react-i18next";
import { useEffect } from "react";

import { ViewModel } from "./ViewModel";
import { useReactiveState } from "../useReactiveState";
import { alwaysShowSelf } from "../settings/settings";

export interface NameData {
/**
* The display name of the participant.
*/
displayName: string;
/**
* The text to be shown on the participant's name tag.
*/
nameTag: string;
}

// TODO: Move this naming logic into the view model
export function useNameData(vm: MediaViewModel): NameData {
const { t } = useTranslation();

export function useDisplayName(vm: MediaViewModel): string {
const [displayName, setDisplayName] = useReactiveState(
() => vm.member?.rawDisplayName ?? "[👻]",
[vm.member],
Expand All @@ -83,11 +69,8 @@ export function useNameData(vm: MediaViewModel): NameData {
};
}
}, [vm.member, setDisplayName]);
const nameTag = vm.local
? t("video_tile.sfu_participant_local")
: displayName;

return { displayName, nameTag };
return displayName;
}

function observeTrackReference(
Expand Down
24 changes: 15 additions & 9 deletions src/tile/GridTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { useObservableEagerState } from "observable-hooks";
import styles from "./GridTile.module.css";
import {
UserMediaViewModel,
useNameData,
useDisplayName,
LocalUserMediaViewModel,
RemoteUserMediaViewModel,
} from "../state/MediaViewModel";
Expand All @@ -60,7 +60,6 @@ interface TileProps {
targetWidth: number;
targetHeight: number;
displayName: string;
nameTag: string;
showSpeakingIndicators: boolean;
}

Expand All @@ -79,7 +78,7 @@ const UserMediaTile = forwardRef<HTMLDivElement, UserMediaTileProps>(
menuStart,
menuEnd,
className,
nameTag,
displayName,
...props
},
ref,
Expand Down Expand Up @@ -134,12 +133,12 @@ const UserMediaTile = forwardRef<HTMLDivElement, UserMediaTileProps>(
className={styles.muteIcon}
/>
}
nameTag={nameTag}
displayName={displayName}
primaryButton={
<Menu
open={menuOpen}
onOpenChange={setMenuOpen}
title={nameTag}
title={displayName}
trigger={
<button aria-label={t("common.options")}>
<OverflowHorizontalIcon aria-hidden width={20} height={20} />
Expand All @@ -156,7 +155,7 @@ const UserMediaTile = forwardRef<HTMLDivElement, UserMediaTileProps>(
);

return (
<ContextMenu title={nameTag} trigger={tile} hasAccessibleAlternative>
<ContextMenu title={displayName} trigger={tile} hasAccessibleAlternative>
{menu}
</ContextMenu>
);
Expand Down Expand Up @@ -282,20 +281,27 @@ interface GridTileProps {

export const GridTile = forwardRef<HTMLDivElement, GridTileProps>(
({ vm, onOpenProfile, ...props }, ref) => {
const nameData = useNameData(vm);
const displayName = useDisplayName(vm);

if (vm instanceof LocalUserMediaViewModel) {
return (
<LocalUserMediaTile
ref={ref}
vm={vm}
onOpenProfile={onOpenProfile}
displayName={displayName}
{...props}
{...nameData}
/>
);
} else {
return <RemoteUserMediaTile ref={ref} vm={vm} {...props} {...nameData} />;
return (
<RemoteUserMediaTile
ref={ref}
vm={vm}
displayName={displayName}
{...props}
/>
);
}
},
);
Expand Down
4 changes: 1 addition & 3 deletions src/tile/MediaView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ interface Props extends ComponentProps<typeof animated.div> {
videoEnabled: boolean;
unencryptedWarning: boolean;
nameTagLeadingIcon?: ReactNode;
nameTag: string;
displayName: string;
primaryButton?: ReactNode;
}
Expand All @@ -58,7 +57,6 @@ export const MediaView = forwardRef<HTMLDivElement, Props>(
videoEnabled,
unencryptedWarning,
nameTagLeadingIcon,
nameTag,
displayName,
primaryButton,
...props
Expand Down Expand Up @@ -100,7 +98,7 @@ export const MediaView = forwardRef<HTMLDivElement, Props>(
<div className={styles.nameTag}>
{nameTagLeadingIcon}
<Text as="span" size="sm" weight="medium" className={styles.name}>
{nameTag}
{displayName}
</Text>
{unencryptedWarning && (
<Tooltip
Expand Down
6 changes: 2 additions & 4 deletions src/tile/SpotlightTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
MediaViewModel,
ScreenShareViewModel,
UserMediaViewModel,
useNameData,
useDisplayName,
} from "../state/MediaViewModel";
import { useInitial } from "../useInitial";
import { useMergedRefs } from "../useMergedRefs";
Expand All @@ -60,7 +60,6 @@ interface SpotlightItemBaseProps {
video: TrackReferenceOrPlaceholder;
member: RoomMember | undefined;
unencryptedWarning: boolean;
nameTag: string;
displayName: string;
}

Expand Down Expand Up @@ -125,7 +124,7 @@ const SpotlightItem = forwardRef<HTMLDivElement, SpotlightItemProps>(
({ vm, targetWidth, targetHeight, intersectionObserver, snap }, theirRef) => {
const ourRef = useRef<HTMLDivElement | null>(null);
const ref = useMergedRefs(ourRef, theirRef);
const { displayName, nameTag } = useNameData(vm);
const displayName = useDisplayName(vm);
const video = useObservableEagerState(vm.video);
const unencryptedWarning = useObservableEagerState(vm.unencryptedWarning);

Expand Down Expand Up @@ -153,7 +152,6 @@ const SpotlightItem = forwardRef<HTMLDivElement, SpotlightItemProps>(
video,
member: vm.member,
unencryptedWarning,
nameTag,
displayName,
};

Expand Down
Loading