GitHub

Source

useMediaDeviceSelect

The useMediaDeviceSelect hook is used to implement the MediaDeviceSelect component and returns o.a. the list of devices of a given kind (audioinput or videoinput), the currently active device and a function to set the the active device.

Import

import { useMediaDeviceSelect } from "@livekit/components-react";

Usage

const { devices, activeDeviceId, setActiveMediaDevice } = useMediaDeviceSelect({
kind: "audioinput"
});

Properties

kindMediaDeviceKind
onError?(e: Error) => void

this callback gets called if an error is thrown when failing to select a device and also if a user denied permissions, eventhough the requestPermissions option is set to true. Most commonly this will emit a MediaDeviceError

requestPermissions?boolean

this will call getUserMedia if the permissions are not yet given to enumerate the devices with device labels. in some browsers multiple calls to getUserMedia result in multiple permission prompts. It's generally advised only flip this to true, once a (preview) track has been acquired successfully with the appropriate permissions.

room?Room
track?LocalAudioTrack | LocalVideoTrack

Returns

{
devices: MediaDeviceInfo[];
className: string;
activeDeviceId: string;
setActiveMediaDevice: (id: string, options?: import("@livekit/components-core").SetMediaDeviceOptions | undefined) => Promise<void>;
}