bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/subscriptions/component.jsx

136 lines
4.5 KiB
React
Raw Normal View History

import { Component } from 'react';
import { withTracker } from 'meteor/react-meteor-data';
import Auth from '/imports/ui/services/auth';
import logger from '/imports/startup/client/logger';
import GroupChat from '/imports/api/group-chat';
import Annotations from '/imports/api/annotations';
import Users from '/imports/api/users';
import AnnotationsTextService from '/imports/ui/components/whiteboard/annotations/text/service';
2020-04-07 04:34:08 +08:00
import { Annotations as AnnotationsLocal } from '/imports/ui/components/whiteboard/service';
2019-08-23 23:17:32 +08:00
const CHAT_CONFIG = Meteor.settings.public.chat;
const CHAT_ENABLED = CHAT_CONFIG.enabled;
const PUBLIC_GROUP_CHAT_ID = CHAT_CONFIG.public_group_id;
const PUBLIC_CHAT_TYPE = CHAT_CONFIG.type_public;
2019-08-23 23:17:32 +08:00
const TYPING_INDICATOR_ENABLED = CHAT_CONFIG.typingIndicator.enabled;
const SUBSCRIPTIONS = [
'users', 'meetings', 'polls', 'presentations', 'slides', 'slide-positions', 'captions',
'voiceUsers', 'whiteboard-multi-user', 'screenshare', 'group-chat',
'presentation-pods', 'users-settings', 'guestUser', 'users-infos', 'note', 'meeting-time-remaining',
refactor(connection status): remove legacy monitor Remove parts of a previous connection monitor. To add some context (as far as my memory goes) to the multiple connection monitor features the product has, `stats` (currently named `connection status`) was introduced at the Flash client back in ~2016. @fcecagno and I did it as a BigBlueButton's Summit activity. Our work was squashed into a single commit in 92554f8b3e39918a88af0ae9f5b85057cb0556eb :). I'm not sure about the whole story behind `network information` (the late connection monitor added to the HTML5 client) but I assume it should work as a collector for a bunch of different connectivity monitors. I remember when it was introduced but I don't know why it wasn't adopted. My best guess would be because of some performance issues the `user list` had back then. To follow on why `connection status` replaced `network information` at the HTML5 client, when I did the `multiple webcams` feature I had to refactor a big chunk of the `video provider` (#8374). Something that wasn't really helping there was the adaptation of `stats` that was made to show local feedback for each webcam connection. Although this feature wasn't being used anymore, `network information` did rely on that to build up data. With this monitor gone I assumed it was my responsibility to provide an alternative so I promoted Mconf's port of the Flash `stats` monitor to BigBlueButton's HTML5 client (#8579). Well, that's my perspective on how things went for those features. If anyone would like to correct me on something or add something else on that history I would appreciate to know.
2021-06-13 23:36:43 +08:00
'local-settings', 'users-typing', 'record-meetings', 'video-streams',
'connection-status', 'voice-call-states', 'external-video-meetings',
];
2021-04-14 01:35:46 +08:00
const EVENT_NAME = 'bbb-group-chat-messages-subscription-has-stoppped';
const EVENT_NAME_SUBSCRIPTION_READY = 'bbb-group-chat-messages-subscriptions-ready';
2021-04-14 01:35:46 +08:00
class Subscriptions extends Component {
componentDidUpdate() {
const { subscriptionsReady } = this.props;
if (subscriptionsReady) {
Session.set('subscriptionsReady', true);
const event = new Event(EVENT_NAME_SUBSCRIPTION_READY);
window.dispatchEvent(event);
}
}
render() {
const { children } = this.props;
return children;
}
}
export default withTracker(() => {
const { credentials } = Auth;
const { meetingId, requesterUserId } = credentials;
if (Session.get('codeError')) {
return {
subscriptionsReady: true,
};
}
2019-07-02 03:00:27 +08:00
const currentUser = Users.findOne({ intId: requesterUserId }, { fields: { role: 1 } });
const subscriptionErrorHandler = {
onError: (error) => {
logger.error({
logCode: 'startup_client_subscription_error',
extraInfo: { error },
}, 'Error while subscribing to collections');
Session.set('codeError', error.error);
},
};
let subscriptionsHandlers = SUBSCRIPTIONS.map((name) => {
if ((!TYPING_INDICATOR_ENABLED && name.indexOf('typing') !== -1)
|| (!CHAT_ENABLED && name.indexOf('chat') !== -1)) return;
return Meteor.subscribe(name, subscriptionErrorHandler);
});
if (currentUser) {
subscriptionsHandlers.push(Meteor.subscribe('meetings', currentUser.role, subscriptionErrorHandler));
subscriptionsHandlers.push(Meteor.subscribe('users', currentUser.role, {
...subscriptionErrorHandler,
onStop: () => {
const event = new Event(EVENT_NAME);
window.dispatchEvent(event);
},
}));
subscriptionsHandlers.push(Meteor.subscribe('breakouts', currentUser.role, subscriptionErrorHandler));
subscriptionsHandlers.push(Meteor.subscribe('guestUser', currentUser.role, subscriptionErrorHandler));
}
const annotationsHandler = Meteor.subscribe('annotations', {
onReady: () => {
const activeTextShapeId = AnnotationsTextService.activeTextShapeId();
AnnotationsLocal.remove({ id: { $ne: `${activeTextShapeId}-fake` } });
2019-05-07 04:32:45 +08:00
Annotations.find({ id: { $ne: activeTextShapeId } }, { reactive: false }).forEach((a) => {
try {
AnnotationsLocal.insert(a);
} catch (e) {
// TODO
}
});
annotationsHandler.stop();
},
...subscriptionErrorHandler,
});
subscriptionsHandlers = subscriptionsHandlers.filter(obj => obj);
const ready = subscriptionsHandlers.every(handler => handler.ready());
let groupChatMessageHandler = {};
if (CHAT_ENABLED && ready) {
const chatsCount = GroupChat.find({
$or: [
{
meetingId,
access: PUBLIC_CHAT_TYPE,
chatId: { $ne: PUBLIC_GROUP_CHAT_ID },
},
{ meetingId, users: { $all: [requesterUserId] } },
],
}).count();
2021-04-14 01:35:46 +08:00
const subHandler = {
...subscriptionErrorHandler,
};
groupChatMessageHandler = Meteor.subscribe('group-chat-msg', chatsCount, subHandler);
}
// TODO: Refactor all the late subscribers
let usersPersistentDataHandler = {};
if (ready) {
usersPersistentDataHandler = Meteor.subscribe('users-persistent-data');
}
return {
subscriptionsReady: ready,
subscriptionsHandlers,
};
})(Subscriptions);