import { useMemo } from "react"; import { useHidStore, useMouseStore, useRTCStore, useSettingsStore, useVideoStore, VideoState } from "@hooks/stores"; import { useHidRpc } from "@hooks/useHidRpc"; import { keys, modifiers } from "@/keyboardMappings"; import { cx } from "@/cva.config"; import { m } from "@localizations/messages.js"; export default function InfoBar() { const { keysDownState } = useHidStore(); const { mouseX, mouseY, mouseMove } = useMouseStore(); const { rpcHidStatus } = useHidRpc(); const videoClientSize = useVideoStore( (state: VideoState) => `${Math.round(state.clientWidth)}x${Math.round(state.clientHeight)}`, ); const videoSize = useVideoStore( (state: VideoState) => `${Math.round(state.width)}x${Math.round(state.height)}`, ); const { debugMode, mouseMode, showPressedKeys } = useSettingsStore(); const { isPasteInProgress } = useHidStore(); const { keyboardLedState, usbState } = useHidStore(); const { isTurnServerInUse } = useRTCStore(); const { hdmiState } = useVideoStore(); const displayKeys = useMemo(() => { if (!showPressedKeys) return ""; const activeModifierMask = keysDownState.modifier || 0; const keysDown = keysDownState.keys || []; const modifierNames = Object.entries(modifiers) .filter(([_, mask]) => (activeModifierMask & mask) !== 0) .map(([name]) => name); const keyNames = Object.entries(keys) .filter(([_, value]) => keysDown.includes(value)) .map(([name]) => name); return [...modifierNames, ...keyNames].join(", "); }, [keysDownState, showPressedKeys]); return (
{debugMode ? (
{m.info_resolution()}{" "} {videoSize}
) : null} {debugMode ? (
{m.info_video_size()} {videoClientSize}
) : null} {(debugMode && mouseMode == "absolute") ? (
{m.info_pointer()} {mouseX},{mouseY}
) : null} {(debugMode && mouseMode == "relative") ? (
{m.info_last_move()} {mouseMove ? `${mouseMove.x},${mouseMove.y} ${mouseMove.buttons ? `(${mouseMove.buttons})` : ""}` : "N/A"}
) : null} {debugMode && (
{m.info_usb_state()} {usbState}
)} {debugMode && (
{m.info_hdmi_state()} {hdmiState}
)} {debugMode && (
{m.info_hidrpc_state()} {rpcHidStatus}
)} {isPasteInProgress && (
{m.info_paste_mode()} {m.info_paste_enabled()}
)} {showPressedKeys && (
{m.info_keys()}

{displayKeys}

)}
{isTurnServerInUse && (
{m.info_relayed_by_cloudflare()}
)}
{m.info_caps_lock()}
{m.info_num_lock()}
{m.info_scroll_lock()}
{keyboardLedState.compose ? (
{m.info_compose()}
) : null} {keyboardLedState.kana ? (
{m.info_kana()}
) : null} {keyboardLedState.shift ? (
{m.info_shift()}
) : null}
); }