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

Add local volume control #468

Merged
merged 12 commits into from
Jul 28, 2022
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"classnames": "^2.3.1",
"color-hash": "^2.0.1",
"events": "^3.3.0",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#984dd26a138411ef73903ff4e635f2752e0829f2",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#e876482e62421bb6a1ba58078435c6b3d1210f15",
"mermaid": "^8.13.8",
"normalize.css": "^8.0.1",
"pako": "^2.0.4",
Expand Down
12 changes: 12 additions & 0 deletions src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ReactComponent as SettingsIcon } from "../icons/Settings.svg";
import { ReactComponent as AddUserIcon } from "../icons/AddUser.svg";
import { ReactComponent as ArrowDownIcon } from "../icons/ArrowDown.svg";
import { TooltipTrigger } from "../Tooltip";
import { ReactComponent as OverflowIcon } from "../icons/Overflow.svg";

export type ButtonVariant =
| "default"
Expand Down Expand Up @@ -237,3 +238,14 @@ export function InviteButton({
</TooltipTrigger>
);
}

export function OptionsButton(props: Omit<Props, "variant">) {
return (
<TooltipTrigger>
<Button variant="icon" {...props}>
<OverflowIcon />
</Button>
{() => "Options"}
</TooltipTrigger>
);
}
10 changes: 9 additions & 1 deletion src/video-grid/VideoTile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import classNames from "classnames";
import styles from "./VideoTile.module.css";
import { ReactComponent as MicMutedIcon } from "../icons/MicMuted.svg";
import { ReactComponent as VideoMutedIcon } from "../icons/VideoMuted.svg";
import { OptionsButton } from "../button/Button";

export const VideoTile = forwardRef(
(
Expand All @@ -35,6 +36,8 @@ export const VideoTile = forwardRef(
name,
showName,
mediaRef,
onOptionsPress,
showOptions,
...rest
},
ref
Expand Down Expand Up @@ -62,13 +65,18 @@ export const VideoTile = forwardRef(
</div>
) : (
(showName || audioMuted || (videoMuted && !noVideo)) && (
<div className={styles.memberName}>
<div className={classNames(styles.infoBubble, styles.memberName)}>
{audioMuted && !(videoMuted && !noVideo) && <MicMutedIcon />}
{videoMuted && !noVideo && <VideoMutedIcon />}
{showName && <span title={name}>{name}</span>}
</div>
)
)}
{showOptions && (
<div className={classNames(styles.infoBubble, styles.optionsButton)}>
<OptionsButton onPress={onOptionsPress} />
</div>
)}
<video ref={mediaRef} playsInline disablePictureInPicture />
</animated.div>
);
Expand Down
19 changes: 16 additions & 3 deletions src/video-grid/VideoTile.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@
object-fit: contain;
}

