2016-11-16 05:00:28 +08:00
|
|
|
import React from 'react';
|
2017-10-11 02:03:29 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2020-05-26 04:00:13 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2022-02-15 04:20:50 +08:00
|
|
|
import Button from '/imports/ui/components/common/button/component';
|
2022-02-15 23:54:55 +08:00
|
|
|
import { withModalMounter } from '/imports/ui/components/common/modal/service';
|
2017-03-23 21:19:44 +08:00
|
|
|
import AudioTestContainer from '/imports/ui/components/audio/audio-test/container';
|
2021-11-09 22:33:40 +08:00
|
|
|
import Styled from './styles';
|
2022-04-05 05:09:35 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
|
|
|
import AudioStreamVolume from '/imports/ui/components/audio/audio-stream-volume/component';
|
2022-04-12 04:18:43 +08:00
|
|
|
import LocalEchoContainer from '/imports/ui/components/audio/local-echo/container';
|
2022-04-05 05:09:35 +08:00
|
|
|
import {
|
|
|
|
getAudioConstraints,
|
|
|
|
} from '/imports/api/audio/client/bridge/service';
|
|
|
|
import MediaStreamUtils from '/imports/utils/media-stream-utils';
|
2017-09-26 04:28:36 +08:00
|
|
|
|
2017-10-11 02:03:29 +08:00
|
|
|
const propTypes = {
|
2021-08-09 22:24:02 +08:00
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
2017-10-11 02:03:29 +08:00
|
|
|
changeInputDevice: PropTypes.func.isRequired,
|
|
|
|
changeOutputDevice: PropTypes.func.isRequired,
|
|
|
|
handleBack: PropTypes.func.isRequired,
|
2022-04-05 05:09:35 +08:00
|
|
|
handleConfirmation: PropTypes.func.isRequired,
|
|
|
|
handleGUMFailure: PropTypes.func.isRequired,
|
2017-10-11 02:03:29 +08:00
|
|
|
isConnecting: PropTypes.bool.isRequired,
|
|
|
|
inputDeviceId: PropTypes.string.isRequired,
|
|
|
|
outputDeviceId: PropTypes.string.isRequired,
|
2022-04-13 05:32:06 +08:00
|
|
|
produceStreams: PropTypes.bool,
|
|
|
|
withEcho: PropTypes.bool,
|
|
|
|
withVolumeMeter: PropTypes.bool,
|
2017-10-11 02:03:29 +08:00
|
|
|
};
|
|
|
|
|
2022-04-13 05:32:06 +08:00
|
|
|
const defaultProps = {
|
|
|
|
produceStreams: false,
|
|
|
|
withEcho: false,
|
|
|
|
withVolumeMeter: false,
|
2022-04-19 04:05:26 +08:00
|
|
|
};
|
2022-04-13 05:32:06 +08:00
|
|
|
|
2017-09-26 04:28:36 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
backLabel: {
|
|
|
|
id: 'app.audio.backLabel',
|
|
|
|
description: 'audio settings back button label',
|
|
|
|
},
|
|
|
|
descriptionLabel: {
|
|
|
|
id: 'app.audio.audioSettings.descriptionLabel',
|
|
|
|
description: 'audio settings description label',
|
|
|
|
},
|
|
|
|
micSourceLabel: {
|
|
|
|
id: 'app.audio.audioSettings.microphoneSourceLabel',
|
|
|
|
description: 'Label for mic source',
|
|
|
|
},
|
|
|
|
speakerSourceLabel: {
|
|
|
|
id: 'app.audio.audioSettings.speakerSourceLabel',
|
|
|
|
description: 'Label for speaker source',
|
|
|
|
},
|
2022-04-02 00:56:16 +08:00
|
|
|
testSpeakerLabel: {
|
|
|
|
id: 'app.audio.audioSettings.testSpeakerLabel',
|
2022-04-02 03:39:15 +08:00
|
|
|
description: 'Label for the speaker test button',
|
2022-04-02 00:56:16 +08:00
|
|
|
},
|
2017-09-26 04:28:36 +08:00
|
|
|
streamVolumeLabel: {
|
|
|
|
id: 'app.audio.audioSettings.microphoneStreamLabel',
|
|
|
|
description: 'Label for stream volume',
|
|
|
|
},
|
2017-10-05 04:49:11 +08:00
|
|
|
retryLabel: {
|
2022-04-05 05:09:35 +08:00
|
|
|
id: 'app.audio.joinAudio',
|
|
|
|
description: 'Confirmation button label',
|
2017-09-29 21:38:10 +08:00
|
|
|
},
|
2017-09-26 04:28:36 +08:00
|
|
|
});
|
2016-12-01 11:37:52 +08:00
|
|
|
|
2017-02-17 04:57:57 +08:00
|
|
|
class AudioSettings extends React.Component {
|
2016-11-16 05:00:28 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2017-10-11 02:03:29 +08:00
|
|
|
const {
|
2017-10-27 21:19:24 +08:00
|
|
|
inputDeviceId,
|
|
|
|
outputDeviceId,
|
2017-10-11 02:03:29 +08:00
|
|
|
} = props;
|
|
|
|
|
2016-12-09 02:17:08 +08:00
|
|
|
this.handleInputChange = this.handleInputChange.bind(this);
|
|
|
|
this.handleOutputChange = this.handleOutputChange.bind(this);
|
2022-04-12 06:18:40 +08:00
|
|
|
this.handleConfirmationClick = this.handleConfirmationClick.bind(this);
|
2017-10-04 04:42:10 +08:00
|
|
|
|
2016-12-09 02:17:08 +08:00
|
|
|
this.state = {
|
2017-10-27 21:19:24 +08:00
|
|
|
inputDeviceId,
|
|
|
|
outputDeviceId,
|
2022-04-13 05:32:06 +08:00
|
|
|
// If streams need to be produced, device selectors are blocked until
|
|
|
|
// at least one stream is generated
|
|
|
|
deviceSelectorsBlocked: props.produceStreams,
|
2022-04-05 05:09:35 +08:00
|
|
|
stream: null,
|
2017-03-23 04:10:49 +08:00
|
|
|
};
|
2022-04-05 05:09:35 +08:00
|
|
|
|
|
|
|
this._isMounted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2022-04-29 00:36:22 +08:00
|
|
|
const { inputDeviceId, outputDeviceId } = this.state;
|
|
|
|
|
2022-04-05 05:09:35 +08:00
|
|
|
this._isMounted = true;
|
2022-04-29 00:36:22 +08:00
|
|
|
// Guarantee initial in/out devices are initialized on all ends
|
|
|
|
this.setInputDevice(inputDeviceId);
|
|
|
|
this.setOutputDevice(outputDeviceId);
|
2022-04-05 05:09:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
const { stream } = this.state;
|
|
|
|
|
|
|
|
this._mounted = false;
|
|
|
|
|
|
|
|
if (stream) {
|
|
|
|
MediaStreamUtils.stopMediaStreamTracks(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 20:41:09 +08:00
|
|
|
handleInputChange(deviceId) {
|
2022-04-29 00:36:22 +08:00
|
|
|
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) {
|
2017-10-27 21:19:24 +08:00
|
|
|
const {
|
2022-04-05 05:09:35 +08:00
|
|
|
handleGUMFailure,
|
2017-10-27 21:19:24 +08:00
|
|
|
changeInputDevice,
|
2022-04-13 05:32:06 +08:00
|
|
|
produceStreams,
|
2017-10-27 21:19:24 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2017-11-01 01:34:06 +08:00
|
|
|
changeInputDevice(deviceId);
|
2022-04-05 05:09:35 +08:00
|
|
|
|
|
|
|
// Only generate input streams if they're going to be used with something
|
|
|
|
// In this case, the volume meter or local echo test.
|
2022-04-13 05:32:06 +08:00
|
|
|
if (produceStreams) {
|
2022-04-05 05:09:35 +08:00
|
|
|
this.generateInputStream(deviceId).then((stream) => {
|
|
|
|
if (!this._isMounted) return;
|
2022-04-13 05:32:06 +08:00
|
|
|
|
2022-04-05 05:09:35 +08:00
|
|
|
this.setState({
|
2022-04-28 22:38:35 +08:00
|
|
|
// We extract the deviceId again from the stream to guarantee consistency
|
|
|
|
// between stream vs chosen device
|
|
|
|
inputDeviceId: MediaStreamUtils.extractDeviceIdFromStream(stream, 'audio'),
|
2022-04-05 05:09:35 +08:00
|
|
|
stream,
|
2022-04-13 05:32:06 +08:00
|
|
|
deviceSelectorsBlocked: false,
|
2022-04-05 05:09:35 +08:00
|
|
|
});
|
|
|
|
}).catch((error) => {
|
|
|
|
logger.warn({
|
|
|
|
logCode: 'audiosettings_gum_failed',
|
|
|
|
extraInfo: {
|
|
|
|
deviceId,
|
|
|
|
errorMessage: error.message,
|
|
|
|
errorName: error.name,
|
|
|
|
},
|
|
|
|
}, `Audio settings gUM failed: ${error.name}`);
|
|
|
|
handleGUMFailure(error);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
inputDeviceId: deviceId,
|
|
|
|
});
|
|
|
|
}
|
2016-12-09 02:17:08 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 00:36:22 +08:00
|
|
|
setOutputDevice(deviceId) {
|
2017-10-27 21:19:24 +08:00
|
|
|
const {
|
|
|
|
changeOutputDevice,
|
2022-04-05 05:09:35 +08:00
|
|
|
withEcho,
|
2017-10-27 21:19:24 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2022-04-13 05:32:06 +08:00
|
|
|
// withEcho usage (isLive arg): if local echo is enabled we need the device
|
|
|
|
// change to be performed seamlessly (which is what the isLive parameter guarantes)
|
2022-04-05 05:09:35 +08:00
|
|
|
changeOutputDevice(deviceId, withEcho);
|
2022-04-13 05:32:06 +08:00
|
|
|
|
2017-09-26 04:28:36 +08:00
|
|
|
this.setState({
|
|
|
|
outputDeviceId: deviceId,
|
|
|
|
});
|
2016-12-09 02:17:08 +08:00
|
|
|
}
|
|
|
|
|
2022-04-19 04:05:26 +08:00
|
|
|
generateInputStream(inputDeviceId) {
|
|
|
|
const { stream } = this.state;
|
|
|
|
|
|
|
|
if (inputDeviceId && stream) {
|
|
|
|
const currentDeviceId = MediaStreamUtils.extractDeviceIdFromStream(stream, 'audio');
|
|
|
|
|
|
|
|
if (currentDeviceId === inputDeviceId) return Promise.resolve(stream);
|
|
|
|
|
|
|
|
MediaStreamUtils.stopMediaStreamTracks(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
const constraints = {
|
|
|
|
audio: getAudioConstraints({ deviceId: inputDeviceId }),
|
|
|
|
};
|
|
|
|
|
|
|
|
return navigator.mediaDevices.getUserMedia(constraints);
|
|
|
|
}
|
|
|
|
|
2022-04-05 05:09:35 +08:00
|
|
|
renderOutputTest() {
|
|
|
|
const { withEcho, intl } = this.props;
|
|
|
|
const { stream } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Styled.Row>
|
|
|
|
<Styled.SpacedLeftCol>
|
|
|
|
<Styled.LabelSmall htmlFor="audioTest">
|
|
|
|
{intl.formatMessage(intlMessages.testSpeakerLabel)}
|
|
|
|
{!withEcho
|
|
|
|
? <AudioTestContainer id="audioTest" />
|
2022-04-19 04:05:26 +08:00
|
|
|
: (
|
|
|
|
<LocalEchoContainer
|
|
|
|
intl={intl}
|
2022-04-12 04:18:43 +08:00
|
|
|
stream={stream}
|
|
|
|
/>
|
2022-04-19 04:05:26 +08:00
|
|
|
)}
|
2022-04-05 05:09:35 +08:00
|
|
|
</Styled.LabelSmall>
|
|
|
|
</Styled.SpacedLeftCol>
|
|
|
|
</Styled.Row>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderVolumeMeter() {
|
2022-04-12 03:40:16 +08:00
|
|
|
const { withVolumeMeter, intl } = this.props;
|
2022-04-05 05:09:35 +08:00
|
|
|
const { stream } = this.state;
|
|
|
|
|
|
|
|
return withVolumeMeter ? (
|
|
|
|
<Styled.Row>
|
|
|
|
<Styled.LabelSmallFullWidth htmlFor="audioStreamVolume">
|
|
|
|
{intl.formatMessage(intlMessages.streamVolumeLabel)}
|
|
|
|
<AudioStreamVolume
|
|
|
|
stream={stream}
|
|
|
|
/>
|
|
|
|
</Styled.LabelSmallFullWidth>
|
|
|
|
</Styled.Row>
|
2022-04-19 04:05:26 +08:00
|
|
|
) : null;
|
2022-04-05 05:09:35 +08:00
|
|
|
}
|
|
|
|
|
2022-04-13 05:32:06 +08:00
|
|
|
renderDeviceSelectors() {
|
|
|
|
const { inputDeviceId, outputDeviceId, deviceSelectorsBlocked } = this.state;
|
|
|
|
const { intl } = this.props;
|
2022-04-12 06:18:40 +08:00
|
|
|
|
2022-04-13 05:32:06 +08:00
|
|
|
return (
|
|
|
|
<Styled.Row>
|
|
|
|
<Styled.Col>
|
|
|
|
<Styled.FormElement>
|
|
|
|
<Styled.LabelSmall htmlFor="inputDeviceSelector">
|
|
|
|
{intl.formatMessage(intlMessages.micSourceLabel)}
|
|
|
|
<Styled.DeviceSelectorSelect
|
|
|
|
id="inputDeviceSelector"
|
2022-04-28 22:38:35 +08:00
|
|
|
deviceId={inputDeviceId}
|
2022-04-13 05:32:06 +08:00
|
|
|
kind="audioinput"
|
|
|
|
blocked={deviceSelectorsBlocked}
|
|
|
|
onChange={this.handleInputChange}
|
|
|
|
intl={intl}
|
|
|
|
/>
|
|
|
|
</Styled.LabelSmall>
|
|
|
|
</Styled.FormElement>
|
|
|
|
</Styled.Col>
|
|
|
|
<Styled.Col>
|
|
|
|
<Styled.FormElement>
|
|
|
|
<Styled.LabelSmall htmlFor="outputDeviceSelector">
|
|
|
|
{intl.formatMessage(intlMessages.speakerSourceLabel)}
|
|
|
|
<Styled.DeviceSelectorSelect
|
|
|
|
id="outputDeviceSelector"
|
2022-04-28 22:38:35 +08:00
|
|
|
deviceId={outputDeviceId}
|
2022-04-13 05:32:06 +08:00
|
|
|
kind="audiooutput"
|
|
|
|
blocked={deviceSelectorsBlocked}
|
|
|
|
onChange={this.handleOutputChange}
|
|
|
|
intl={intl}
|
|
|
|
/>
|
|
|
|
</Styled.LabelSmall>
|
|
|
|
</Styled.FormElement>
|
|
|
|
</Styled.Col>
|
|
|
|
</Styled.Row>
|
|
|
|
);
|
2022-04-12 06:18:40 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 05:00:28 +08:00
|
|
|
render() {
|
2017-02-17 04:57:57 +08:00
|
|
|
const {
|
2017-09-29 21:38:10 +08:00
|
|
|
isConnecting,
|
2017-02-17 04:57:57 +08:00
|
|
|
intl,
|
2017-10-27 21:19:24 +08:00
|
|
|
handleBack,
|
2017-02-17 04:57:57 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2016-11-16 05:00:28 +08:00
|
|
|
return (
|
2021-11-09 22:33:40 +08:00
|
|
|
<Styled.FormWrapper>
|
|
|
|
<Styled.Form>
|
|
|
|
<Styled.Row>
|
|
|
|
<Styled.AudioNote>
|
2017-04-07 20:44:05 +08:00
|
|
|
{intl.formatMessage(intlMessages.descriptionLabel)}
|
2021-11-09 22:33:40 +08:00
|
|
|
</Styled.AudioNote>
|
|
|
|
</Styled.Row>
|
2022-04-13 05:32:06 +08:00
|
|
|
{this.renderDeviceSelectors()}
|
2022-04-05 05:09:35 +08:00
|
|
|
{this.renderOutputTest()}
|
|
|
|
{this.renderVolumeMeter()}
|
2021-11-09 22:33:40 +08:00
|
|
|
</Styled.Form>
|
2017-03-23 04:10:49 +08:00
|
|
|
|
2021-11-09 22:33:40 +08:00
|
|
|
<Styled.EnterAudio>
|
|
|
|
<Styled.BackButton
|
2017-09-26 04:28:36 +08:00
|
|
|
label={intl.formatMessage(intlMessages.backLabel)}
|
2019-03-12 12:14:31 +08:00
|
|
|
size="md"
|
|
|
|
color="primary"
|
2017-10-27 21:19:24 +08:00
|
|
|
onClick={handleBack}
|
2017-09-29 21:38:10 +08:00
|
|
|
disabled={isConnecting}
|
|
|
|
ghost
|
2017-09-26 04:28:36 +08:00
|
|
|
/>
|
2017-09-29 21:38:10 +08:00
|
|
|
<Button
|
2019-03-12 12:14:31 +08:00
|
|
|
size="md"
|
|
|
|
color="primary"
|
2017-10-05 04:49:11 +08:00
|
|
|
label={intl.formatMessage(intlMessages.retryLabel)}
|
2022-04-12 06:18:40 +08:00
|
|
|
onClick={this.handleConfirmationClick}
|
2017-10-05 04:49:11 +08:00
|
|
|
/>
|
2021-11-09 22:33:40 +08:00
|
|
|
</Styled.EnterAudio>
|
|
|
|
</Styled.FormWrapper>
|
2017-09-29 21:42:08 +08:00
|
|
|
);
|
2016-11-16 05:00:28 +08:00
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|
2017-02-17 04:57:57 +08:00
|
|
|
|
2017-10-11 02:03:29 +08:00
|
|
|
AudioSettings.propTypes = propTypes;
|
2022-04-19 04:05:26 +08:00
|
|
|
AudioSettings.defaultProps = defaultProps;
|
2017-10-11 02:03:29 +08:00
|
|
|
|
2017-05-03 01:18:01 +08:00
|
|
|
export default withModalMounter(injectIntl(AudioSettings));
|