2019-06-03 22:28:05 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-09-26 04:28:36 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2020-05-26 04:00:13 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2021-04-01 01:13:36 +08:00
|
|
|
import deviceInfo from '/imports/utils/deviceInfo';
|
2018-11-01 02:51:56 +08:00
|
|
|
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
|
2020-07-28 03:49:26 +08:00
|
|
|
import InputStreamLiveSelectorContainer from './input-stream-live-selector/container';
|
2020-06-16 21:41:51 +08:00
|
|
|
import MutedAlert from '/imports/ui/components/muted-alert/component';
|
2021-11-09 20:45:31 +08:00
|
|
|
import Styled from './styles';
|
2022-06-17 03:59:01 +08:00
|
|
|
import Button from '/imports/ui/components/common/button/component';
|
2023-03-24 23:29:09 +08:00
|
|
|
import AudioModalContainer from '../audio-modal/container';
|
2017-09-20 01:47:57 +08:00
|
|
|
|
2017-12-11 21:47:50 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
joinAudio: {
|
|
|
|
id: 'app.audio.joinAudio',
|
|
|
|
description: 'Join audio button label',
|
|
|
|
},
|
2021-03-19 02:12:01 +08:00
|
|
|
leaveAudio: {
|
|
|
|
id: 'app.audio.leaveAudio',
|
|
|
|
description: 'Leave audio button label',
|
|
|
|
},
|
2017-12-11 21:47:50 +08:00
|
|
|
muteAudio: {
|
|
|
|
id: 'app.actionsBar.muteLabel',
|
|
|
|
description: 'Mute audio button label',
|
|
|
|
},
|
|
|
|
unmuteAudio: {
|
|
|
|
id: 'app.actionsBar.unmuteLabel',
|
|
|
|
description: 'Unmute audio button label',
|
|
|
|
},
|
|
|
|
});
|
2017-09-20 01:47:57 +08:00
|
|
|
|
2017-09-26 04:28:36 +08:00
|
|
|
const propTypes = {
|
fix: breakout autojoin audio with wrong behavior
When joining/returning breakouts, audio would always connect
with full audio. This can lead to a performance problem, once
all listenonly users would join full audio, increasing the
number of streams in FreeSWITCH.
We now have a consistent behavior, which is:
1 - The choice made by the user in the main room is predominant:
if mic is active in main room, user will automatically
join mic in breakout room. When returning from breakout
room, user will also join with mic again.
2 - Changes made in breakout room won't have effect when
returning to the main room. This means if user, for example,
change from listenonly to mic in breakout room, the returning
will consider the option choosen previously (listenonly) and
listenonly will be active again in the main room.
3 - If user didn't join audio in the main room, the audio modal
will be prompted when joining the breakout room (this is
a special case of (1))
The following is some technicall information:
InputStreamLiveSelector (component.jsx) now calls
'handleLeaveAudio' function, which is the default
function when user leaves audio (also used when
dynamic devices are inactive).
We now store information about user's choice (mic or listenonly)
using local storage, instead of the previous cookie method (this
was triggering some warnings in browser's console).
Also did a small refactoring to match eslint rules.
Fixes #11662.
2021-04-21 01:38:11 +08:00
|
|
|
shortcuts: PropTypes.objectOf(PropTypes.string).isRequired,
|
2017-09-26 04:28:36 +08:00
|
|
|
handleToggleMuteMicrophone: PropTypes.func.isRequired,
|
|
|
|
handleLeaveAudio: PropTypes.func.isRequired,
|
2017-10-23 20:41:09 +08:00
|
|
|
disable: PropTypes.bool.isRequired,
|
2019-03-22 06:16:56 +08:00
|
|
|
muted: PropTypes.bool.isRequired,
|
|
|
|
showMute: PropTypes.bool.isRequired,
|
|
|
|
inAudio: PropTypes.bool.isRequired,
|
|
|
|
listenOnly: PropTypes.bool.isRequired,
|
2021-03-19 02:12:01 +08:00
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
2019-03-22 06:16:56 +08:00
|
|
|
talking: PropTypes.bool.isRequired,
|
2017-09-26 04:28:36 +08:00
|
|
|
};
|
2017-09-20 01:47:57 +08:00
|
|
|
|
2019-06-03 22:28:05 +08:00
|
|
|
class AudioControls extends PureComponent {
|
2020-07-28 03:49:26 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2023-03-24 23:29:09 +08:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
isAudioModalOpen: false,
|
|
|
|
};
|
|
|
|
|
2022-06-09 03:42:41 +08:00
|
|
|
this.renderButtonsAndStreamSelector = this.renderButtonsAndStreamSelector.bind(this);
|
2021-03-19 02:12:01 +08:00
|
|
|
this.renderJoinLeaveButton = this.renderJoinLeaveButton.bind(this);
|
2023-03-24 23:29:09 +08:00
|
|
|
this.setAudioModalIsOpen = this.setAudioModalIsOpen.bind(this);
|
2020-07-28 03:49:26 +08:00
|
|
|
}
|
|
|
|
|
2021-03-19 02:12:01 +08:00
|
|
|
renderJoinButton() {
|
|
|
|
const {
|
|
|
|
disable,
|
|
|
|
intl,
|
|
|
|
shortcuts,
|
2023-03-24 23:29:09 +08:00
|
|
|
joinListenOnly,
|
|
|
|
isConnected
|
2021-03-19 02:12:01 +08:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
2022-06-17 03:59:01 +08:00
|
|
|
<Button
|
2023-03-24 23:29:09 +08:00
|
|
|
onClick={() => this.handleJoinAudio(joinListenOnly, isConnected)}
|
2021-03-19 02:12:01 +08:00
|
|
|
disabled={disable}
|
|
|
|
hideLabel
|
|
|
|
aria-label={intl.formatMessage(intlMessages.joinAudio)}
|
|
|
|
label={intl.formatMessage(intlMessages.joinAudio)}
|
2021-08-26 03:27:50 +08:00
|
|
|
data-test="joinAudio"
|
2021-03-19 02:12:01 +08:00
|
|
|
color="default"
|
|
|
|
ghost
|
2021-10-19 04:26:01 +08:00
|
|
|
icon="no_audio"
|
2021-03-19 02:12:01 +08:00
|
|
|
size="lg"
|
|
|
|
circle
|
|
|
|
accessKey={shortcuts.joinaudio}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-09 03:42:41 +08:00
|
|
|
renderButtonsAndStreamSelector(_enableDynamicDeviceSelection) {
|
2021-03-19 02:12:01 +08:00
|
|
|
const {
|
2022-06-09 03:42:41 +08:00
|
|
|
handleLeaveAudio, handleToggleMuteMicrophone, muted, disable, talking,
|
2021-03-19 02:12:01 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2022-10-25 01:20:49 +08:00
|
|
|
const { isMobile } = deviceInfo;
|
|
|
|
|
2021-03-19 02:12:01 +08:00
|
|
|
return (
|
2022-06-09 03:42:41 +08:00
|
|
|
<InputStreamLiveSelectorContainer {...{
|
|
|
|
handleLeaveAudio,
|
|
|
|
handleToggleMuteMicrophone,
|
|
|
|
muted,
|
|
|
|
disable,
|
|
|
|
talking,
|
2022-10-25 01:20:49 +08:00
|
|
|
isMobile,
|
2022-06-09 03:42:41 +08:00
|
|
|
_enableDynamicDeviceSelection,
|
|
|
|
}}
|
2021-03-19 02:12:01 +08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderJoinLeaveButton() {
|
|
|
|
const {
|
|
|
|
inAudio,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
let { enableDynamicAudioDeviceSelection } = Meteor.settings.public.app;
|
|
|
|
|
|
|
|
if (typeof enableDynamicAudioDeviceSelection === 'undefined') {
|
|
|
|
enableDynamicAudioDeviceSelection = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inAudio) {
|
2024-04-16 01:37:20 +08:00
|
|
|
return this.renderButtonsAndStreamSelector(enableDynamicAudioDeviceSelection);
|
2021-03-19 02:12:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.renderJoinButton();
|
|
|
|
}
|
|
|
|
|
2023-03-24 23:29:09 +08:00
|
|
|
handleJoinAudio(joinListenOnly, isConnected) {
|
|
|
|
(isConnected()
|
|
|
|
? joinListenOnly()
|
|
|
|
: this.setAudioModalIsOpen(true)
|
|
|
|
)}
|
|
|
|
|
|
|
|
setAudioModalIsOpen(value) {
|
|
|
|
this.setState({ isAudioModalOpen: value })
|
|
|
|
}
|
|
|
|
|
2018-11-01 23:03:16 +08:00
|
|
|
render() {
|
|
|
|
const {
|
2019-03-22 06:16:56 +08:00
|
|
|
showMute,
|
|
|
|
muted,
|
2019-08-22 20:05:06 +08:00
|
|
|
isVoiceUser,
|
2021-04-01 03:09:08 +08:00
|
|
|
listenOnly,
|
2020-06-16 23:03:45 +08:00
|
|
|
inputStream,
|
2020-06-23 21:38:59 +08:00
|
|
|
isViewer,
|
|
|
|
isPresenter,
|
2018-11-01 23:03:16 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2023-03-24 23:29:09 +08:00
|
|
|
const { isAudioModalOpen } = this.state;
|
|
|
|
|
2020-10-27 05:07:15 +08:00
|
|
|
const MUTE_ALERT_CONFIG = Meteor.settings.public.app.mutedAlert;
|
|
|
|
const { enabled: muteAlertEnabled } = MUTE_ALERT_CONFIG;
|
2021-01-31 01:04:07 +08:00
|
|
|
|
2018-11-01 23:03:16 +08:00
|
|
|
return (
|
2021-11-09 20:45:31 +08:00
|
|
|
<Styled.Container>
|
2021-07-06 22:59:42 +08:00
|
|
|
{isVoiceUser && inputStream && muteAlertEnabled && !listenOnly && muted && showMute ? (
|
2021-01-31 01:04:07 +08:00
|
|
|
<MutedAlert {...{
|
|
|
|
muted, inputStream, isViewer, isPresenter,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : null}
|
2020-07-28 03:49:26 +08:00
|
|
|
{
|
2021-03-19 02:12:01 +08:00
|
|
|
this.renderJoinLeaveButton()
|
2020-07-28 03:49:26 +08:00
|
|
|
}
|
2023-03-24 23:29:09 +08:00
|
|
|
{
|
|
|
|
isAudioModalOpen ? <AudioModalContainer
|
|
|
|
{...{
|
2023-03-29 22:08:56 +08:00
|
|
|
priority: "low",
|
2023-03-24 23:29:09 +08:00
|
|
|
setIsOpen: this.setAudioModalIsOpen,
|
|
|
|
isOpen: isAudioModalOpen
|
|
|
|
}}
|
|
|
|
/> : null
|
|
|
|
}
|
2021-11-09 20:45:31 +08:00
|
|
|
</Styled.Container>
|
2020-06-16 21:41:51 +08:00
|
|
|
);
|
2018-11-01 23:03:16 +08:00
|
|
|
}
|
|
|
|
}
|
2017-09-26 04:28:36 +08:00
|
|
|
|
|
|
|
AudioControls.propTypes = propTypes;
|
|
|
|
|
2021-03-19 02:12:01 +08:00
|
|
|
export default withShortcutHelper(injectIntl(AudioControls), ['joinAudio',
|
|
|
|
'leaveAudio', 'toggleMute']);
|