Hoshani
Hoshani

Reputation: 846

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

Upvotes: 0

Views: 372

Answers (2)

Philipp Hancke
Philipp Hancke

Reputation: 17350

navigator.getUserMedia is the legacy variant of getUserMedia It uses callbacks and does not return a promise.

You're mixing styles, either use callbacks or navigator.mediaDevices.getUserMedia without callbacks.

Upvotes: 0

Sumit Vekariya
Sumit Vekariya

Reputation: 488

navigator.getUserMedia is deprecated.

Try this instead navigator.mediaDevices.getUserMedia()

Upvotes: 2

Related Questions