Skip to content

Commit 7b57fc2

Browse files
Half-Shotrobintown
authored andcommitted
Add ability to adjust sound effect volume.
1 parent 1df2e0c commit 7b57fc2

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

public/locales/en-GB/app.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@
144144
"room_auth_view_eula_caption": "By clicking \"Continue\", you agree to our <2>End User Licensing Agreement (EULA)</2>",
145145
"screenshare_button_label": "Share screen",
146146
"settings": {
147+
"audio_tab": {
148+
"effect_volume_label": "Sound effect volume",
149+
"effect_volume_description": "Adjust the volume at which reactions and hand raised effects play"
150+
},
147151
"developer_settings_label": "Developer Settings",
148152
"developer_settings_label_description": "Expose developer settings in the settings window.",
149153
"developer_tab_title": "Developer",

src/room/ReactionAudioRenderer.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ Please see LICENSE in the repository root for full details.
88
import { ReactNode, useEffect, useRef } from "react";
99

1010
import { useReactions } from "../useReactions";
11-
import { playReactionsSound, useSetting } from "../settings/settings";
11+
import {
12+
playReactionsSound,
13+
effectSoundVolume as effectSoundVolumeSetting,
14+
useSetting,
15+
} from "../settings/settings";
1216
import { GenericReaction, ReactionSet } from "../reactions";
1317

1418
export function ReactionsAudioRenderer(): ReactNode {
1519
const { reactions } = useReactions();
1620
const [shouldPlay] = useSetting(playReactionsSound);
21+
const [effectSoundVolume] = useSetting(effectSoundVolumeSetting);
1722
const audioElements = useRef<Record<string, HTMLAudioElement | null>>({});
1823

1924
useEffect(() => {
@@ -30,6 +35,7 @@ export function ReactionsAudioRenderer(): ReactNode {
3035
const audioElement =
3136
audioElements.current[reactionName] ?? audioElements.current.generic;
3237
if (audioElement?.paused) {
38+
audioElement.volume = effectSoundVolume;
3339
void audioElement.play();
3440
}
3541
}

src/settings/SettingsModal.module.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,20 @@ Please see LICENSE in the repository root for full details.
1616
.fieldRowText {
1717
margin-bottom: 0;
1818
}
19+
20+
.volumeSlider {
21+
margin-top: var(--cpd-space-2x);
22+
}
23+
24+
.volumeSlider > label {
25+
margin-bottom: var(--cpd-space-1x);
26+
display: block;
27+
}
28+
29+
.volumeSlider > span {
30+
max-width: 20em;
31+
}
32+
33+
.volumeSlider > p {
34+
color: var(--cpd-color-text-secondary);
35+
}

src/settings/SettingsModal.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Please see LICENSE in the repository root for full details.
88
import { ChangeEvent, FC, ReactNode, useCallback } from "react";
99
import { Trans, useTranslation } from "react-i18next";
1010
import { MatrixClient } from "matrix-js-sdk/src/matrix";
11-
import { Dropdown, Text } from "@vector-im/compound-web";
11+
import { Dropdown, Separator, Text } from "@vector-im/compound-web";
1212

1313
import { Modal } from "../Modal";
1414
import styles from "./SettingsModal.module.css";
@@ -28,9 +28,11 @@ import {
2828
developerSettingsTab as developerSettingsTabSetting,
2929
duplicateTiles as duplicateTilesSetting,
3030
useOptInAnalytics,
31+
effectSoundVolume,
3132
} from "./settings";
3233
import { isFirefox } from "../Platform";
3334
import { PreferencesSettingsTab } from "./PreferencesSettingsTab";
35+
import { Slider } from "../Slider";
3436

3537
type SettingsTab =
3638
| "audio"
@@ -116,6 +118,8 @@ export const SettingsModal: FC<Props> = ({
116118
const devices = useMediaDevices();
117119
useMediaDeviceNames(devices, open);
118120

121+
const [soundVolume, setSoundVolume] = useSetting(effectSoundVolume);
122+
119123
const audioTab: Tab<SettingsTab> = {
120124
key: "audio",
121125
name: t("common.audio"),
@@ -127,6 +131,19 @@ export const SettingsModal: FC<Props> = ({
127131
devices.audioOutput,
128132
t("settings.speaker_device_selection_label"),
129133
)}
134+
<Separator />
135+
<div className={styles.volumeSlider}>
136+
<label>{t("settings.audio_tab.effect_volume_label")}</label>
137+
<p>{t("settings.audio_tab.effect_volume_description")}</p>
138+
<Slider
139+
label={t("video_tile.volume")}
140+
value={soundVolume}
141+
onValueChange={setSoundVolume}
142+
min={0}
143+
max={1}
144+
step={0.01}
145+
/>
146+
</div>
130147
</>
131148
),
132149
};

src/settings/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,6 @@ export const playReactionsSound = new Setting<boolean>(
100100
true,
101101
);
102102

103+
export const effectSoundVolume = new Setting<number>("effects-sound-volume", 1);
104+
103105
export const alwaysShowSelf = new Setting<boolean>("always-show-self", true);

0 commit comments

Comments
 (0)