optimaize focus on player

This commit is contained in:
DmitriyB
2023-02-15 15:58:12 +05:00
parent 0be57b5b88
commit a0291e3a64
2 changed files with 3 additions and 10 deletions
@@ -34,6 +34,7 @@ export const PlayerComponent: React.FC<any> = ({ closeStream }) => {
<> <>
<iframe <iframe
id='player' id='player'
onBlur={(e) => e.target.focus()} /// element loosing focus and keyboard input doesn't work
title="stream" title="stream"
src={url} src={url}
className={"player playerOn"} className={"player playerOn"}
@@ -6,7 +6,6 @@ import fullscreenOff from "../../../images/icons/fullscreenOff.svg";
export const FullscreenButton = ({ }) => { export const FullscreenButton = ({ }) => {
const player = document.getElementById('player') // set focus to element after fullscreen state changed, otherwise keyboard doesn't work in iframe
const [active, setActive] = useState(Boolean(document.fullscreenElement)); const [active, setActive] = useState(Boolean(document.fullscreenElement));
const [button, setButton] = useState({ const [button, setButton] = useState({
icon: fullscreen, icon: fullscreen,
@@ -27,9 +26,6 @@ export const FullscreenButton = ({ }) => {
} }
useEffect(() => { useEffect(() => {
if (player) {
player.focus()
}
setButton({ setButton({
icon: active ? fullscreen : fullscreenOff, icon: active ? fullscreen : fullscreenOff,
inactive: "fullscreen-control-btn", inactive: "fullscreen-control-btn",
@@ -39,21 +35,17 @@ export const FullscreenButton = ({ }) => {
}, [active]) }, [active])
useEffect(() => { useEffect(() => {
function onFullscreenChange() { function onFullscreenChange() {
setActive(Boolean(document.fullscreenElement)); setActive(Boolean(document.fullscreenElement));
} }
document.addEventListener('fullscreenchange', onFullscreenChange); document.addEventListener('fullscreenchange', onFullscreenChange);
return () => document.removeEventListener('fullscreenchange', onFullscreenChange); return () => document.removeEventListener('fullscreenchange', onFullscreenChange);
}, []); }, []);
return ( return (
<div className="toolbar-button-area"> <div className="toolbar-button-area">
<Button button={button} active={active} onClick={handleClick}></Button> <Button button={button} active={active} onClick={handleClick}></Button>