.memberName {
.infoBubble {
position: absolute;
bottom: 16px;
left: 16px;
height: 24px;
padding: 0 8px;
color: white;
Expand All @@ -62,6 +60,21 @@
z-index: 1;
}

.optionsButton {
right: 16px;
top: 16px;
}

.optionsButton button svg {
height: 20px;
width: 20px;
}

.memberName {
left: 16px;
bottom: 16px;
}

.memberName > * {
margin-right: 6px;
}
Expand Down
51 changes: 36 additions & 15 deletions src/video-grid/VideoTileContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { useCallFeed } from "./useCallFeed";
import { useSpatialMediaStream } from "./useMediaStream";
import { useRoomMemberName } from "./useRoomMemberName";
import { VideoTile } from "./VideoTile";
import { VideoTileSettingsModal } from "./VideoTileSettingsModal";
import { useModalTriggerState } from "../Modal";

export function VideoTileContainer({
item,
Expand All @@ -37,6 +39,7 @@ export function VideoTileContainer({
isLocal,
audioMuted,
videoMuted,
localVolume,
noVideo,
speaking,
stream,
Expand All @@ -49,26 +52,44 @@ export function VideoTileContainer({
audioOutputDevice,
audioContext,
audioDestination,
isLocal
isLocal,
localVolume
);
const {
modalState: videoTileSettingsModalState,
modalProps: videoTileSettingsModalProps,
} = useModalTriggerState();
const onOptionsPress = () => {
videoTileSettingsModalState.open();
};

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

return (
<VideoTile
isLocal={isLocal}
speaking={speaking && !disableSpeakingIndicator}
audioMuted={audioMuted}
noVideo={noVideo}
videoMuted={videoMuted}
screenshare={purpose === SDPStreamMetadataPurpose.Screenshare}
name={rawDisplayName}
showName={showName}
ref={tileRef}
mediaRef={mediaRef}
avatar={getAvatar && getAvatar(member, width, height)}
{...rest}
/>
<>
<VideoTile
isLocal={isLocal}
speaking={speaking && !disableSpeakingIndicator}
audioMuted={audioMuted}
noVideo={noVideo}
videoMuted={videoMuted}
screenshare={purpose === SDPStreamMetadataPurpose.Screenshare}
name={rawDisplayName}
showName={showName}
ref={tileRef}
mediaRef={mediaRef}
avatar={getAvatar && getAvatar(member, width, height)}
onOptionsPress={onOptionsPress}
showOptions={!item.callFeed.isLocal()}
{...rest}
/>
{videoTileSettingsModalState.isOpen && (
<VideoTileSettingsModal
{...videoTileSettingsModalProps}
feed={item.callFeed}
/>
)}
</>
);
}
70 changes: 70 additions & 0 deletions src/video-grid/VideoTileSettingsModal.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.content {
margin: 27px 34px;
}

.localVolumePercentage {
width: 3ch;
}

.localVolumeSlider[type="range"] {
-ms-appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;

cursor: pointer;
width: 100%;
}

.localVolumeSlider[type="range"]::-moz-range-track {
-moz-appearance: none;
appearance: none;

height: 4px;
}
.localVolumeSlider[type="range"]::-ms-track {
-ms-appearance: none;
appearance: none;

height: 4px;
}
.localVolumeSlider[type="range"]::-webkit-slider-runnable-track {
-webkit-appearance: none;
appearance: none;

height: 4px;
}

.localVolumeSlider[type="range"]::-moz-range-thumb {
-moz-appearance: none;
appearance: none;

height: 16px;
width: 16px;
margin-top: -6px;

border-radius: 100%;
background: var(--accent);
}
.localVolumeSlider[type="range"]::-ms-thumb {
-ms-appearance: none;
appearance: none;

height: 16px;
width: 16px;
margin-top: -6px;

border-radius: 100%;
background: var(--accent);
}
.localVolumeSlider[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;

height: 16px;
width: 16px;
margin-top: -6px;

border-radius: 100%;
background: var(--accent);
}
74 changes: 74 additions & 0 deletions src/video-grid/VideoTileSettingsModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2022 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React, { ChangeEvent, useState } from "react";
import { CallFeed } from "matrix-js-sdk/src/webrtc/callFeed";

import selectInputStyles from "../input/SelectInput.module.css";
import { FieldRow } from "../input/Input";
import { Modal } from "../Modal";
import styles from "./VideoTileSettingsModal.module.css";

interface LocalVolumeProps {
feed: CallFeed;
}

const LocalVolume: React.FC<LocalVolumeProps> = ({
feed,
}: LocalVolumeProps) => {
const [localVolume, setLocalVolume] = useState<number>(feed.getLocalVolume());

const onLocalVolumeChanged = (event: ChangeEvent<HTMLInputElement>) => {
const value: number = +event.target.value;
setLocalVolume(value);
feed.setLocalVolume(value);
};

return (
<>
<h4 className={selectInputStyles.label}> Local Volume </h4>
<FieldRow>
<span className={styles.localVolumePercentage}>
{`${Math.round(localVolume * 100)}%`}
</span>
<input
className={styles.localVolumeSlider}
type="range"
min="0"
max="1"
step="0.01"
value={localVolume}
onChange={onLocalVolumeChanged}
/>
</FieldRow>
</>
);
};

// TODO: Extend ModalProps
interface Props {
robintown marked this conversation as resolved.
Show resolved Hide resolved
feed: CallFeed;
}

export const VideoTileSettingsModal = ({ feed, ...rest }: Props) => {
return (
<Modal title="Feed settings" isDismissable mobileFullScreen {...rest}>
<div className={styles.content}>
<LocalVolume feed={feed} />
</div>
</Modal>
);
};
10 changes: 10 additions & 0 deletions src/video-grid/useCallFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function getCallFeedState(callFeed) {
: true,
videoMuted: callFeed ? callFeed.isVideoMuted() : true,
audioMuted: callFeed ? callFeed.isAudioMuted() : true,
localVolume: callFeed ? callFeed.getLocalVolume() : 0,
stream: callFeed ? callFeed.stream : undefined,
purpose: callFeed ? callFeed.purpose : undefined,
};
Expand All @@ -44,13 +45,18 @@ export function useCallFeed(callFeed) {
setState((prevState) => ({ ...prevState, audioMuted, videoMuted }));
}

function onLocalVolumeChanged(localVolume) {
setState((prevState) => ({ ...prevState, localVolume }));
}

function onUpdateCallFeed() {
setState(getCallFeedState(callFeed));
}

if (callFeed) {
callFeed.on(CallFeedEvent.Speaking, onSpeaking);
callFeed.on(CallFeedEvent.MuteStateChanged, onMuteStateChanged);
callFeed.on(CallFeedEvent.LocalVolumeChanged, onLocalVolumeChanged);
callFeed.on(CallFeedEvent.NewStream, onUpdateCallFeed);
}

Expand All @@ -63,6 +69,10 @@ export function useCallFeed(callFeed) {
CallFeedEvent.MuteStateChanged,
onMuteStateChanged
);
callFeed.removeListener(
CallFeedEvent.LocalVolumeChanged,
onLocalVolumeChanged
);
callFeed.removeListener(CallFeedEvent.NewStream, onUpdateCallFeed);
}
};
Expand Down
Loading