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';
|
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';
|
2017-09-20 01:47:57 +08:00
|
|
|
import Service from '../service';
|
|
|
|
|
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': {
|
|
|
|
makeCall('toggleSelfVoice');
|
|
|
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-26 02:41:24 +08:00
|
|
|
const handleLeaveAudio = () => {
|
|
|
|
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;
|
|
|
|
|
2019-05-24 00:47:56 +08:00
|
|
|
export default lockContextContainer(withModalMounter(withTracker(({ mountModal, userLocks }) => ({
|
2018-12-10 10:12:42 +08:00
|
|
|
processToggleMuteFromOutside: arg => processToggleMuteFromOutside(arg),
|
2019-07-26 02:41:24 +08:00
|
|
|
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(),
|
2019-08-22 20:05:06 +08:00
|
|
|
isVoiceUser: isVoiceUser(),
|
2019-07-26 02:41:24 +08:00
|
|
|
handleToggleMuteMicrophone: () => toggleMuteMicrophone(),
|
|
|
|
handleJoinAudio: () => (isConnected() ? joinListenOnly() : mountModal(<AudioModalContainer />)),
|
|
|
|
handleLeaveAudio,
|
2019-05-24 00:47:56 +08:00
|
|
|
}))(AudioControlsContainer)));
|