Merge pull request #1015 from robintown/shortcut-focus
Make keyboard shortcuts accessible by default
This commit is contained in:
commit
4719a92ffc
5 changed files with 30 additions and 48 deletions
|
@ -106,7 +106,6 @@
|
||||||
"Show call inspector": "Show call inspector",
|
"Show call inspector": "Show call inspector",
|
||||||
"Sign in": "Sign in",
|
"Sign in": "Sign in",
|
||||||
"Sign out": "Sign out",
|
"Sign out": "Sign out",
|
||||||
"Single-key keyboard shortcuts": "Single-key keyboard shortcuts",
|
|
||||||
"Spatial audio": "Spatial audio",
|
"Spatial audio": "Spatial audio",
|
||||||
"Speaker": "Speaker",
|
"Speaker": "Speaker",
|
||||||
"Speaker {{n}}": "Speaker {{n}}",
|
"Speaker {{n}}": "Speaker {{n}}",
|
||||||
|
@ -138,7 +137,6 @@
|
||||||
"Walkie-talkie call": "Walkie-talkie call",
|
"Walkie-talkie call": "Walkie-talkie call",
|
||||||
"Walkie-talkie call name": "Walkie-talkie call name",
|
"Walkie-talkie call name": "Walkie-talkie call name",
|
||||||
"WebRTC is not supported or is being blocked in this browser.": "WebRTC is not supported or is being blocked in this browser.",
|
"WebRTC is not supported or is being blocked in this browser.": "WebRTC is not supported or is being blocked in this browser.",
|
||||||
"Whether to enable single-key keyboard shortcuts, e.g. 'm' to mute/unmute the mic.": "Whether to enable single-key keyboard shortcuts, e.g. 'm' to mute/unmute the mic.",
|
|
||||||
"Yes, join call": "Yes, join call",
|
"Yes, join call": "Yes, join call",
|
||||||
"You can't talk at the same time": "You can't talk at the same time",
|
"You can't talk at the same time": "You can't talk at the same time",
|
||||||
"Your recent calls": "Your recent calls"
|
"Your recent calls": "Your recent calls"
|
||||||
|
|
|
@ -157,7 +157,7 @@ export function InCallView({
|
||||||
const { hideScreensharing } = useUrlParams();
|
const { hideScreensharing } = useUrlParams();
|
||||||
|
|
||||||
useCallViewKeyboardShortcuts(
|
useCallViewKeyboardShortcuts(
|
||||||
!feedbackModalState.isOpen,
|
containerRef1,
|
||||||
toggleMicrophoneMuted,
|
toggleMicrophoneMuted,
|
||||||
toggleLocalVideoMuted,
|
toggleLocalVideoMuted,
|
||||||
setMicrophoneMuted
|
setMicrophoneMuted
|
||||||
|
|
|
@ -28,7 +28,6 @@ import { ReactComponent as OverflowIcon } from "../icons/Overflow.svg";
|
||||||
import { SelectInput } from "../input/SelectInput";
|
import { SelectInput } from "../input/SelectInput";
|
||||||
import { useMediaHandler } from "./useMediaHandler";
|
import { useMediaHandler } from "./useMediaHandler";
|
||||||
import {
|
import {
|
||||||
useKeyboardShortcuts,
|
|
||||||
useSpatialAudio,
|
useSpatialAudio,
|
||||||
useShowInspector,
|
useShowInspector,
|
||||||
useOptInAnalytics,
|
useOptInAnalytics,
|
||||||
|
@ -65,7 +64,6 @@ export const SettingsModal = (props: Props) => {
|
||||||
const [optInAnalytics, setOptInAnalytics] = useOptInAnalytics();
|
const [optInAnalytics, setOptInAnalytics] = useOptInAnalytics();
|
||||||
const [developerSettingsTab, setDeveloperSettingsTab] =
|
const [developerSettingsTab, setDeveloperSettingsTab] =
|
||||||
useDeveloperSettingsTab();
|
useDeveloperSettingsTab();
|
||||||
const [keyboardShortcuts, setKeyboardShortcuts] = useKeyboardShortcuts();
|
|
||||||
const [newGrid, setNewGrid] = useNewGrid();
|
const [newGrid, setNewGrid] = useNewGrid();
|
||||||
|
|
||||||
const downloadDebugLog = useDownloadDebugLog();
|
const downloadDebugLog = useDownloadDebugLog();
|
||||||
|
@ -176,21 +174,6 @@ export const SettingsModal = (props: Props) => {
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<h4>Keyboard</h4>
|
|
||||||
<FieldRow>
|
|
||||||
<InputField
|
|
||||||
id="keyboardShortcuts"
|
|
||||||
label={t("Single-key keyboard shortcuts")}
|
|
||||||
type="checkbox"
|
|
||||||
checked={keyboardShortcuts}
|
|
||||||
description={t(
|
|
||||||
"Whether to enable single-key keyboard shortcuts, e.g. 'm' to mute/unmute the mic."
|
|
||||||
)}
|
|
||||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
||||||
setKeyboardShortcuts(event.target.checked)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</FieldRow>
|
|
||||||
<h4>Analytics</h4>
|
<h4>Analytics</h4>
|
||||||
<FieldRow>
|
<FieldRow>
|
||||||
<InputField
|
<InputField
|
||||||
|
|
|
@ -98,9 +98,6 @@ export const useOptInAnalytics = (): DisableableSetting<boolean | null> => {
|
||||||
return [false, null];
|
return [false, null];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useKeyboardShortcuts = () =>
|
|
||||||
useSetting("keyboard-shortcuts", true);
|
|
||||||
|
|
||||||
export const useNewGrid = () => useSetting("new-grid", false);
|
export const useNewGrid = () => useSetting("new-grid", false);
|
||||||
|
|
||||||
export const useDeveloperSettingsTab = () =>
|
export const useDeveloperSettingsTab = () =>
|
||||||
|
|
|
@ -14,47 +14,55 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useCallback, useState } from "react";
|
import { RefObject, useCallback, useRef } from "react";
|
||||||
|
|
||||||
import { getSetting } from "./settings/useSetting";
|
|
||||||
import { useEventTarget } from "./useEvents";
|
import { useEventTarget } from "./useEvents";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether focus is in the same part of the tree as the given
|
||||||
|
* element (specifically, if an ancestor or descendant of it is focused).
|
||||||
|
*/
|
||||||
|
const mayReceiveKeyEvents = (e: HTMLElement): boolean => {
|
||||||
|
const focusedElement = document.activeElement;
|
||||||
|
return (
|
||||||
|
focusedElement !== null &&
|
||||||
|
(focusedElement.contains(e) || e.contains(focusedElement))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export function useCallViewKeyboardShortcuts(
|
export function useCallViewKeyboardShortcuts(
|
||||||
enabled: boolean,
|
focusElement: RefObject<HTMLElement | null>,
|
||||||
toggleMicrophoneMuted: () => void,
|
toggleMicrophoneMuted: () => void,
|
||||||
toggleLocalVideoMuted: () => void,
|
toggleLocalVideoMuted: () => void,
|
||||||
setMicrophoneMuted: (muted: boolean) => void
|
setMicrophoneMuted: (muted: boolean) => void
|
||||||
) {
|
) {
|
||||||
const [spacebarHeld, setSpacebarHeld] = useState(false);
|
const spacebarHeld = useRef(false);
|
||||||
|
|
||||||
|
// These event handlers are set on the window because we want users to be able
|
||||||
|
// to trigger them without going to the trouble of focusing something
|
||||||
|
|
||||||
useEventTarget(
|
useEventTarget(
|
||||||
window,
|
window,
|
||||||
"keydown",
|
"keydown",
|
||||||
useCallback(
|
useCallback(
|
||||||
(event: KeyboardEvent) => {
|
(event: KeyboardEvent) => {
|
||||||
if (!enabled) return;
|
if (focusElement.current === null) return;
|
||||||
// Check if keyboard shortcuts are enabled
|
if (!mayReceiveKeyEvents(focusElement.current)) return;
|
||||||
const keyboardShortcuts = getSetting("keyboard-shortcuts", true);
|
|
||||||
if (!keyboardShortcuts) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === "m") {
|
if (event.key === "m") {
|
||||||
toggleMicrophoneMuted();
|
toggleMicrophoneMuted();
|
||||||
} else if (event.key == "v") {
|
} else if (event.key == "v") {
|
||||||
toggleLocalVideoMuted();
|
toggleLocalVideoMuted();
|
||||||
} else if (event.key === " " && !spacebarHeld) {
|
} else if (event.key === " " && !spacebarHeld.current) {
|
||||||
setSpacebarHeld(true);
|
spacebarHeld.current = true;
|
||||||
setMicrophoneMuted(false);
|
setMicrophoneMuted(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
enabled,
|
focusElement,
|
||||||
spacebarHeld,
|
|
||||||
toggleLocalVideoMuted,
|
toggleLocalVideoMuted,
|
||||||
toggleMicrophoneMuted,
|
toggleMicrophoneMuted,
|
||||||
setMicrophoneMuted,
|
setMicrophoneMuted,
|
||||||
setSpacebarHeld,
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -64,19 +72,15 @@ export function useCallViewKeyboardShortcuts(
|
||||||
"keyup",
|
"keyup",
|
||||||
useCallback(
|
useCallback(
|
||||||
(event: KeyboardEvent) => {
|
(event: KeyboardEvent) => {
|
||||||
if (!enabled) return;
|
if (focusElement.current === null) return;
|
||||||
// Check if keyboard shortcuts are enabled
|
if (!mayReceiveKeyEvents(focusElement.current)) return;
|
||||||
const keyboardShortcuts = getSetting("keyboard-shortcuts", true);
|
|
||||||
if (!keyboardShortcuts) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === " ") {
|
if (event.key === " ") {
|
||||||
setSpacebarHeld(false);
|
spacebarHeld.current = false;
|
||||||
setMicrophoneMuted(true);
|
setMicrophoneMuted(true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[enabled, setMicrophoneMuted, setSpacebarHeld]
|
[focusElement, setMicrophoneMuted]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -85,9 +89,9 @@ export function useCallViewKeyboardShortcuts(
|
||||||
"blur",
|
"blur",
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
if (spacebarHeld) {
|
if (spacebarHeld) {
|
||||||
setSpacebarHeld(false);
|
spacebarHeld.current = false;
|
||||||
setMicrophoneMuted(true);
|
setMicrophoneMuted(true);
|
||||||
}
|
}
|
||||||
}, [setMicrophoneMuted, setSpacebarHeld, spacebarHeld])
|
}, [setMicrophoneMuted, spacebarHeld])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue