Merge pull request #14907 from prlanzarin/u26-plastic-lyre

fix(audio): guarantee consistency of selected output devices in AudioSettings
This commit is contained in:
Paulo Lanzarin 2022-04-29 15:01:29 -03:00 committed by GitHub
commit 3fd64ad7b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 24 deletions

View File

@ -93,9 +93,12 @@ class AudioSettings extends React.Component {
} }
componentDidMount() { componentDidMount() {
const { inputDeviceId } = this.state; const { inputDeviceId, outputDeviceId } = this.state;
this._isMounted = true; this._isMounted = true;
this.handleInputChange(inputDeviceId); // Guarantee initial in/out devices are initialized on all ends
this.setInputDevice(inputDeviceId);
this.setOutputDevice(outputDeviceId);
} }
componentWillUnmount() { componentWillUnmount() {
@ -109,6 +112,32 @@ class AudioSettings extends React.Component {
} }
handleInputChange(deviceId) { handleInputChange(deviceId) {
this.setInputDevice(deviceId);
}
handleOutputChange(deviceId) {
this.setOutputDevice(deviceId);
}
handleConfirmationClick() {
const { stream } = this.state;
const {
produceStreams,
handleConfirmation,
} = this.props;
// Stream generation disabled or there isn't any stream: just run the provided callback
if (!produceStreams || !stream) return handleConfirmation();
// Stream generation enabled and there is a valid input stream => call
// the confirmation callback with the input stream as arg so it can be used
// in upstream components. The rationale is no surplus gUM calls.
// We're cloning it because the original will be cleaned up on unmount here.
const clonedStream = stream.clone();
return handleConfirmation(clonedStream);
}
setInputDevice(deviceId) {
const { const {
handleGUMFailure, handleGUMFailure,
changeInputDevice, changeInputDevice,
@ -148,7 +177,7 @@ class AudioSettings extends React.Component {
} }
} }
handleOutputChange(deviceId) { setOutputDevice(deviceId) {
const { const {
changeOutputDevice, changeOutputDevice,
withEcho, withEcho,
@ -163,24 +192,6 @@ class AudioSettings extends React.Component {
}); });
} }
handleConfirmationClick() {
const { stream } = this.state;
const {
produceStreams,
handleConfirmation,
} = this.props;
// Stream generation disabled or there isn't any stream: just run the provided callback
if (!produceStreams || !stream) return handleConfirmation();
// Stream generation enabled and there is a valid input stream => call
// the confirmation callback with the input stream as arg so it can be used
// in upstream components. The rationale is no surplus gUM calls.
// We're cloning it because the original will be cleaned up on unmount here.
const clonedStream = stream.clone();
return handleConfirmation(clonedStream);
}
generateInputStream(inputDeviceId) { generateInputStream(inputDeviceId) {
const { stream } = this.state; const { stream } = this.state;

View File

@ -112,9 +112,7 @@ export default {
changeInputStream: (newInputStream) => { AudioManager.inputStream = newInputStream; }, changeInputStream: (newInputStream) => { AudioManager.inputStream = newInputStream; },
liveChangeInputDevice: (inputDeviceId) => AudioManager.liveChangeInputDevice(inputDeviceId), liveChangeInputDevice: (inputDeviceId) => AudioManager.liveChangeInputDevice(inputDeviceId),
changeOutputDevice: (outputDeviceId, isLive) => { changeOutputDevice: (outputDeviceId, isLive) => {
if (AudioManager.outputDeviceId !== outputDeviceId) { AudioManager.changeOutputDevice(outputDeviceId, isLive);
AudioManager.changeOutputDevice(outputDeviceId, isLive);
}
}, },
isConnected: () => AudioManager.isConnected, isConnected: () => AudioManager.isConnected,
isTalking: () => AudioManager.isTalking, isTalking: () => AudioManager.isTalking,