Skip to content

Commit 942800a

Browse files
Merge pull request #468 from vector-im/SimonBrandner/feat/local-volume
2 parents 414996c + 0c3dab8 commit 942800a

File tree

10 files changed

+257
-28
lines changed

10 files changed

+257
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"classnames": "^2.3.1",
3939
"color-hash": "^2.0.1",
4040
"events": "^3.3.0",
41-
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#984dd26a138411ef73903ff4e635f2752e0829f2",
41+
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#e876482e62421bb6a1ba58078435c6b3d1210f15",
4242
"mermaid": "^8.13.8",
4343
"normalize.css": "^8.0.1",
4444
"pako": "^2.0.4",

src/button/Button.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { ReactComponent as SettingsIcon } from "../icons/Settings.svg";
3030
import { ReactComponent as AddUserIcon } from "../icons/AddUser.svg";
3131
import { ReactComponent as ArrowDownIcon } from "../icons/ArrowDown.svg";
3232
import { TooltipTrigger } from "../Tooltip";
33+
import { ReactComponent as OverflowIcon } from "../icons/Overflow.svg";
3334

3435
export type ButtonVariant =
3536
| "default"
@@ -237,3 +238,14 @@ export function InviteButton({
237238
</TooltipTrigger>
238239
);
239240
}
241+
242+
export function OptionsButton(props: Omit<Props, "variant">) {
243+
return (
244+
<TooltipTrigger>
245+
<Button variant="icon" {...props}>
246+
<OverflowIcon />
247+
</Button>
248+
{() => "Options"}
249+
</TooltipTrigger>
250+
);
251+
}

src/video-grid/VideoTile.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import classNames from "classnames";
2020
import styles from "./VideoTile.module.css";
2121
import { ReactComponent as MicMutedIcon } from "../icons/MicMuted.svg";
2222
import { ReactComponent as VideoMutedIcon } from "../icons/VideoMuted.svg";
23+
import { OptionsButton } from "../button/Button";
2324

2425
export const VideoTile = forwardRef(
2526
(
@@ -35,6 +36,8 @@ export const VideoTile = forwardRef(
3536
name,
3637
showName,
3738
mediaRef,
39+
onOptionsPress,
40+
showOptions,
3841
...rest
3942
},
4043
ref
@@ -62,13 +65,18 @@ export const VideoTile = forwardRef(
6265
</div>
6366
) : (
6467
(showName || audioMuted || (videoMuted && !noVideo)) && (
65-
<div className={styles.memberName}>
68+
<div className={classNames(styles.infoBubble, styles.memberName)}>
6669
{audioMuted && !(videoMuted && !noVideo) && <MicMutedIcon />}
6770
{videoMuted && !noVideo && <VideoMutedIcon />}
6871
{showName && <span title={name}>{name}</span>}
6972
</div>
7073
)
7174
)}
75+
{showOptions && (
76+
<div className={classNames(styles.infoBubble, styles.optionsButton)}>
77+
<OptionsButton onPress={onOptionsPress} />
78+
</div>
79+
)}
7280
<video ref={mediaRef} playsInline disablePictureInPicture />
7381
</animated.div>
7482
);

src/video-grid/VideoTile.module.css

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@
4444
object-fit: contain;
4545
}
4646

