UNPKG

@twilio/voice-sdk

Version:
889 lines (887 loc) 67.3 kB
import { __awaiter } from 'tslib'; import { EventEmitter } from 'events'; import Device from './device.js'; import { NotSupportedError, InvalidArgumentError } from './errors/index.js'; import Log from './log.js'; import OutputDeviceCollection from './outputdevicecollection.js'; import MediaDeviceInfoShim from './shims/mediadeviceinfo.js'; import { difference, average } from './util.js'; /** * Aliases for audio kinds, used for labelling. */ const kindAliases = { audioinput: 'Audio Input', audiooutput: 'Audio Output', }; /** * Provides input and output audio-based functionality in one convenient class. */ class AudioHelper extends EventEmitter { /** * The currently set audio constraints set by setAudioConstraints(). Starts as null. */ get audioConstraints() { return this._audioConstraints; } /** * The active input device. Having no inputDevice specified by `setInputDevice()` * will disable input selection related functionality. */ get inputDevice() { return this._inputDevice; } /** * The current input stream coming from the microphone device or * the processed audio stream if there is an {@link AudioProcessor}. */ get inputStream() { return this._localProcessedStream || this._selectedInputDeviceStream; } /** * The processed stream if a local {@link AudioProcessor} was previously added. * @deprecated Use {@link AudioHelper#localProcessedStream} instead. */ get processedStream() { this._log.warn('AudioHelper#processedStream is deprecated. Please use AudioHelper#localProcessedStream instead.'); return this._localProcessedStream; } /** * The processed stream if a local {@link AudioProcessor} was previously added. */ get localProcessedStream() { return this._localProcessedStream; } /** * The processed stream if a remote {@link AudioProcessor} was previously added. */ get remoteProcessedStream() { return this._remoteProcessedStream; } /** * @internal * @param onActiveOutputsChanged - A callback to be called when the user changes the active output devices. * @param onActiveInputChanged - A callback to be called when the user changes the active input device. * @param [options] */ constructor(onActiveOutputsChanged, onActiveInputChanged, options) { super(); /** * A Map of all audio input devices currently available to the browser by their device ID. */ this.availableInputDevices = new Map(); /** * A Map of all audio output devices currently available to the browser by their device ID. */ this.availableOutputDevices = new Map(); /** * The currently set audio constraints set by setAudioConstraints(). */ this._audioConstraints = null; /** * The audio stream of the default device. * This is populated when _openDefaultDeviceWithConstraints is called, * See _selectedInputDeviceStream for differences. * TODO: Combine these two workflows (3.x?) */ this._defaultInputDeviceStream = null; /** * Whether each sound is enabled. */ this._enabledSounds = { [Device.SoundName.Disconnect]: true, [Device.SoundName.Incoming]: true, [Device.SoundName.Outgoing]: true, }; /** * The current input device. */ this._inputDevice = null; /** * The internal promise created when calling setInputDevice */ this._inputDevicePromise = null; /** * Whether the {@link AudioHelper} is currently polling the input stream's volume. */ this._isPollingInputVolume = false; /** * An instance of Logger to use. */ this._log = new Log('AudioHelper'); /** * Internal reference to the local processed stream. */ this._localProcessedStream = null; /** * Internal reference to the remote processed stream. */ this._remoteProcessedStream = null; /** * The selected input stream coming from the microphone device. * This is populated when the setInputDevice is called, meaning, * the end user manually selected it, which is different than * the defaultInputDeviceStream. * TODO: Combine these two workflows (3.x?) */ this._selectedInputDeviceStream = null; /** * A record of unknown devices (Devices without labels) */ this._unknownDeviceIndexes = { audioinput: {}, audiooutput: {}, }; /** * Update the available input and output devices * @internal */ this._updateAvailableDevices = () => { if (!this._mediaDevices || !this._enumerateDevices) { return Promise.reject('Enumeration not supported'); } return this._enumerateDevices().then((devices) => { this._updateDevices(devices.filter((d) => d.kind === 'audiooutput'), this.availableOutputDevices, this._removeLostOutput); this._updateDevices(devices.filter((d) => d.kind === 'audioinput'), this.availableInputDevices, this._removeLostInput); const defaultDevice = this.availableOutputDevices.get('default') || Array.from(this.availableOutputDevices.values())[0]; [this.speakerDevices, this.ringtoneDevices].forEach(outputDevices => { if (!outputDevices.get().size && this.availableOutputDevices.size && this.isOutputSelectionSupported) { outputDevices.set(defaultDevice.deviceId) .catch((reason) => { this._log.warn(`Unable to set audio output devices. ${reason}`); }); } }); }); }; /** * Remove an input device from inputs * @param lostDevice * @returns Whether the device was active */ this._removeLostInput = (lostDevice) => { if (!this.inputDevice || this.inputDevice.deviceId !== lostDevice.deviceId) { return false; } this._destroyLocalProcessedStream(); this._replaceStream(null); this._inputDevice = null; this._maybeStopPollingVolume(); const defaultDevice = this.availableInputDevices.get('default') || Array.from(this.availableInputDevices.values())[0]; if (defaultDevice) { this.setInputDevice(defaultDevice.deviceId); } return true; }; /** * Remove an input device from outputs * @param lostDevice * @returns Whether the device was active */ this._removeLostOutput = (lostDevice) => { const wasSpeakerLost = this.speakerDevices.delete(lostDevice); const wasRingtoneLost = this.ringtoneDevices.delete(lostDevice); return wasSpeakerLost || wasRingtoneLost; }; options = Object.assign({ AudioContext: typeof AudioContext !== 'undefined' && AudioContext, setSinkId: typeof HTMLAudioElement !== 'undefined' && HTMLAudioElement.prototype.setSinkId, }, options); this._beforeSetInputDevice = options.beforeSetInputDevice || (() => Promise.resolve()); this._updateUserOptions(options); this._audioProcessorEventObserver = options.audioProcessorEventObserver; this._mediaDevices = options.mediaDevices || navigator.mediaDevices; this._onActiveInputChanged = onActiveInputChanged; this._enumerateDevices = typeof options.enumerateDevices === 'function' ? options.enumerateDevices : this._mediaDevices && this._mediaDevices.enumerateDevices.bind(this._mediaDevices); const isAudioContextSupported = !!(options.AudioContext || options.audioContext); const isEnumerationSupported = !!this._enumerateDevices; if (options.enabledSounds) { this._enabledSounds = options.enabledSounds; } const isSetSinkSupported = typeof options.setSinkId === 'function'; this.isOutputSelectionSupported = isEnumerationSupported && isSetSinkSupported; this.isVolumeSupported = isAudioContextSupported; if (this.isVolumeSupported) { this._audioContext = options.audioContext || options.AudioContext && new options.AudioContext(); if (this._audioContext) { this._inputVolumeAnalyser = this._audioContext.createAnalyser(); this._inputVolumeAnalyser.fftSize = 32; this._inputVolumeAnalyser.smoothingTimeConstant = 0.3; } } this.ringtoneDevices = new OutputDeviceCollection('ringtone', this.availableOutputDevices, onActiveOutputsChanged, this.isOutputSelectionSupported); this.speakerDevices = new OutputDeviceCollection('speaker', this.availableOutputDevices, onActiveOutputsChanged, this.isOutputSelectionSupported); this.addListener('newListener', (eventName) => { if (eventName === 'inputVolume') { this._maybeStartPollingVolume(); } }); this.addListener('removeListener', (eventName) => { if (eventName === 'inputVolume') { this._maybeStopPollingVolume(); } }); this.once('newListener', () => { // NOTE (rrowland): Ideally we would only check isEnumerationSupported here, but // in at least one browser version (Tested in FF48) enumerateDevices actually // returns bad data for the listed devices. Instead, we check for // isOutputSelectionSupported to avoid these quirks that may negatively affect customers. if (!this.isOutputSelectionSupported) { this._log.warn('Warning: This browser does not support audio output selection.'); } if (!this.isVolumeSupported) { this._log.warn(`Warning: This browser does not support Twilio's volume indicator feature.`); } }); if (isEnumerationSupported) { this._initializeEnumeration(); } // NOTE (kchoy): Currently microphone permissions are not supported in firefox, and Safari V15 and older. // https://github.com/mozilla/standards-positions/issues/19#issuecomment-370158947 // https://caniuse.com/permissions-api if (navigator && navigator.permissions && typeof navigator.permissions.query === 'function') { navigator.permissions.query({ name: 'microphone' }).then((microphonePermissionStatus) => { if (microphonePermissionStatus.state !== 'granted') { const handleStateChange = () => { this._updateAvailableDevices(); this._stopMicrophonePermissionListener(); }; microphonePermissionStatus.addEventListener('change', handleStateChange); this._microphonePermissionStatus = microphonePermissionStatus; this._onMicrophonePermissionStatusChanged = handleStateChange; } }).catch((reason) => this._log.warn(`Warning: unable to listen for microphone permission changes. ${reason}`)); } else { this._log.warn('Warning: current browser does not support permissions API.'); } } /** * Destroy this AudioHelper instance * @internal */ _destroy() { this._stopDefaultInputDeviceStream(); this._stopSelectedInputDeviceStream(); this._destroyLocalProcessedStream(); this._destroyRemoteProcessedStream(); this._maybeStopPollingVolume(); this.removeAllListeners(); this._stopMicrophonePermissionListener(); this._unbind(); } /** * Destroys the remote processed stream and updates references. * @internal */ _destroyRemoteProcessedStream() { if (this._remoteProcessor && this._remoteProcessedStream) { this._log.info('destroying remote processed stream'); const remoteProcessedStream = this._remoteProcessedStream; this._remoteProcessedStream.getTracks().forEach(track => track.stop()); this._remoteProcessedStream = null; this._remoteProcessor.destroyProcessedStream(remoteProcessedStream); this._audioProcessorEventObserver.emit('destroy', true); } } /** * Promise to wait for the input device, if setInputDevice is called outside of the SDK. * @internal */ _getInputDevicePromise() { return this._inputDevicePromise; } /** * The current AudioProcessorEventObserver instance. * @internal */ _getAudioProcessorEventObserver() { return this._audioProcessorEventObserver; } /** * Route remote stream to the processor if it exists. * @internal */ _maybeCreateRemoteProcessedStream(stream) { if (this._remoteProcessor) { this._log.info('Creating remote processed stream'); return this._remoteProcessor.createProcessedStream(stream).then((processedStream) => { this._remoteProcessedStream = processedStream; this._audioProcessorEventObserver.emit('create', true); return this._remoteProcessedStream; }); } return Promise.resolve(stream); } /** * Start polling volume if it's supported and there's an input stream to poll. * @internal */ _maybeStartPollingVolume() { if (!this.isVolumeSupported || !this.inputStream) { return; } this._updateVolumeSource(); if (this._isPollingInputVolume || !this._inputVolumeAnalyser) { return; } const bufferLength = this._inputVolumeAnalyser.frequencyBinCount; const buffer = new Uint8Array(bufferLength); this._isPollingInputVolume = true; const emitVolume = () => { if (!this._isPollingInputVolume) { return; } if (this._inputVolumeAnalyser) { this._inputVolumeAnalyser.getByteFrequencyData(buffer); const inputVolume = average(buffer); this.emit('inputVolume', inputVolume / 255); } requestAnimationFrame(emitVolume); }; requestAnimationFrame(emitVolume); } /** * Stop polling volume if it's currently polling and there are no listeners. * @internal */ _maybeStopPollingVolume() { if (!this.isVolumeSupported) { return; } if (!this._isPollingInputVolume || (this.inputStream && this.listenerCount('inputVolume'))) { return; } if (this._inputVolumeSource) { this._inputVolumeSource.disconnect(); delete this._inputVolumeSource; } this._isPollingInputVolume = false; } /** * Call getUserMedia with specified constraints * @internal */ _openDefaultDeviceWithConstraints(constraints) { this._log.info('Opening default device with constraints', constraints); return this._getUserMedia(constraints).then((stream) => { this._log.info('Opened default device. Updating available devices.'); // Ensures deviceId's and labels are populated after the gUM call // by calling enumerateDevices this._updateAvailableDevices().catch(error => { // Ignore error, we don't want to break the call flow this._log.warn('Unable to updateAvailableDevices after gUM call', error); }); this._defaultInputDeviceStream = stream; return this._maybeCreateLocalProcessedStream(stream); }); } /** * Stop the default audio stream * @internal */ _stopDefaultInputDeviceStream() { if (this._defaultInputDeviceStream) { this._log.info('stopping default device stream'); this._defaultInputDeviceStream.getTracks().forEach(track => track.stop()); this._defaultInputDeviceStream = null; this._destroyLocalProcessedStream(); } } /** * Unbind the listeners from mediaDevices. * @internal */ _unbind() { var _a; if ((_a = this._mediaDevices) === null || _a === void 0 ? void 0 : _a.removeEventListener) { this._mediaDevices.removeEventListener('devicechange', this._updateAvailableDevices); } } /** * Update AudioHelper options that can be changed by the user * @internal */ _updateUserOptions(options) { if (typeof options.enumerateDevices === 'function') { this._enumerateDevices = options.enumerateDevices; } if (typeof options.getUserMedia === 'function') { this._getUserMedia = options.getUserMedia; } } /** * Adds an {@link AudioProcessor} object. Once added, the AudioHelper will route * the input audio stream through the processor before sending the audio * stream to Twilio. Only one AudioProcessor can be added at this time. * * See the {@link AudioProcessor} interface for an example. * * @param processor The AudioProcessor to add. * @param isRemote If set to true, the processor will be applied to the remote * audio track. Default value is false. * @returns */ addProcessor(processor, isRemote = false) { this._log.debug('.addProcessor'); if (this._localProcessor && !isRemote) { throw new NotSupportedError('Can only have one Local AudioProcessor at a time.'); } if (this._remoteProcessor && isRemote) { throw new NotSupportedError('Can only have one Remote AudioProcessor at a time.'); } if (typeof processor !== 'object' || processor === null) { throw new InvalidArgumentError('Missing AudioProcessor argument.'); } if (typeof processor.createProcessedStream !== 'function') { throw new InvalidArgumentError('Missing createProcessedStream() method.'); } if (typeof processor.destroyProcessedStream !== 'function') { throw new InvalidArgumentError('Missing destroyProcessedStream() method.'); } if (isRemote) { this._remoteProcessor = processor; this._audioProcessorEventObserver.emit('add', true); return Promise.resolve(); } else { this._localProcessor = processor; this._audioProcessorEventObserver.emit('add', false); return this._restartInputStreams(); } } /** * Enable or disable the disconnect sound. * @param doEnable Passing `true` will enable the sound and `false` will disable the sound. * Not passing this parameter will not alter the enable-status of the sound. * @returns The enable-status of the sound. */ disconnect(doEnable) { this._log.debug('.disconnect', doEnable); return this._maybeEnableSound(Device.SoundName.Disconnect, doEnable); } /** * Enable or disable the incoming sound. * @param doEnable Passing `true` will enable the sound and `false` will disable the sound. * Not passing this parameter will not alter the enable-status of the sound. * @returns The enable-status of the sound. */ incoming(doEnable) { this._log.debug('.incoming', doEnable); return this._maybeEnableSound(Device.SoundName.Incoming, doEnable); } /** * Enable or disable the outgoing sound. * @param doEnable Passing `true` will enable the sound and `false` will disable the sound. * Not passing this parameter will not alter the enable-status of the sound. * @returns The enable-status of the sound. */ outgoing(doEnable) { this._log.debug('.outgoing', doEnable); return this._maybeEnableSound(Device.SoundName.Outgoing, doEnable); } /** * Removes an {@link AudioProcessor}. Once removed, the AudioHelper will start using * the audio stream from the selected input device for existing or future calls. * * @param processor The AudioProcessor to remove. * @param isRemote If set to true, the processor will be removed from the remote * audio track. Default value is false. * @returns */ removeProcessor(processor, isRemote = false) { this._log.debug('.removeProcessor'); if (typeof processor !== 'object' || processor === null) { throw new InvalidArgumentError('Missing AudioProcessor argument.'); } if (this._localProcessor !== processor && !isRemote) { throw new InvalidArgumentError('Cannot remove a Local AudioProcessor that has not been previously added.'); } if (this._remoteProcessor !== processor && isRemote) { throw new InvalidArgumentError('Cannot remove a Remote AudioProcessor that has not been previously added.'); } if (isRemote) { this._destroyRemoteProcessedStream(); this._remoteProcessor = null; this._audioProcessorEventObserver.emit('remove', true); return Promise.resolve(); } else { this._destroyLocalProcessedStream(); this._localProcessor = null; this._audioProcessorEventObserver.emit('remove', false); return this._restartInputStreams(); } } /** * Set the MediaTrackConstraints to be applied on every getUserMedia call for new input * device audio. Any deviceId specified here will be ignored. Instead, device IDs should * be specified using {@link AudioHelper#setInputDevice}. The returned Promise resolves * when the media is successfully reacquired, or immediately if no input device is set. * @param audioConstraints - The MediaTrackConstraints to apply. */ setAudioConstraints(audioConstraints) { this._log.debug('.setAudioConstraints', audioConstraints); this._audioConstraints = Object.assign({}, audioConstraints); delete this._audioConstraints.deviceId; return this.inputDevice ? this._setInputDevice(this.inputDevice.deviceId, true) : Promise.resolve(); } /** * Replace the current input device with a new device by ID. * * Calling `setInputDevice` sets the stream for current and future calls and * will not release it automatically. * * While this behavior is not an issue, it will result in the application * holding onto the input device, and the application may show a red * "recording" symbol in the browser tab. * * To remove the red "recording" symbol, the device must be released. To * release it, call `unsetInputDevice` after the call disconnects. Note that * after calling `unsetInputDevice` future calls will then use the default * input device. * * Consider application logic that keeps track of the user-selected device * and call `setInputDevice` before calling `device.connect()` for outgoing * calls and `call.accept()` for incoming calls. Furthermore, consider * calling `unsetInputDevice` once a call is disconnected. Below is an * example: * * ```ts * import { Device } from '@twilio/voice-sdk'; * let inputDeviceId = ...; * const device = new Device(...); * * async function makeOutgoingCall() { * await device.audio.setInputDevice(inputDeviceId); * const call = await device.connect(...); * * call.on('disconnect', async () => { * inputDeviceId = ... // save the current input device id * await device.audio.unsetInputDevice(); * }); * } * * async function acceptIncomingCall(incomingCall) { * await device.audio.setInputDevice(inputDeviceId); * await incomingCall.accept(); * * incomingCall.on('disconnect', async () => { * inputDeviceId = ... // save the current input device id * await device.audio.unsetInputDevice(); * }); * } * ``` * * @param deviceId - An ID of a device to replace the existing * input device with. */ setInputDevice(deviceId) { this._log.debug('.setInputDevice', deviceId); return this._setInputDevice(deviceId, false); } /** * Unset the MediaTrackConstraints to be applied on every getUserMedia call for new input * device audio. The returned Promise resolves when the media is successfully reacquired, * or immediately if no input device is set. */ unsetAudioConstraints() { this._log.debug('.unsetAudioConstraints'); this._audioConstraints = null; return this.inputDevice ? this._setInputDevice(this.inputDevice.deviceId, true) : Promise.resolve(); } /** * Unset the input device, stopping the tracks. This should only be called when not in a connection, and * will not allow removal of the input device during a live call. */ unsetInputDevice() { this._log.debug('.unsetInputDevice', this.inputDevice); if (!this.inputDevice) { return Promise.resolve(); } this._destroyLocalProcessedStream(); return this._onActiveInputChanged(null).then(() => { this._replaceStream(null); this._inputDevice = null; this._maybeStopPollingVolume(); }); } /** * Destroys the local processed stream and updates references. */ _destroyLocalProcessedStream() { if (this._localProcessor && this._localProcessedStream) { this._log.info('destroying local processed stream'); const localProcessedStream = this._localProcessedStream; this._localProcessedStream.getTracks().forEach(track => track.stop()); this._localProcessedStream = null; this._localProcessor.destroyProcessedStream(localProcessedStream); this._audioProcessorEventObserver.emit('destroy', false); } } /** * Get the index of an un-labeled Device. * @param mediaDeviceInfo * @returns The index of the passed MediaDeviceInfo */ _getUnknownDeviceIndex(mediaDeviceInfo) { const id = mediaDeviceInfo.deviceId; const kind = mediaDeviceInfo.kind; let index = this._unknownDeviceIndexes[kind][id]; if (!index) { index = Object.keys(this._unknownDeviceIndexes[kind]).length + 1; this._unknownDeviceIndexes[kind][id] = index; } return index; } /** * Initialize output device enumeration. */ _initializeEnumeration() { if (!this._mediaDevices || !this._enumerateDevices) { throw new NotSupportedError('Enumeration is not supported'); } if (this._mediaDevices.addEventListener) { this._mediaDevices.addEventListener('devicechange', this._updateAvailableDevices); } this._updateAvailableDevices().then(() => { if (!this.isOutputSelectionSupported) { return; } Promise.all([ this.speakerDevices.set('default'), this.ringtoneDevices.set('default'), ]).catch(reason => { this._log.warn(`Warning: Unable to set audio output devices. ${reason}`); }); }); } /** * Route local stream to the processor if it exists. */ _maybeCreateLocalProcessedStream(stream) { if (this._localProcessor) { this._log.info('Creating local processed stream'); return this._localProcessor.createProcessedStream(stream).then((processedStream) => { this._localProcessedStream = processedStream; this._audioProcessorEventObserver.emit('create', false); return this._localProcessedStream; }); } return Promise.resolve(stream); } /** * Set whether the sound is enabled or not * @param soundName * @param doEnable * @returns Whether the sound is enabled or not */ _maybeEnableSound(soundName, doEnable) { if (typeof doEnable !== 'undefined') { this._enabledSounds[soundName] = doEnable; } return this._enabledSounds[soundName]; } /** * Stop the tracks on the current input stream before replacing it with the passed stream. * @param stream - The new stream */ _replaceStream(stream) { this._log.info('Replacing with new stream.'); if (this._selectedInputDeviceStream) { this._log.info('Old stream detected. Stopping tracks.'); this._stopSelectedInputDeviceStream(); } this._selectedInputDeviceStream = stream; } /** * Restart the active input streams */ _restartInputStreams() { if (this.inputDevice && this._selectedInputDeviceStream) { this._log.info('Restarting selected input device'); return this._setInputDevice(this.inputDevice.deviceId, true); } if (this._defaultInputDeviceStream) { const defaultDevice = this.availableInputDevices.get('default') || Array.from(this.availableInputDevices.values())[0]; this._log.info('Restarting default input device, now becoming selected.'); return this._setInputDevice(defaultDevice.deviceId, true); } return Promise.resolve(); } /** * Replace the current input device with a new device by ID. * @param deviceId - An ID of a device to replace the existing * input device with. * @param forceGetUserMedia - If true, getUserMedia will be called even if * the specified device is already active. */ _setInputDevice(deviceId, forceGetUserMedia) { return __awaiter(this, void 0, void 0, function* () { const setInputDevice = () => __awaiter(this, void 0, void 0, function* () { yield this._beforeSetInputDevice(); if (typeof deviceId !== 'string') { return Promise.reject(new InvalidArgumentError('Must specify the device to set')); } const device = this.availableInputDevices.get(deviceId); if (!device) { return Promise.reject(new InvalidArgumentError(`Device not found: ${deviceId}`)); } this._log.info('Setting input device. ID: ' + deviceId); if (this._inputDevice && this._inputDevice.deviceId === deviceId && this._selectedInputDeviceStream) { if (!forceGetUserMedia) { return Promise.resolve(); } // If the currently active track is still in readyState `live`, gUM may return the same track // rather than returning a fresh track. this._log.info('Same track detected on setInputDevice, stopping old tracks.'); this._stopSelectedInputDeviceStream(); } // Release the default device in case it was created previously this._stopDefaultInputDeviceStream(); const constraints = { audio: Object.assign({ deviceId: { exact: deviceId } }, this.audioConstraints) }; this._log.info('setInputDevice: getting new tracks.'); return this._getUserMedia(constraints).then((originalStream) => { this._destroyLocalProcessedStream(); return this._maybeCreateLocalProcessedStream(originalStream).then((newStream) => { this._log.info('setInputDevice: invoking _onActiveInputChanged.'); return this._onActiveInputChanged(newStream).then(() => { this._replaceStream(originalStream); this._inputDevice = device; this._maybeStartPollingVolume(); }); }); }); }); return this._inputDevicePromise = setInputDevice().finally(() => { this._inputDevicePromise = null; }); }); } /** * Remove event listener for microphone permissions */ _stopMicrophonePermissionListener() { var _a; if ((_a = this._microphonePermissionStatus) === null || _a === void 0 ? void 0 : _a.removeEventListener) { this._microphonePermissionStatus.removeEventListener('change', this._onMicrophonePermissionStatusChanged); } } /** * Stop the selected audio stream */ _stopSelectedInputDeviceStream() { if (this._selectedInputDeviceStream) { this._log.info('Stopping selected device stream'); this._selectedInputDeviceStream.getTracks().forEach(track => track.stop()); } } /** * Update a set of devices. * @param updatedDevices - An updated list of available Devices * @param availableDevices - The previous list of available Devices * @param removeLostDevice - The method to call if a previously available Device is * no longer available. */ _updateDevices(updatedDevices, availableDevices, removeLostDevice) { const updatedDeviceIds = updatedDevices.map(d => d.deviceId); const knownDeviceIds = Array.from(availableDevices.values()).map(d => d.deviceId); const lostActiveDevices = []; // Remove lost devices const lostDeviceIds = difference(knownDeviceIds, updatedDeviceIds); lostDeviceIds.forEach((lostDeviceId) => { const lostDevice = availableDevices.get(lostDeviceId); if (lostDevice) { availableDevices.delete(lostDeviceId); if (removeLostDevice(lostDevice)) { lostActiveDevices.push(lostDevice); } } }); // Add any new devices, or devices with updated labels let deviceChanged = false; updatedDevices.forEach(newDevice => { const existingDevice = availableDevices.get(newDevice.deviceId); const newMediaDeviceInfo = this._wrapMediaDeviceInfo(newDevice); if (!existingDevice || existingDevice.label !== newMediaDeviceInfo.label) { availableDevices.set(newDevice.deviceId, newMediaDeviceInfo); deviceChanged = true; } }); if (deviceChanged || lostDeviceIds.length) { // Force a new gUM in case the underlying tracks of the active stream have changed. One // reason this might happen is when `default` is selected and set to a USB device, // then that device is unplugged or plugged back in. We can't check for the 'ended' // event or readyState because it is asynchronous and may take upwards of 5 seconds, // in my testing. (rrowland) const defaultId = 'default'; // this.inputDevice is not null if audio.setInputDevice() was explicitly called const isInputDeviceSet = this.inputDevice && this.inputDevice.deviceId === defaultId; // If this.inputDevice is null, and default stream is not null, it means // the user is using the default stream and did not explicitly call audio.setInputDevice() const isDefaultDeviceSet = this._defaultInputDeviceStream && this.availableInputDevices.get(defaultId); if (isInputDeviceSet || isDefaultDeviceSet) { this._log.warn(`Calling getUserMedia after device change to ensure that the \ tracks of the active device (default) have not gone stale.`); // NOTE(csantos): Updating the stream in the same execution context as the devicechange event // causes the new gUM call to fail silently. Meaning, the gUM call may succeed, // but it won't actually update the stream. We need to update the stream in a different // execution context (setTimeout) to properly update the stream. setTimeout(() => { this._setInputDevice(defaultId, true); }, 0); } this._log.debug('#deviceChange', lostActiveDevices); this.emit('deviceChange', lostActiveDevices); } } /** * Disconnect the old input volume source, and create and connect a new one with the current * input stream. */ _updateVolumeSource() { if (!this.inputStream || !this._audioContext || !this._inputVolumeAnalyser) { return; } if (this._inputVolumeSource) { this._inputVolumeSource.disconnect(); } try { this._inputVolumeSource = this._audioContext.createMediaStreamSource(this.inputStream); this._inputVolumeSource.connect(this._inputVolumeAnalyser); } catch (ex) { this._log.warn('Unable to update volume source', ex); delete this._inputVolumeSource; } } /** * Convert a MediaDeviceInfo to a IMediaDeviceInfoShim. * @param mediaDeviceInfo - The info to convert * @returns The converted shim */ _wrapMediaDeviceInfo(mediaDeviceInfo) { const options = { deviceId: mediaDeviceInfo.deviceId, groupId: mediaDeviceInfo.groupId, kind: mediaDeviceInfo.kind, label: mediaDeviceInfo.label, }; if (!options.label) { if (options.deviceId === 'default') { options.label = 'Default'; } else { const index = this._getUnknownDeviceIndex(mediaDeviceInfo); options.label = `Unknown ${kindAliases[options.kind]} Device ${index}`; } } return new MediaDeviceInfoShim(options); } } /** * @mergeModuleWith AudioHelper */ (function (AudioHelper) { })(AudioHelper || (AudioHelper = {})); var AudioHelper$1 = AudioHelper; export { AudioHelper$1 as default }; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXVkaW9oZWxwZXIuanMiLCJzb3VyY2VzIjpbIi4uLy4uL2xpYi90d2lsaW8vYXVkaW9oZWxwZXIudHMiXSwic291cmNlc0NvbnRlbnQiOltudWxsXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBVUE7O0FBRUc7QUFDSCxNQUFNLFdBQVcsR0FBMkI7QUFDMUMsSUFBQSxVQUFVLEVBQUUsYUFBYTtBQUN6QixJQUFBLFdBQVcsRUFBRSxjQUFjO0NBQzVC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