UNPKG

chromatone-theory

Version:

Music theory needed to create chromatone empowered apps

34 lines (29 loc) 1.33 kB
export function initGetUserMedia() { window.AudioContext = window.AudioContext || window.webkitAudioContext if (!window.AudioContext) { return alert('AudioContext not supported') } // Older browsers might not implement mediaDevices at all, so we set an empty object first if (navigator.mediaDevices === undefined) { navigator.mediaDevices = {} } // Some browsers partially implement mediaDevices. We can't just assign an object // with getUserMedia as it would overwrite existing properties. // Here, we will just add the getUserMedia property if it's missing. if (navigator.mediaDevices.getUserMedia === undefined) { navigator.mediaDevices.getUserMedia = function (constraints) { // First get ahold of the legacy getUserMedia, if present const getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia // Some browsers just don't implement it - return a rejected promise with an error // to keep a consistent interface if (!getUserMedia) { alert('getUserMedia is not implemented in this browser') } // Otherwise, wrap the call to the old navigator.getUserMedia with a Promise return new Promise(function (resolve, reject) { getUserMedia.call(navigator, constraints, resolve, reject) }) } } }