2017-08-04 20:24:57 +08:00
|
|
|
import React from 'react';
|
2018-01-08 12:44:42 +08:00
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
2017-05-02 03:52:57 +08:00
|
|
|
import { withModalMounter } from '/imports/ui/components/modal/service';
|
2017-10-19 03:40:01 +08:00
|
|
|
import { injectIntl, defineMessages } from 'react-intl';
|
2018-06-29 02:14:35 +08:00
|
|
|
import _ from 'lodash';
|
2017-11-22 21:11:21 +08:00
|
|
|
import Breakouts from '/imports/api/breakouts';
|
2018-07-10 03:23:16 +08:00
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2018-09-14 02:09:30 +08:00
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
2017-05-02 03:52:57 +08:00
|
|
|
import Service from './service';
|
2017-09-29 21:38:10 +08:00
|
|
|
import AudioModalContainer from './audio-modal/container';
|
2017-03-28 04:40:44 +08:00
|
|
|
|
2017-10-19 03:40:01 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
joinedAudio: {
|
|
|
|
id: 'app.audioManager.joinedAudio',
|
|
|
|
description: 'Joined audio toast message',
|
|
|
|
},
|
2017-10-23 20:41:09 +08:00
|
|
|
joinedEcho: {
|
2017-10-19 03:40:01 +08:00
|
|
|
id: 'app.audioManager.joinedEcho',
|
|
|
|
description: 'Joined echo test toast message',
|
|
|
|
},
|
|
|
|
leftAudio: {
|
|
|
|
id: 'app.audioManager.leftAudio',
|
|
|
|
description: 'Left audio toast message',
|
|
|
|
},
|
|
|
|
genericError: {
|
|
|
|
id: 'app.audioManager.genericError',
|
2018-06-20 23:36:26 +08:00
|
|
|
description: 'Generic error message',
|
2017-10-19 03:40:01 +08:00
|
|
|
},
|
|
|
|
connectionError: {
|
|
|
|
id: 'app.audioManager.connectionError',
|
2018-06-20 23:36:26 +08:00
|
|
|
description: 'Connection error message',
|
2017-10-19 03:40:01 +08:00
|
|
|
},
|
|
|
|
requestTimeout: {
|
|
|
|
id: 'app.audioManager.requestTimeout',
|
2018-06-20 23:36:26 +08:00
|
|
|
description: 'Request timeout error message',
|
2017-10-19 03:40:01 +08:00
|
|
|
},
|
|
|
|
invalidTarget: {
|
|
|
|
id: 'app.audioManager.invalidTarget',
|
2018-06-20 23:36:26 +08:00
|
|
|
description: 'Invalid target error message',
|
2017-10-19 03:40:01 +08:00
|
|
|
},
|
2017-10-27 01:14:56 +08:00
|
|
|
mediaError: {
|
|
|
|
id: 'app.audioManager.mediaError',
|
2018-06-20 23:36:26 +08:00
|
|
|
description: 'Media error message',
|
2017-10-27 01:14:56 +08:00
|
|
|
},
|
2018-06-27 21:56:03 +08:00
|
|
|
BrowserNotSupported: {
|
|
|
|
id: 'app.audioNotification.audioFailedError1003',
|
|
|
|
description: 'browser not supported error messsage',
|
|
|
|
},
|
2018-06-29 02:18:53 +08:00
|
|
|
iceNegotiationError: {
|
2018-06-27 21:56:03 +08:00
|
|
|
id: 'app.audioNotification.audioFailedError1007',
|
|
|
|
description: 'ice negociation error messsage',
|
|
|
|
},
|
2018-07-10 03:23:16 +08:00
|
|
|
reconectingAsListener: {
|
|
|
|
id: 'app.audioNotificaion.reconnectingAsListenOnly',
|
|
|
|
description: 'ice negociation error messsage',
|
|
|
|
},
|
2017-10-19 03:40:01 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-01-10 06:07:29 +08:00
|
|
|
class AudioContainer extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.init = props.init.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2017-05-04 05:39:07 +08:00
|
|
|
|
2017-08-15 03:19:35 +08:00
|
|
|
let didMountAutoJoin = false;
|
2017-08-05 04:33:25 +08:00
|
|
|
|
2018-01-08 12:44:42 +08:00
|
|
|
export default withModalMounter(injectIntl(withTracker(({ mountModal, intl }) => {
|
2017-04-20 04:42:48 +08:00
|
|
|
const APP_CONFIG = Meteor.settings.public.app;
|
2017-03-28 04:40:44 +08:00
|
|
|
|
2018-09-14 02:09:30 +08:00
|
|
|
const autoJoin = getFromUserSettings('autoJoin', APP_CONFIG.autoJoin);
|
2017-11-22 21:11:21 +08:00
|
|
|
const openAudioModal = mountModal.bind(
|
|
|
|
null,
|
|
|
|
<AudioModalContainer />,
|
|
|
|
);
|
2018-07-10 03:23:16 +08:00
|
|
|
if (Service.audioLocked() && Service.isConnected() && !Service.isListenOnly()) {
|
|
|
|
Service.exitAudio();
|
|
|
|
notify(intl.formatMessage(intlMessages.reconectingAsListener), 'info', 'audio_on');
|
|
|
|
Service.joinListenOnly();
|
|
|
|
}
|
2017-11-01 00:46:14 +08:00
|
|
|
|
|
|
|
Breakouts.find().observeChanges({
|
|
|
|
removed() {
|
2018-06-20 23:36:26 +08:00
|
|
|
// if the user joined a breakout room, the main room's audio was
|
|
|
|
// programmatically dropped to avoid interference. On breakout end,
|
|
|
|
// offer to rejoin main room audio only if the user is not in audio already
|
|
|
|
if (Service.isUsingAudio()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-12 01:00:16 +08:00
|
|
|
setTimeout(() => openAudioModal(), 0);
|
2017-11-01 00:46:14 +08:00
|
|
|
},
|
|
|
|
});
|
2017-08-04 20:24:57 +08:00
|
|
|
|
2018-06-29 02:14:35 +08:00
|
|
|
const webRtcError = _.range(1001, 1012)
|
|
|
|
.reduce((acc, value) => ({
|
|
|
|
...acc,
|
|
|
|
[value]: intl.formatMessage({ id: `app.audioNotification.audioFailedError${value}` }),
|
|
|
|
}), {});
|
2018-06-27 21:56:03 +08:00
|
|
|
|
2017-10-19 03:40:01 +08:00
|
|
|
const messages = {
|
|
|
|
info: {
|
|
|
|
JOINED_AUDIO: intl.formatMessage(intlMessages.joinedAudio),
|
|
|
|
JOINED_ECHO: intl.formatMessage(intlMessages.joinedEcho),
|
|
|
|
LEFT_AUDIO: intl.formatMessage(intlMessages.leftAudio),
|
|
|
|
},
|
|
|
|
error: {
|
|
|
|
GENERIC_ERROR: intl.formatMessage(intlMessages.genericError),
|
|
|
|
CONNECTION_ERROR: intl.formatMessage(intlMessages.connectionError),
|
|
|
|
REQUEST_TIMEOUT: intl.formatMessage(intlMessages.requestTimeout),
|
|
|
|
INVALID_TARGET: intl.formatMessage(intlMessages.invalidTarget),
|
2017-11-02 20:10:01 +08:00
|
|
|
MEDIA_ERROR: intl.formatMessage(intlMessages.mediaError),
|
2018-06-27 21:56:03 +08:00
|
|
|
WEBRTC_NOT_SUPPORTED: intl.formatMessage(intlMessages.BrowserNotSupported),
|
2018-06-29 02:18:53 +08:00
|
|
|
ICE_NEGOTIATION_FAILED: intl.formatMessage(intlMessages.iceNegotiationError),
|
2018-06-27 21:56:03 +08:00
|
|
|
...webRtcError,
|
2017-10-19 03:40:01 +08:00
|
|
|
},
|
2017-10-23 20:41:09 +08:00
|
|
|
};
|
2017-10-19 03:40:01 +08:00
|
|
|
|
2017-03-28 04:40:44 +08:00
|
|
|
return {
|
2017-05-02 03:52:57 +08:00
|
|
|
init: () => {
|
2017-10-19 03:40:01 +08:00
|
|
|
Service.init(messages);
|
2017-10-23 20:41:09 +08:00
|
|
|
Service.changeOutputDevice(document.querySelector('#remote-media').sinkId);
|
2018-03-02 20:01:34 +08:00
|
|
|
if (!autoJoin || didMountAutoJoin) return;
|
2017-11-01 00:46:14 +08:00
|
|
|
openAudioModal();
|
2017-08-15 03:19:35 +08:00
|
|
|
didMountAutoJoin = true;
|
2017-05-02 03:52:57 +08:00
|
|
|
},
|
2017-03-28 04:40:44 +08:00
|
|
|
};
|
2018-01-08 12:44:42 +08:00
|
|
|
})(AudioContainer)));
|