2017-01-26 03:52:17 +08:00
|
|
|
import { createContainer } from 'meteor/react-meteor-data';
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import AudioNotification from './component';
|
|
|
|
|
2017-01-30 23:42:58 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
audioFailed: {
|
|
|
|
id: 'app.audioNotification.audioFailedMessage',
|
|
|
|
description: 'The audio could not connect, Try again',
|
|
|
|
},
|
2017-02-01 00:06:12 +08:00
|
|
|
mediaFailed: {
|
|
|
|
id: 'app.audioNotification.mediaFailedMessage',
|
|
|
|
description: 'Could not access getUserMicMedia, Try again',
|
|
|
|
},
|
2017-01-30 23:42:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
class AudioNotificationContainer extends Component {
|
2017-01-26 03:52:17 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.color = null;
|
|
|
|
this.message = null;
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
status: null,
|
2017-03-25 00:38:49 +08:00
|
|
|
};
|
2017-01-26 03:52:17 +08:00
|
|
|
|
|
|
|
this.handleAudioFailure = this.handleAudioFailure.bind(this);
|
2017-02-01 00:06:12 +08:00
|
|
|
this.handleMediaFailure = this.handleMediaFailure.bind(this);
|
2017-01-26 03:52:17 +08:00
|
|
|
this.handleClose = this.handleClose.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2017-03-25 00:38:49 +08:00
|
|
|
window.addEventListener('bbb.webrtc.failed', this.handleAudioFailure);
|
|
|
|
window.addEventListener('bbb.webrtc.mediaFailed', this.handleMediaFailure);
|
|
|
|
window.addEventListener('bbb.webrtc.connected', this.handleClose);
|
2017-01-26 03:52:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2017-03-25 00:38:49 +08:00
|
|
|
window.removeEventListener('bbb.webrtc.failed', this.handleAudioFailure);
|
|
|
|
window.removeEventListener('bbb.webrtc.mediaFailed', this.handleMediaFailure);
|
|
|
|
window.removeEventListener('bbb.webrtc.connected', this.handleClose);
|
2017-01-26 03:52:17 +08:00
|
|
|
}
|
|
|
|
|
2017-02-07 23:16:04 +08:00
|
|
|
handleClose() {
|
2017-01-26 03:52:17 +08:00
|
|
|
this.color = null;
|
|
|
|
this.message = null;
|
2017-03-25 00:38:49 +08:00
|
|
|
this.setState({ status: null });
|
2017-01-26 03:52:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handleAudioFailure() {
|
2017-01-30 23:42:58 +08:00
|
|
|
this.message = this.props.audioFailure;
|
2017-03-25 00:38:49 +08:00
|
|
|
this.setState({ status: 'failed' });
|
2017-01-26 03:52:17 +08:00
|
|
|
}
|
|
|
|
|
2017-02-01 00:06:12 +08:00
|
|
|
handleMediaFailure() {
|
|
|
|
this.message = this.props.mediaFailure;
|
2017-03-25 00:38:49 +08:00
|
|
|
this.setState({ status: 'failed' });
|
2017-02-01 00:06:12 +08:00
|
|
|
}
|
|
|
|
|
2017-01-26 03:52:17 +08:00
|
|
|
render() {
|
|
|
|
const handleClose = this.handleClose;
|
2017-02-01 00:13:01 +08:00
|
|
|
this.color = 'danger';
|
2017-01-26 03:52:17 +08:00
|
|
|
|
2017-03-25 00:38:49 +08:00
|
|
|
return (
|
2017-01-26 03:52:17 +08:00
|
|
|
<AudioNotification
|
|
|
|
color={this.color}
|
|
|
|
message={this.message}
|
2017-03-25 00:38:49 +08:00
|
|
|
handleClose={handleClose}
|
2017-01-26 03:52:17 +08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-01-30 23:42:58 +08:00
|
|
|
|
|
|
|
export default injectIntl(createContainer(({ intl }) => {
|
|
|
|
let messages = {};
|
|
|
|
messages.audioFailure = intl.formatMessage(intlMessages.audioFailed);
|
2017-02-01 00:06:12 +08:00
|
|
|
messages.mediaFailure = intl.formatMessage(intlMessages.mediaFailed);
|
2017-01-30 23:42:58 +08:00
|
|
|
return messages;
|
|
|
|
}, AudioNotificationContainer));
|