Work with getUserMedia across browsers

The web has seen a great technology added to it which provides access to the user's microphone and webcam. The specification for these tools keeps changing, most notably some of the more modern ones deliver access to getUserMedia through javascript Promises so I've tried to build a simple function which unifies the different browsers so that they behave the same.

function requestUserMedia (constraints)

    if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia)
        return navigator.mediaDevices.getUserMedia(constraints);

    return new Promise(function (resolve, reject) {

        var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
        if (getUserMedia)
  , constraints, resolve, reject);
        else {
            var err = new Error("Browser doesn't support getUserMedia.");



requestUserMedia({ audio: true })
    .then(function (stream) {})
    .catch(function (err) {});

In every case calling requestUserMedia will return a promise, which resolves a MediaStream. Promises are supported in every browser in which getUserMedia is supported, however you may need to prevent this code from running if the user's browser doesn't have javascript Promises.

A stub or a polyfill perhaps, which mocks javascript Promises functionality.

Another way in which getUserMedia is a little strange is in stopping the stream. Some browsers return a list.

if (stream.getTracks)
    stream.getTracks().forEach(function (track) { track.stop(); });

It will get you off the ground. Now if only Safari would support this powerful feature right?