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

45 lines
1.3 KiB
JavaScript

import React, { Component, PropTypes } from 'react';
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';
import SettingsService from '/imports/ui/components/settings/service';
class ChatNotificationContainer extends Component {
constructor(props) {
super(props);
this.audio = new Audio('/html5client/resources/sounds/notify.mp3');
}
playAudio() {
if (this.props.disableAudio) return;
return _.debounce(() => this.audio.play(), this.audio.duration * 1000)();
}
componentDidUpdate(prevProps) {
if (this.props.unreadMessagesCount > prevProps.unreadMessagesCount) {
this.playAudio();
}
}
render() {
return null;
}
}
export default createContainer(({ currentChatID }) => {
const AppSettings = SettingsService.getSettingsFor('application');
const unreadMessagesCount = UserListService.getOpenChats()
.map(chat => chat.unreadCounter)
.filter(userID => userID !== Auth.userID)
.reduce((a, b) => a + b, 0);
return {
disableAudio: !AppSettings.chatAudioNotifications,
unreadMessagesCount,
};
}, ChatNotificationContainer);