Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main.js initAudio() function fix with promise (new standard not deprecated) #22

Open
axew3 opened this issue Dec 29, 2017 · 0 comments
Open

Comments

@axew3
Copy link

axew3 commented Dec 29, 2017

`function initAudio() {
// 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
var 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) {
return Promise.reject(new Error('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);
});
}
}

navigator.mediaDevices.getUserMedia({ audio: true, video: false })
.then(gotStream)
.catch(function(err) {
console.log(err.name + ": " + err.message);
});
}`

The initAudio() function on file main.js, should be changed with the above.
See this at:
https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia

@axew3 axew3 closed this as completed Dec 31, 2017
@axew3 axew3 reopened this Dec 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant