public/js/browser-calls.js
/**
 * Make a custom MediaDevices object, and proxy through existing functionality. If
 *   devicechange is present, we simply reemit the event. If not, we will do the
 *   detection ourselves and fire the event when necessary. The same logic exists
 *   for deviceinfochange for consistency, however deviceinfochange is our own event
 *   so it is unlikely that it will ever be native. The w3c spec for devicechange
 *   is unclear as to whether MediaDeviceInfo changes (such as label) will
 *   trigger the devicechange event. We have an open question on this here:
 *   https://bugs.chromium.org/p/chromium/issues/detail?id=585096
 */
Make a custom MediaDevices object, and proxy through existing functionality. If
devicechange is present, we simply reemit the event. If not, we will do the
detection ourselves and fire the event when necessary. The same logic exists
for deviceinfochange for consistency, however deviceinfochange is our own event
so it is unlikely that it will ever be native. The w3c spec for devicechange
is unclear as to whether MediaDeviceInfo changes (such as label) will
trigger the devicechange event.
Make a custom MediaDevices object and proxy through existing functionality . If devicechange is present we simply reemit the event . If not we will do the detection ourselves and fire the event when necessary . The same logic exists for deviceinfochange for consistency however deviceinfochange is our own event so it is unlikely that it will ever be native . The w3c spec for devicechange is unclear as to whether MediaDeviceInfo changes ( such as label ) will trigger the devicechange event .
function MediaDevicesShim() {
    EventTarget.call(this);
    this._defineEventHandler('devicechange');
    this._defineEventHandler('deviceinfochange');
    var knownDevices = [];
    Object.defineProperties(this, {
        _deviceChangeIsNative: {
            value: reemitNativeEvent(this, 'devicechange')
        },
        _deviceInfoChangeIsNative: {
            value: reemitNativeEvent(this, 'deviceinfochange')
        },
        _knownDevices: {
            value: knownDevices
        },
        _pollInterval: {
            value: null,
            writable: true
        }
    });
    if (typeof nativeMediaDevices.enumerateDevices === 'function') {
        nativeMediaDevices.enumerateDevices().then(function (devices) {
            devices.sort(sortDevicesById).forEach([].push, knownDevices);
        });
    }
    this._eventEmitter.on('newListener', function maybeStartPolling(eventName) {
        if (eventName !== 'devicechange' && eventName !== 'deviceinfochange') {
            return;
        }
        this._pollInterval = this._pollInterval
            || setInterval(sampleDevices.bind(null, this), POLL_INTERVAL_MS);
    }.bind(this));
    this._eventEmitter.on('removeListener', function maybeStopPolling() {
        if (this._pollInterval && !hasChangeListeners(this)) {
            clearInterval(this._pollInterval);
            this._pollInterval = null;
        }
    }.bind(this));
}
function MediaDevicesShim ( ) { EventTarget . call ( this ) ; this . _defineEventHandler ( 'devicechange' ) ; this . _defineEventHandler ( 'deviceinfochange' ) ; var knownDevices = [ ] ; Object . defineProperties ( this , { _deviceChangeIsNative : { value : reemitNativeEvent ( this , 'devicechange' ) } , _deviceInfoChangeIsNative : { value : reemitNativeEvent ( this , 'deviceinfochange' ) } , _knownDevices : { value : knownDevices } , _pollInterval : { value : null , writable : true } } ) ; if ( typeof nativeMediaDevices . enumerateDevices === 'function' ) { nativeMediaDevices . enumerateDevices ( ) . then ( function ( devices ) { devices . sort ( sortDevicesById ) . forEach ( [ ] . push , knownDevices ) ; } ) ; } this . _eventEmitter . on ( 'newListener' , function maybeStartPolling ( eventName ) { if ( eventName !== 'devicechange' && eventName !== 'deviceinfochange' ) { return ; } this . _pollInterval = this . _pollInterval || setInterval ( sampleDevices . bind ( null , this ) , POLL_INTERVAL_MS ) ; } . bind ( this ) ) ; this . _eventEmitter . on ( 'removeListener' , function maybeStopPolling ( ) { if ( this . _pollInterval && ! hasChangeListeners ( this ) ) { clearInterval ( this . _pollInterval ) ; this . _pollInterval = null ; } } . bind ( this ) ) ; }
Make a custom MediaDevices object, and proxy through existing functionality.
Make a custom MediaDevices object and proxy through existing functionality .