Skip to content

Commit

Permalink
Redo request device permissions when opening menu (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO authored Apr 3, 2024
1 parent 98ac0ca commit f9b3d53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-guests-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/components-react": patch
---

Request device permissions when opening media device menu
13 changes: 10 additions & 3 deletions packages/react/src/prefabs/MediaDeviceMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function MediaDeviceMenu({
const [isOpen, setIsOpen] = React.useState(false);
const [devices, setDevices] = React.useState<MediaDeviceInfo[]>([]);
const [updateRequired, setUpdateRequired] = React.useState<boolean>(true);
const [needPermissions, setNeedPermissions] = React.useState(requestPermissions);

const handleActiveDeviceChange = (kind: MediaDeviceKind, deviceId: string) => {
log.debug('handle device change');
Expand All @@ -58,6 +59,12 @@ export function MediaDeviceMenu({
const button = React.useRef<HTMLButtonElement>(null);
const tooltip = React.useRef<HTMLDivElement>(null);

React.useLayoutEffect(() => {
if (isOpen) {
setNeedPermissions(true);
}
}, [isOpen]);

React.useLayoutEffect(() => {
if (button.current && tooltip.current && (devices || updateRequired)) {
computeMenuPosition(button.current, tooltip.current).then(({ x, y }) => {
Expand Down Expand Up @@ -118,7 +125,7 @@ export function MediaDeviceMenu({
onDeviceListChange={setDevices}
kind={kind}
track={tracks?.[kind]}
requestPermissions={requestPermissions}
requestPermissions={needPermissions}
/>
) : (
<>
Expand All @@ -130,7 +137,7 @@ export function MediaDeviceMenu({
}
onDeviceListChange={setDevices}
track={tracks?.audioinput}
requestPermissions={requestPermissions}
requestPermissions={needPermissions}
/>
<div className="lk-device-menu-heading">Video inputs</div>
<MediaDeviceSelect
Expand All @@ -140,7 +147,7 @@ export function MediaDeviceMenu({
}
onDeviceListChange={setDevices}
track={tracks?.videoinput}
requestPermissions={requestPermissions}
requestPermissions={needPermissions}
/>
</>
)}
Expand Down

0 comments on commit f9b3d53

Please sign in to comment.