toggle only (#426)

This commit is contained in:
lukasIO 2025-05-21 17:18:03 +02:00 committed by GitHub
parent 2143d36dec
commit cdbf5b1f87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,34 +2,30 @@
import React from 'react';
import { Track } from 'livekit-client';
import { useLocalParticipant, useTrackToggle } from '@livekit/components-react';
import { useTrackToggle } from '@livekit/components-react';
export function KeyboardShortcuts() {
const _ = useLocalParticipant();
const { toggle: toggleMic, enabled: micEnabled } = useTrackToggle({ source: Track.Source.Microphone });
const { toggle: toggleCamera, enabled: cameraEnabled } = useTrackToggle({ source: Track.Source.Camera });
const { toggle: toggleMic } = useTrackToggle({ source: Track.Source.Microphone });
const { toggle: toggleCamera } = useTrackToggle({ source: Track.Source.Camera });
React.useEffect(() => {
function handleShortcut(event: KeyboardEvent) {
// Toggle microphone: Cmd/Ctrl-Shift-A
if (toggleMic && event.key === 'A' && (event.ctrlKey || event.metaKey)) {
event.preventDefault();
toggleMic(!micEnabled, true);
toggleMic();
}
// Toggle camera: Cmd/Ctrl-Shift-V
if (event.key === 'V' && (event.ctrlKey || event.metaKey)) {
event.preventDefault();
toggleCamera(!cameraEnabled, true);
toggleCamera();
}
}
window.addEventListener('keydown', handleShortcut);
return () => window.removeEventListener('keydown', handleShortcut);
}, [
toggleMic, micEnabled,
toggleCamera, cameraEnabled,
]);
}, [toggleMic, toggleCamera]);
return null;
}