From ae1939300e3e46c6de0863ac850612fb63e86b88 Mon Sep 17 00:00:00 2001 From: Jan-Ivar Bruaroey Date: Wed, 7 Dec 2016 11:37:28 -0500 Subject: [PATCH] Updated to use navigator.mediaDevices.getUserMedia and srcObject. --- s/webrtc-capturestill/capture.js | 34 ++++++-------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/s/webrtc-capturestill/capture.js b/s/webrtc-capturestill/capture.js index 8dbec08..06e37cb 100644 --- a/s/webrtc-capturestill/capture.js +++ b/s/webrtc-capturestill/capture.js @@ -25,41 +25,19 @@ photo = document.getElementById('photo'); startbutton = document.getElementById('startbutton'); - navigator.getMedia = ( navigator.getUserMedia || - navigator.webkitGetUserMedia || - navigator.mozGetUserMedia || - navigator.msGetUserMedia); - - navigator.getMedia( - { - video: true, - audio: false - }, - function(stream) { - if (navigator.mozGetUserMedia) { - video.mozSrcObject = stream; - } else { - var vendorURL = window.URL || window.webkitURL; - video.src = vendorURL.createObjectURL(stream); - } + navigator.mediaDevices.getUserMedia({ video: true, audio: false }) + .then(function(stream) { + video.srcObject = stream; video.play(); - }, - function(err) { + }) + .catch(function(err) { console.log("An error occured! " + err); - } - ); + }); video.addEventListener('canplay', function(ev){ if (!streaming) { height = video.videoHeight / (video.videoWidth/width); - // Firefox currently has a bug where the height can't be read from - // the video, so we will make assumptions if this happens. - - if (isNaN(height)) { - height = width / (4/3); - } - video.setAttribute('width', width); video.setAttribute('height', height); canvas.setAttribute('width', width);