Search code examples
webrtcsimplewebrtc

stream is undefined when using navigator.getUserMedia


I am using webrtc and trying to show the video after obtaining permission of getUserMedia()

here is what I am trying to do

var mediaConstraints = { audio: true, video: true };

const stream = await navigator.getUserMedia
        (mediaConstraints, function() {
            console.log("obtained successfully");

    }, function() {
        console.error("access was denied OR hardware issue");
        });

however stream is undefied, it should have a value of any kind


Solution

  • navigator.getUserMedia is deprecated.

    Try this instead navigator.mediaDevices.getUserMedia()