Create-react-app: CRA WebServer isn't rendering getUserMedia API for iOS Safari properly.

Created on 24 Dec 2019  路  3Comments  路  Source: facebook/create-react-app

Describe the bug

I'm trying to access the camera on iOS through implementing the getUserMedia API in my React App. My code works fine when I navigate run it in StackBlitz on iOS Safari. However when I navigate to mylocalIP:3000 on iOS Safari, the component doesn't prompt for access to the webcam. See my component here or below:

const Video: React.FC = () => {
    useEffect(() => {
        start()
    })

    const constraints = {
        audio: false,
        video: true
    };

    async function start() {
        const stream = await navigator.mediaDevices.getUserMedia(constraints)
        const video = document.getElementById('video') as HTMLVideoElement;
        video.setAttribute("playsinline", "true");
        video.setAttribute("controls", "true");
        video.srcObject = stream;
    }

    return (
        <video id='video' autoPlay playsInline></video>
    )
}

export default Video

Did you try recovering your dependencies?

Yes, followed all steps.

Which terms did you search for in User Guide?

Nothing relevant in the User Guide

Environment

Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Binaries:
Node: 10.14.1 - ~/.nvm/versions/node/v10.14.1/bin/node
Yarn: Not Found
npm: 6.10.3 - ~/.nvm/versions/node/v10.14.1/bin/npm
Browsers:
Chrome: 79.0.3945.88
Firefox: Not Found
Safari: 13.0.4
npmPackages:
react: ^16.10.2 => 16.10.2
react-dom: ^16.10.2 => 16.10.2
react-scripts: 3.2.0 => 3.2.0
npmGlobalPackages:
create-react-app: 3.3.0

Steps to reproduce

(Write your steps here:)

  1. Copy and paste the component from StackBlitz or this issue
  2. npm start
  3. Navigate to your your-ip:3000 on iOS Safari

Expected behavior

The phone will prompt to share the webcam with the site.

Actual behavior

Screen displays an empty video icon.

Reproducible demo

StackBlitz Demo
Copy that code into CRA and navigate to the hosted site.

bug report needs triage

All 3 comments

Duplicate of #8234?

@heyimalex #8234 is clearly a duplicate of this one, not the other way round....

Sorry! I just saw the other one first, figured you were co-workers that just miscommunicated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dualcnhq picture dualcnhq  路  3Comments

onelson picture onelson  路  3Comments

Aranir picture Aranir  路  3Comments

DaveLindberg picture DaveLindberg  路  3Comments

oltsa picture oltsa  路  3Comments