2017-09-20 01:47:57 +08:00
|
|
|
import React from 'react';
|
2018-01-08 12:44:42 +08:00
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
2017-09-26 04:28:36 +08:00
|
|
|
import { withModalMounter } from '/imports/ui/components/modal/service';
|
2018-11-01 23:03:16 +08:00
|
|
|
import AudioManager from '/imports/ui/services/audio-manager';
|
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
2019-05-24 00:47:56 +08:00
|
|
|
import lockContextContainer from '/imports/ui/components/lock-viewers/context/container';
|
2019-07-26 02:41:24 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2020-06-23 21:38:59 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import Users from '/imports/api/users';
|
2021-02-05 02:42:31 +08:00
|
|
|
import Storage from '/imports/ui/services/storage/session';
|
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
2017-09-20 01:47:57 +08:00
|
|
|
import AudioControls from './component';
|
2017-09-29 21:38:10 +08:00
|
|
|
import AudioModalContainer from '../audio-modal/container';
|
2020-03-03 04:49:15 +08:00
|
|
|
import { invalidateCookie } from '../audio-modal/service';
|
2017-09-20 01:47:57 +08:00
|
|
|
import Service from '../service';
|
2021-02-11 21:23:38 +08:00
|
|
|
import AppService from '/imports/ui/components/app/service';
|
2017-09-20 01:47:57 +08:00
|
|
|
|
2020-06-23 21:38:59 +08:00
|
|
|
const ROLE_VIEWER = Meteor.settings.public.user.role_viewer;
|
2021-02-05 02:42:31 +08:00
|
|
|
const APP_CONFIG = Meteor.settings.public.app;
|
2020-06-23 21:38:59 +08:00
|
|
|
|
2017-09-26 04:28:36 +08:00
|
|
|
const AudioControlsContainer = props => <AudioControls {...props} />;
|
2017-09-20 01:47:57 +08:00
|
|
|
|
2018-11-01 23:03:16 +08:00
|
|
|
const processToggleMuteFromOutside = (e) => {
|
2018-11-14 01:14:30 +08:00
|
|
|
switch (e.data) {
|
|
|
|
case 'c_mute': {
|
2020-02-14 03:19:29 +08:00
|
|
|
makeCall('toggleVoice');
|
2018-11-14 01:14:30 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-11-21 21:46:13 +08:00
|
|
|
case 'get_audio_joined_status': {
|
|
|
|
const audioJoinedState = AudioManager.isConnected ? 'joinedAudio' : 'notInAudio';
|
|
|
|
this.window.parent.postMessage({ response: audioJoinedState }, '*');
|
|
|
|
break;
|
|
|
|
}
|
2018-11-14 01:14:30 +08:00
|
|
|
case 'c_mute_status': {
|
|
|
|
const muteState = AudioManager.isMuted ? 'selfMuted' : 'selfUnmuted';
|
|
|
|
this.window.parent.postMessage({ response: muteState }, '*');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// console.log(e.data);
|
|
|
|
}
|
2018-11-01 23:03:16 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-11 21:23:38 +08:00
|
|
|
const handleLeaveAudio = () => {
|
|
|
|
const meetingIsBreakout = AppService.meetingIsBreakout();
|
|
|
|
|
2020-03-03 04:49:15 +08:00
|
|
|
if (!meetingIsBreakout) {
|
|
|
|
invalidateCookie('joinedAudio');
|
|
|
|
}
|
|
|
|
|
2021-02-05 02:42:31 +08:00
|
|
|
const skipOnFistJoin = getFromUserSettings('bbb_skip_check_audio_on_first_join', APP_CONFIG.skipCheckOnJoin);
|
|
|
|
if (skipOnFistJoin && !Storage.getItem('getEchoTest')) {
|
|
|
|
Storage.setItem('getEchoTest', true);
|
|
|
|
}
|
|
|
|
|
2019-07-26 02:41:24 +08:00
|
|
|
Service.exitAudio();
|
|
|
|
logger.info({
|
|
|
|
logCode: 'audiocontrols_leave_audio',
|
|
|
|
extraInfo: { logType: 'user_action' },
|
|
|
|
}, 'audio connection closed by user');
|
|
|
|
};
|
|
|
|
|
|
|
|
const {
|
2019-08-22 20:05:06 +08:00
|
|
|
isVoiceUser,
|
2019-07-26 02:41:24 +08:00
|
|
|
isConnected,
|
|
|
|
isListenOnly,
|
|
|
|
isEchoTest,
|
|
|
|
isMuted,
|
|
|
|
isConnecting,
|
|
|
|
isHangingUp,
|
|
|
|
isTalking,
|
|
|
|
toggleMuteMicrophone,
|
|
|
|
joinListenOnly,
|
|
|
|
} = Service;
|
|
|
|
|
2020-06-23 21:38:59 +08:00
|
|
|
export default lockContextContainer(withModalMounter(withTracker(({ mountModal, userLocks }) => {
|
|
|
|
const currentUser = Users.findOne({ meetingId: Auth.meetingID, userId: Auth.userID }, {
|
|
|
|
fields: {
|
|
|
|
role: 1,
|
|
|
|
presenter: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const isViewer = currentUser.role === ROLE_VIEWER;
|
|
|
|
const isPresenter = currentUser.presenter;
|
2021-03-07 09:09:43 +08:00
|
|
|
const { status } = Service.getBreakoutAudioTransferStatus();
|
2020-06-23 21:38:59 +08:00
|
|
|
|
2021-03-07 09:09:43 +08:00
|
|
|
if (status === AudioManager.BREAKOUT_AUDIO_TRANSFER_STATES.RETURNING) {
|
2021-03-08 02:01:12 +08:00
|
|
|
Service.setBreakoutAudioTransferStatus({
|
|
|
|
status: AudioManager.BREAKOUT_AUDIO_TRANSFER_STATES.DISCONNECTED,
|
|
|
|
});
|
2021-02-26 02:36:11 +08:00
|
|
|
Service.recoverMicState();
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:38:59 +08:00
|
|
|
return ({
|
|
|
|
processToggleMuteFromOutside: arg => processToggleMuteFromOutside(arg),
|
|
|
|
showMute: isConnected() && !isListenOnly() && !isEchoTest() && !userLocks.userMic,
|
|
|
|
muted: isConnected() && !isListenOnly() && isMuted(),
|
|
|
|
inAudio: isConnected() && !isEchoTest(),
|
|
|
|
listenOnly: isConnected() && isListenOnly(),
|
|
|
|
disable: isConnecting() || isHangingUp() || !Meteor.status().connected,
|
|
|
|
talking: isTalking() && !isMuted(),
|
|
|
|
isVoiceUser: isVoiceUser(),
|
|
|
|
handleToggleMuteMicrophone: () => toggleMuteMicrophone(),
|
|
|
|
handleJoinAudio: () => (isConnected() ? joinListenOnly() : mountModal(<AudioModalContainer />)),
|
|
|
|
handleLeaveAudio,
|
|
|
|
inputStream: AudioManager.inputStream,
|
|
|
|
isViewer,
|
|
|
|
isPresenter,
|
|
|
|
});
|
|
|
|
})(AudioControlsContainer)));
|