function getMediaDevices () {
  if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
    return navigator.mediaDevices
  }

  const getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia
  if (!getUserMedia) {
    return null
  }

  return {
    getUserMedia (opts) {
      return new Promise((resolve, reject) => {
        getUserMedia.call(navigator, opts, resolve, reject)
      })
    }
  }
}
function getMediaDevices () {
  if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
    return navigator.mediaDevices
  }

  const getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia
  if (!getUserMedia) {
    return null
  }

  return {
    getUserMedia (opts) {
      return new Promise((resolve, reject) => {
        getUserMedia.call(navigator, opts, resolve, reject)
      })
    }
  }
}
function getMediaDevices ( ) { if ( navigator . mediaDevices && navigator . mediaDevices . getUserMedia ) { return navigator . mediaDevices } const getUserMedia = navigator . mozGetUserMedia || navigator . webkitGetUserMedia if ( ! getUserMedia ) { return null } return { getUserMedia ( opts ) { return new Promise ( ( resolve , reject ) => { getUserMedia . call ( navigator , opts , resolve , reject ) } ) } } }
Setup getUserMedia, with polyfill for older browsers Adapted from: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
Setup getUserMedia with polyfill for older browsers Adapted from : https : // developer . mozilla . org / en - US / docs / Web / API / MediaDevices / getUserMedia
getMediaDevices - returns a Promise