Skip to content

Commit 25f0403

Browse files
authored
Merge pull request #3336 from element-hq/robin/switch-camera-tile
Move the switch camera button to the local user's tile
2 parents 8757445 + f8a051e commit 25f0403

14 files changed

+253
-184
lines changed

src/button/Button.tsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
EndCallIcon,
1717
ShareScreenSolidIcon,
1818
SettingsSolidIcon,
19-
SwitchCameraSolidIcon,
2019
} from "@vector-im/compound-design-tokens/assets/web/icons";
2120

2221
import styles from "./Button.module.css";
@@ -67,23 +66,6 @@ export const VideoButton: FC<VideoButtonProps> = ({ muted, ...props }) => {
6766
);
6867
};
6968

70-
export const SwitchCameraButton: FC<ComponentPropsWithoutRef<"button">> = (
71-
props,
72-
) => {
73-
const { t } = useTranslation();
74-
75-
return (
76-
<Tooltip label={t("switch_camera")}>
77-
<CpdButton
78-
iconOnly
79-
Icon={SwitchCameraSolidIcon}
80-
kind="secondary"
81-
{...props}
82-
/>
83-
</Tooltip>
84-
);
85-
};
86-
8769
interface ShareScreenButtonProps extends ComponentPropsWithoutRef<"button"> {
8870
enabled: boolean;
8971
}

