bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/chat/notification/container.jsx

47 lines
1.2 KiB
React
Raw Normal View History

import React, { Component } from 'react';
2017-10-06 20:50:01 +08:00
// import PropTypes from 'prop-types';
import { createContainer } from 'meteor/react-meteor-data';
import _ from 'lodash';
import Auth from '/imports/ui/services/auth';
import UserListService from '/imports/ui/components/user-list/service';
2017-03-29 02:41:48 +08:00
import Settings from '/imports/ui/services/settings';
class ChatNotificationContainer extends Component {
constructor(props) {
super(props);
this.audio = new Audio('/html5client/resources/sounds/notify.mp3');
}
2017-10-06 20:50:01 +08:00
componentDidUpdate(prevProps) {
if (this.props.unreadMessagesCount < prevProps.unreadMessagesCount) return;
this.playAudio();
}
playAudio() {
if (this.props.disableAudio) return;
2017-10-06 20:50:01 +08:00
_.debounce(() => this.audio.play(), this.audio.duration * 1000)();
}
render() {
return null;
}
}
2017-10-06 20:50:01 +08:00
export default createContainer(() => {
2017-03-29 02:41:48 +08:00
const AppSettings = Settings.application;
const unreadMessagesCount = UserListService.getOpenChats()
2017-10-06 20:50:01 +08:00
.map(chat => chat.unreadCounter)
.filter(userID => userID !== Auth.userID)
.reduce((a, b) => a + b, 0);
return {
disableAudio: !AppSettings.chatAudioNotifications,
unreadMessagesCount,
};
}, ChatNotificationContainer);