diff --git a/src/livekit/MediaDevicesContext.tsx b/src/livekit/MediaDevicesContext.tsx index df5b3fd98..db995ff0d 100644 --- a/src/livekit/MediaDevicesContext.tsx +++ b/src/livekit/MediaDevicesContext.tsx @@ -26,6 +26,7 @@ import { } from "react"; import { createMediaDeviceObserver } from "@livekit/components-core"; import { Observable } from "rxjs"; +import { logger } from "matrix-js-sdk/src/logger"; import { isFirefox, @@ -82,21 +83,31 @@ function useMediaDevice( // Tragically, the only way to get device names out of LiveKit is to specify a // kind, which then results in multiple permissions requests. const deviceObserver = useMemo( - () => createMediaDeviceObserver(kind, requestPermissions), + () => + createMediaDeviceObserver( + kind, + () => { + logger.error("Error creating MediaDeviceObserver"); + }, + requestPermissions, + ), [kind, requestPermissions], ); const available = useObservableState(deviceObserver, []); const [selectedId, select] = useState(fallbackDevice); return useMemo(() => { - const devId = available.some((d) => d.deviceId === selectedId) - ? selectedId - : available.some((d) => d.deviceId === fallbackDevice) - ? fallbackDevice - : available.at(0)?.deviceId; + let devId; + if (available) { + devId = available.some((d) => d.deviceId === selectedId) + ? selectedId + : available.some((d) => d.deviceId === fallbackDevice) + ? fallbackDevice + : available.at(0)?.deviceId; + } return { - available, + available: available ?? [], selectedId: alwaysDefault ? undefined : devId, select, }; diff --git a/yarn.lock b/yarn.lock index 7c10e688a..671bb829d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1989,10 +1989,10 @@ resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.4.0.tgz#08d6c5e20cf7e4cc02fd181c4b0c225cd31dbb60" integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA== -"@livekit/components-core@0.8.0": - version "0.8.0" - resolved "https://registry.yarnpkg.com/@livekit/components-core/-/components-core-0.8.0.tgz#6c20fff1459624e78fe72abd4a46151e31d5e3d8" - integrity sha512-nfJO5BBKR1hvkImsErxl7EwSJMXcZ0xSpHT42sevUeL5VKVYUj5YJFuhOs/xUMx06kBSDNMGHNsjRvbYgLFv0w== +"@livekit/components-core@0.8.1": + version "0.8.1" + resolved "https://registry.yarnpkg.com/@livekit/components-core/-/components-core-0.8.1.tgz#40efb867c9fc5c9c3ee37055fb307a3ed41b24ed" + integrity sha512-0pe+xRIuDObJNGv9Khn+RxHVGL2bit45ORLu+u3UoiAEt1V+pR2XldN6lW6pChuEBY1KLUuuS3h1EbcxrIkYOw== dependencies: "@floating-ui/dom" "^1.1.0" email-regex "^5.0.0" @@ -2000,11 +2000,11 @@ rxjs "^7.8.0" "@livekit/components-react@^1.1.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@livekit/components-react/-/components-react-1.4.0.tgz#c57621e3a27f3a758aafb7a66abe7b5f22a94e7f" - integrity sha512-hcJWM/E9rqa1KH76nLVlbL6twM5W/xUwobSOGwklCxih4D575qd9XWB3hlOHqHL0h1FIvzuhOJgyJ8NXoRpucA== + version "1.4.1" + resolved "https://registry.yarnpkg.com/@livekit/components-react/-/components-react-1.4.1.tgz#c17e2ad4162d492ebdb5827a9f9b71d908b61322" + integrity sha512-k8zJhr9JfYqClhR6mifpH0z7pO1imKu3/ytjG2P6L1GM4SYT3GGOJV3TPwrNn35glHY2TveHvHjWLh7JHiNF3w== dependencies: - "@livekit/components-core" "0.8.0" + "@livekit/components-core" "0.8.1" "@react-hook/latest" "^1.0.3" clsx "^2.0.0" usehooks-ts "^2.9.1"