src/grid/TileWrapper.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ const TileWrapper_ = memo(
6161
useDrag((state) => onDrag?.current!(id, state), {
6262
target: ref,
6363
filterTaps: true,
64-
preventScroll: true,
64+
// Previous designs, which allowed tiles to be dragged and dropped around
65+
// the scrolling grid, required us to set preventScroll to true here. But
66+
// our designs no longer call for this, and meanwhile there's a bug in
67+
// use-gesture that causes filterTaps + preventScroll to break buttons
68+
// within tiles (like the 'switch camera' button) on mobile.
69+
// https://github.com/pmndrs/use-gesture/issues/593
6570
});
6671

6772
return (

src/room/InCallView.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ Please see LICENSE in the repository root for full details.
115115

116116
@media (max-width: 340px) {
117117
.invite,
118-
.switchCamera,
119118
.shareScreen {
120119
display: none;
121120
}

src/room/InCallView.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import {
4444
ShareScreenButton,
4545
SettingsButton,
4646
ReactionToggleButton,
47-
SwitchCameraButton,
4847
} from "../button";
4948
import { Header, LeftNav, RightNav, RoomHeaderInfo } from "../Header";
5049
import { type HeaderStyle, useUrlParams } from "../UrlParams";
@@ -94,7 +93,6 @@ import {
9493
useReactionsSender,
9594
} from "../reactions/useReactionsSender";
9695
import { ReactionsAudioRenderer } from "./ReactionAudioRenderer";
97-
import { useSwitchCamera } from "./useSwitchCamera";
9896
import { ReactionsOverlay } from "./ReactionsOverlay";
9997
import { CallEventAudioRenderer } from "./CallEventAudioRenderer";
10098
import {
@@ -318,7 +316,6 @@ export const InCallView: FC<InCallViewProps> = ({
318316
const showFooter = useBehavior(vm.showFooter$);
319317
const earpieceMode = useBehavior(vm.earpieceMode$);
320318
const audioOutputSwitcher = useBehavior(vm.audioOutputSwitcher$);
321-
const switchCamera = useSwitchCamera(vm.localVideo$);
322319
useSubscription(vm.autoLeaveWhenOthersLeft$, onLeave);
323320

324321
// Ideally we could detect taps by listening for click events and checking
@@ -676,15 +673,6 @@ export const InCallView: FC<InCallViewProps> = ({
676673
data-testid="incall_videomute"
677674
/>,
678675
);
679-
if (switchCamera !== null)
680-
buttons.push(
681-
<SwitchCameraButton
682-
key="switch_camera"
683-
className={styles.switchCamera}
684-
onClick={switchCamera}
685-
onTouchEnd={onControlsTouchEnd}
686-
/>,
687-
);
688676
if (canScreenshare && !hideScreensharing) {
689677
buttons.push(
690678
<ShareScreenButton

src/room/LobbyView.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import {
2424
type LocalVideoTrack,
2525
Track,
2626
} from "livekit-client";
27-
import { useObservable, useObservableEagerState } from "observable-hooks";
28-
import { map } from "rxjs";
27+
import { useObservableEagerState } from "observable-hooks";
2928
import { useNavigate } from "react-router-dom";
3029

3130
import inCallStyles from "./InCallView.module.css";
@@ -38,7 +37,6 @@ import {
3837
EndCallButton,
3938
MicButton,
4039
SettingsButton,
41-
SwitchCameraButton,
4240
VideoButton,
4341
} from "../button/Button";
4442
import { SettingsModal, defaultSettingsTab } from "../settings/SettingsModal";
@@ -47,7 +45,6 @@ import { E2eeType } from "../e2ee/e2eeType";
4745
import { Link } from "../button/Link";
4846
import { useMediaDevices } from "../MediaDevicesContext";
4947
import { useInitial } from "../useInitial";
50-
import { useSwitchCamera as useShowSwitchCamera } from "./useSwitchCamera";
5148
import {
5249
useTrackProcessor,
5350
useTrackProcessorSync,
@@ -195,12 +192,6 @@ export const LobbyView: FC<Props> = ({
195192
}, [devices, videoInputId, videoTrack]);
196193

197194
useTrackProcessorSync(videoTrack);
198-
const showSwitchCamera = useShowSwitchCamera(
199-
useObservable(
200-
(inputs$) => inputs$.pipe(map(([video]) => video)),
201-
[videoTrack],
202-
),
203-
);
204195

205196
// TODO: Unify this component with InCallView, so we can get slick joining
206197
// animations and don't have to feel bad about reusing its CSS
@@ -257,9 +248,6 @@ export const LobbyView: FC<Props> = ({
257248
onClick={onVideoPress}
258249
disabled={muteStates.video.setEnabled === null}
259250
/>
260-
{showSwitchCamera && (
261-
<SwitchCameraButton onClick={showSwitchCamera} />
262-
)}
263251
<SettingsButton onClick={openSettings} />
264252
{!confineToRoom && <EndCallButton onClick={onLeaveClick} />}
265253
</div>

src/room/useSwitchCamera.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/state/CallViewModel.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import {
1313
import {
1414
type Room as LivekitRoom,
1515
type LocalParticipant,
16-
LocalVideoTrack,
1716
ParticipantEvent,
1817
type RemoteParticipant,
19-
Track,
2018
} from "livekit-client";
2119
import { RoomStateEvent, type Room, type RoomMember } from "matrix-js-sdk";
2220
import {
@@ -60,7 +58,6 @@ import {
6058
import {
6159
LocalUserMediaViewModel,
6260
type MediaViewModel,
63-
observeTrackReference$,
6461
RemoteUserMediaViewModel,
6562
ScreenShareViewModel,
6663
type UserMediaViewModel,
@@ -263,6 +260,7 @@ class UserMedia {
263260
participant: LocalParticipant | RemoteParticipant | undefined,
264261
encryptionSystem: EncryptionSystem,
265262
livekitRoom: LivekitRoom,
263+
mediaDevices: MediaDevices,
266264
displayname$: Observable<string>,
267265
handRaised$: Observable<Date | null>,
268266
reaction$: Observable<ReactionOption | null>,
@@ -276,6 +274,7 @@ class UserMedia {
276274
this.participant$ as Behavior<LocalParticipant>,
277275
encryptionSystem,
278276
livekitRoom,
277+
mediaDevices,
279278
this.scope.behavior(displayname$),
280279
this.scope.behavior(handRaised$),
281280
this.scope.behavior(reaction$),
@@ -390,18 +389,6 @@ function getRoomMemberFromRtcMember(
390389

391390
// TODO: Move wayyyy more business logic from the call and lobby views into here
392391
export class CallViewModel extends ViewModel {
393-
public readonly localVideo$ = this.scope.behavior<LocalVideoTrack | null>(
394-
observeTrackReference$(
395-
this.livekitRoom.localParticipant,
396-
Track.Source.Camera,
397-
).pipe(
398-
map((trackRef) => {
399-
const track = trackRef?.publication?.track;
400-
return track instanceof LocalVideoTrack ? track : null;
401-
}),
402-
),
403-
);
404-
405392
/**
406393
* The raw list of RemoteParticipants as reported by LiveKit
407394
*/
@@ -616,6 +603,7 @@ export class CallViewModel extends ViewModel {
616603
participant,
617604
this.options.encryptionSystem,
618605
this.livekitRoom,
606+
this.mediaDevices,
619607
this.memberDisplaynames$.pipe(
620608
map((m) => m.get(matrixIdentifier) ?? "[👻]"),
621609
),
@@ -680,6 +668,7 @@ export class CallViewModel extends ViewModel {
680668
participant,
681669
this.options.encryptionSystem,
682670
this.livekitRoom,
671+
this.mediaDevices,
683672
this.memberDisplaynames$.pipe(
684673
map(
685674
(m) => m.get(participant.identity) ?? "[👻]",

0 commit comments

Comments
 (0)