-
Notifications
You must be signed in to change notification settings - Fork 89
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
Make the volume slider less silly #2681
base: livekit
Are you sure you want to change the base?
Conversation
Previously, dragging it all the way to the left would *not* mute the participant but rather bottom out at 10% volume, and people have found this unintuitive. Let's make it less silly by giving the slider a range of 0% to 100%, and making the mute toggle button have the same effect as dragging the slider to zero. When unmuting, it will reset to the last non-zero "committed" volume, similar to how the volume sliders in desktop environments work.
(state, event) => | ||
event === "toggle mute" | ||
? { ...state, muted: !state.muted } | ||
: event === "commit" | ||
? { ...state, committedVolume: state.volume } | ||
: // Volume adjustment | ||
event === 0 | ||
? // Dragging the slider to zero should have the same effect as | ||
// muting: reset the volume to the committed volume, as if it were | ||
// never dragged | ||
{ ...state, muted: true, volume: state.committedVolume } | ||
: { ...state, muted: false, volume: event }, | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO using a switch
statement reads better:
(state, event) => | |
event === "toggle mute" | |
? { ...state, muted: !state.muted } | |
: event === "commit" | |
? { ...state, committedVolume: state.volume } | |
: // Volume adjustment | |
event === 0 | |
? // Dragging the slider to zero should have the same effect as | |
// muting: reset the volume to the committed volume, as if it were | |
// never dragged | |
{ ...state, muted: true, volume: state.committedVolume } | |
: { ...state, muted: false, volume: event }, | |
), | |
(state, event) => { | |
switch (event) { | |
case "toggle mute": | |
return { ...state, muted: !state.muted }; | |
case "commit": | |
return { ...state, committedVolume: state.volume }; | |
case 0: // Volume adjustment | |
// Dragging the slider to zero should have the same effect as | |
// muting: reset the volume to the committed volume, as if it were | |
// never dragged | |
return { ...state, muted: true, volume: state.committedVolume }; | |
default: | |
return { ...state, muted: false, volume: event }; | |
} | |
}), |
onValueChange: onValueChangeProp, | ||
onValueCommit: onValueCommitProp, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOI where are onValueChangeProp
& onValueCommit
prop defined?
@@ -16,6 +16,7 @@ interface Props { | |||
label: string; | |||
value: number; | |||
onValueChange: (value: number) => void; | |||
onValueCommit?: (value: number) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be optional?
Previously, dragging it all the way to the left would not mute the participant but rather bottom out at 10% volume, and people have found this unintuitive. Let's make it less silly by giving the slider a range of 0% to 100%, and making the mute toggle button have the same effect as dragging the slider to zero. When unmuting, it will reset to the last non-zero "committed" volume, similar to how the volume sliders in desktop environments work.