Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow getCameraDevice to return undefined when no Devices are available (e.g. iOS Simulator) #1848

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

mrousavy
Copy link
Owner

What

On an iOS simulator, getAvailableCameraDevices() returns [] (there are no cameras unfortunately).

This PR returns undefined instead of throwing an error if no device can be found.

Changes

Tested on

Related issues

cc @hamdij0maa

@vercel
Copy link

vercel bot commented Sep 25, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
react-native-vision-camera ✅ Ready (Inspect) Visit Preview Sep 25, 2023 0:11am

@hamdij0maa
Copy link

<3 🚀

@hirbod
Copy link
Contributor

hirbod commented Sep 25, 2023

@mrousavy just an idea: could it be possible to have a look how Tesla Motors achieves fake camera previews inside the simulator with their RN module? Maybe it could be copied

https://github.com/teslamotors/react-native-camera-kit/blob/master/ios/ReactNativeCameraKit/SimulatorCamera.swift
https://github.com/teslamotors/react-native-camera-kit/blob/master/ios/ReactNativeCameraKit/SimulatorPreviewView.swift

@mrousavy
Copy link
Owner Author

@hirbod unfortunately not, no. Also that lib was written by Wix and just got moved to Tesla.

The reason why this will not work is because VisionCamera builds upon Camera Devices, allowing the user to select any given camera device. I cannot simulate a fake device, as that would mean I have to:

  1. Create a dummy CameraDevice specifically for iOS simulators
  2. Add dummy implementation for every single Camera Device specific function (start session, enable flash, etc) because those depend on the low-level hardware device type
  3. Resolve takePhoto and recordVideo with dummy files
  4. Simulate a fake preview using Metal (that's surprisingly the easy part)

Which is a shit ton of extra code. Like really, a shit ton.

The real solution would be to add support to Cameras on iOS simulators (e.g the macbooks camera, I am surprised this still doesn't work.)

@mrousavy mrousavy merged commit f7428f2 into main Sep 26, 2023
@mrousavy mrousavy deleted the fix/allow-undefined-device branch September 26, 2023 09:24
@hirbod
Copy link
Contributor

hirbod commented Sep 26, 2023

Yeah, makes sense. That extra work is indeed too much.

@xts-bit
Copy link

xts-bit commented Sep 29, 2023

@hirbod @mrousavy Like Will it support FaceTime support on Macs?

eidan66 added a commit to eidan66/react-native-vision-camera that referenced this pull request Nov 9, 2023
According to this change: mrousavy#1848

We maybe should let devices be undefined.
isaaccolson pushed a commit to isaaccolson/deliveries-mobile that referenced this pull request Oct 30, 2024
…e available (e.g. iOS Simulator) (mrousavy#1848)

fix: Allow `getCameraDevice` to return `undefined` when no Devices are available
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 No camera device found in IOS simulator
4 participants