47-
.memberName {
47+
.infoBubble {
4848
position: absolute;
49-
bottom: 16px;
50-
left: 16px;
5149
height: 24px;
5250
padding: 0 8px;
5351
color: white;
@@ -62,6 +60,21 @@
6260
z-index: 1;
6361
}
6462

63+
.optionsButton {
64+
right: 16px;
65+
top: 16px;
66+
}
67+
68+
.optionsButton button svg {
69+
height: 20px;
70+
width: 20px;
71+
}
72+
73+
.memberName {
74+
left: 16px;
75+
bottom: 16px;
76+
}
77+
6578
.memberName > * {
6679
margin-right: 6px;
6780
}

src/video-grid/VideoTileContainer.jsx

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { useCallFeed } from "./useCallFeed";
2020
import { useSpatialMediaStream } from "./useMediaStream";
2121
import { useRoomMemberName } from "./useRoomMemberName";
2222
import { VideoTile } from "./VideoTile";
23+
import { VideoTileSettingsModal } from "./VideoTileSettingsModal";
24+
import { useModalTriggerState } from "../Modal";
2325

2426
export function VideoTileContainer({
2527
item,
@@ -37,6 +39,7 @@ export function VideoTileContainer({
3739
isLocal,
3840
audioMuted,
3941
videoMuted,
42+
localVolume,
4043
noVideo,
4144
speaking,
4245
stream,
@@ -49,26 +52,44 @@ export function VideoTileContainer({
4952
audioOutputDevice,
5053
audioContext,
5154
audioDestination,
52-
isLocal
55+
isLocal,
56+
localVolume
5357
);
58+
const {
59+
modalState: videoTileSettingsModalState,
60+
modalProps: videoTileSettingsModalProps,
61+
} = useModalTriggerState();
62+
const onOptionsPress = () => {
63+
videoTileSettingsModalState.open();
64+
};
5465

5566
// Firefox doesn't respect the disablePictureInPicture attribute
5667
// https://bugzilla.mozilla.org/show_bug.cgi?id=1611831
5768

5869
return (
59-
<VideoTile
60-
isLocal={isLocal}
61-
speaking={speaking && !disableSpeakingIndicator}
62-
audioMuted={audioMuted}
63-
noVideo={noVideo}
64-
videoMuted={videoMuted}
65-
screenshare={purpose === SDPStreamMetadataPurpose.Screenshare}
66-
name={rawDisplayName}
67-
showName={showName}
68-
ref={tileRef}
69-
mediaRef={mediaRef}
70-
avatar={getAvatar && getAvatar(member, width, height)}
71-
{...rest}
72-
/>
70+
<>
71+
<VideoTile
72+
isLocal={isLocal}
73+
speaking={speaking && !disableSpeakingIndicator}
74+
audioMuted={audioMuted}
75+
noVideo={noVideo}
76+
videoMuted={videoMuted}
77+
screenshare={purpose === SDPStreamMetadataPurpose.Screenshare}
78+
name={rawDisplayName}
79+
showName={showName}
80+
ref={tileRef}
81+
mediaRef={mediaRef}
82+
avatar={getAvatar && getAvatar(member, width, height)}
83+
onOptionsPress={onOptionsPress}
84+
showOptions={!item.callFeed.isLocal()}
85+
{...rest}
86+
/>
87+
{videoTileSettingsModalState.isOpen && (
88+
<VideoTileSettingsModal
89+
{...videoTileSettingsModalProps}
90+
feed={item.callFeed}
91+
/>
92+
)}
93+
</>
7394
);
7495
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.content {
2+
margin: 27px 34px;
3+
}
4+
5+
.localVolumePercentage {
6+
width: 3ch;
7+
}
8+
9+
.localVolumeSlider[type="range"] {
10+
-ms-appearance: none;
11+
-moz-appearance: none;
12+
-webkit-appearance: none;
13+
appearance: none;
14+
15+
cursor: pointer;
16+
width: 100%;
17+
}
18+
19+
.localVolumeSlider[type="range"]::-moz-range-track {
20+
-moz-appearance: none;
21+
appearance: none;
22+
23+
height: 4px;
24+
}
25+
.localVolumeSlider[type="range"]::-ms-track {
26+
-ms-appearance: none;
27+
appearance: none;
28+
29+
height: 4px;
30+
}
31+
.localVolumeSlider[type="range"]::-webkit-slider-runnable-track {
32+
-webkit-appearance: none;
33+
appearance: none;
34+
35+
height: 4px;
36+
}
37+
38+
.localVolumeSlider[type="range"]::-moz-range-thumb {
39+
-moz-appearance: none;
40+
appearance: none;
41+
42+
height: 16px;
43+
width: 16px;
44+
margin-top: -6px;
45+
46+
border-radius: 100%;
47+
background: var(--accent);
48+
}
49+
.localVolumeSlider[type="range"]::-ms-thumb {
50+
-ms-appearance: none;
51+
appearance: none;
52+
53+
height: 16px;
54+
width: 16px;
55+
margin-top: -6px;
56+
57+
border-radius: 100%;
58+
background: var(--accent);
59+
}
60+
.localVolumeSlider[type="range"]::-webkit-slider-thumb {
61+
-webkit-appearance: none;
62+
appearance: none;
63+
64+
height: 16px;
65+
width: 16px;
66+
margin-top: -6px;
67+
68+
border-radius: 100%;
69+
background: var(--accent);
70+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright 2022 New Vector Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React, { ChangeEvent, useState } from "react";
18+
import { CallFeed } from "matrix-js-sdk/src/webrtc/callFeed";
19+
20+
import selectInputStyles from "../input/SelectInput.module.css";
21+
import { FieldRow } from "../input/Input";
22+
import { Modal } from "../Modal";
23+
import styles from "./VideoTileSettingsModal.module.css";
24+
25+
interface LocalVolumeProps {
26+
feed: CallFeed;
27+
}
28+
29+
const LocalVolume: React.FC<LocalVolumeProps> = ({
30+
feed,
31+
}: LocalVolumeProps) => {
32+
const [localVolume, setLocalVolume] = useState<number>(feed.getLocalVolume());
33+
34+
const onLocalVolumeChanged = (event: ChangeEvent<HTMLInputElement>) => {
35+
const value: number = +event.target.value;
36+
setLocalVolume(value);
37+
feed.setLocalVolume(value);
38+
};
39+
40+
return (
41+
<>
42+
<h4 className={selectInputStyles.label}> Local Volume </h4>
43+
<FieldRow>
44+
<span className={styles.localVolumePercentage}>
45+
{`${Math.round(localVolume * 100)}%`}
46+
</span>
47+
<input
48+
className={styles.localVolumeSlider}
49+
type="range"
50+
min="0"
51+
max="1"
52+
step="0.01"
53+
value={localVolume}
54+
onChange={onLocalVolumeChanged}
55+
/>
56+
</FieldRow>
57+
</>
58+
);
59+
};
60+
61+
// TODO: Extend ModalProps
62+
interface Props {
63+
feed: CallFeed;
64+
}
65+
66+
export const VideoTileSettingsModal = ({ feed, ...rest }: Props) => {
67+
return (
68+
<Modal title="Feed settings" isDismissable mobileFullScreen {...rest}>
69+
<div className={styles.content}>
70+
<LocalVolume feed={feed} />
71+
</div>
72+
</Modal>
73+
);
74+
};

src/video-grid/useCallFeed.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function getCallFeedState(callFeed) {
2727
: true,
2828
videoMuted: callFeed ? callFeed.isVideoMuted() : true,
2929
audioMuted: callFeed ? callFeed.isAudioMuted() : true,
30+
localVolume: callFeed ? callFeed.getLocalVolume() : 0,
3031
stream: callFeed ? callFeed.stream : undefined,
3132
purpose: callFeed ? callFeed.purpose : undefined,
3233
};
@@ -44,13 +45,18 @@ export function useCallFeed(callFeed) {
4445
setState((prevState) => ({ ...prevState, audioMuted, videoMuted }));
4546
}
4647

48+
function onLocalVolumeChanged(localVolume) {
49+
setState((prevState) => ({ ...prevState, localVolume }));
50+
}
51+
4752
function onUpdateCallFeed() {
4853
setState(getCallFeedState(callFeed));
4954
}
5055

5156
if (callFeed) {
5257
callFeed.on(CallFeedEvent.Speaking, onSpeaking);
5358
callFeed.on(CallFeedEvent.MuteStateChanged, onMuteStateChanged);
59+
callFeed.on(CallFeedEvent.LocalVolumeChanged, onLocalVolumeChanged);
5460
callFeed.on(CallFeedEvent.NewStream, onUpdateCallFeed);
5561
}
5662

@@ -63,6 +69,10 @@ export function useCallFeed(callFeed) {
6369
CallFeedEvent.MuteStateChanged,
6470
onMuteStateChanged
6571
);
72+
callFeed.removeListener(
73+
CallFeedEvent.LocalVolumeChanged,
74+
onLocalVolumeChanged
75+
);
6676
callFeed.removeListener(CallFeedEvent.NewStream, onUpdateCallFeed);
6777
}
6878
};

0 commit comments

Comments
 (0)