2019-07-29 22:17:38 +08:00
|
|
|
import { Component } from 'react';
|
2019-04-25 04:48:16 +08:00
|
|
|
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';
|
2020-06-05 21:32:05 +08:00
|
|
|
import Users from '/imports/api/users';
|
2019-04-25 04:48:16 +08:00
|
|
|
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-04-25 04:48:16 +08:00
|
|
|
|
2019-08-23 23:17:32 +08:00
|
|
|
|
2019-04-25 04:48:16 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
2019-07-18 05:00:33 +08:00
|
|
|
const CHAT_ENABLED = CHAT_CONFIG.enabled;
|
2019-04-25 04:48:16 +08:00
|
|
|
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;
|
2019-04-25 04:48:16 +08:00
|
|
|
const SUBSCRIPTIONS = [
|
2019-08-01 03:10:41 +08:00
|
|
|
'users', 'meetings', 'polls', 'presentations', 'slides', 'slide-positions', 'captions',
|
2019-04-25 04:48:16 +08:00
|
|
|
'voiceUsers', 'whiteboard-multi-user', 'screenshare', 'group-chat',
|
2019-09-09 22:29:59 +08:00
|
|
|
'presentation-pods', 'users-settings', 'guestUser', 'users-infos', 'note', 'meeting-time-remaining',
|
2021-06-13 23:36:43 +08:00
|
|
|
'local-settings', 'users-typing', 'record-meetings', 'video-streams',
|
2021-05-27 03:09:25 +08:00
|
|
|
'connection-status', 'voice-call-states', 'external-video-meetings',
|
2019-04-25 04:48:16 +08:00
|
|
|
];
|
|
|
|
|
2021-04-14 01:35:46 +08:00
|
|
|
const EVENT_NAME = 'bbb-group-chat-messages-subscription-has-stoppped';
|
2021-07-09 01:08:32 +08:00
|
|
|
const EVENT_NAME_SUBSCRIPTION_READY = 'bbb-group-chat-messages-subscriptions-ready';
|
2021-04-14 01:35:46 +08:00
|
|
|
|
2019-07-29 22:17:38 +08:00
|
|
|
class Subscriptions extends Component {
|
2019-04-25 04:48:16 +08:00
|
|
|
componentDidUpdate() {
|
|
|
|
const { subscriptionsReady } = this.props;
|
|
|
|
if (subscriptionsReady) {
|
|
|
|
Session.set('subscriptionsReady', true);
|
2021-07-09 01:08:32 +08:00
|
|
|
const event = new Event(EVENT_NAME_SUBSCRIPTION_READY);
|
|
|
|
window.dispatchEvent(event);
|
2019-04-25 04:48:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { children } = this.props;
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-20 04:33:32 +08:00
|
|
|
|
2019-04-25 04:48:16 +08:00
|
|
|
export default withTracker(() => {
|
|
|
|
const { credentials } = Auth;
|
|
|
|
const { meetingId, requesterUserId } = credentials;
|
2019-05-29 01:32:59 +08:00
|
|
|
if (Session.get('codeError')) {
|
|
|
|
return {
|
|
|
|
subscriptionsReady: true,
|
|
|
|
};
|
|
|
|
}
|
2019-07-02 03:00:27 +08:00
|
|
|
|
2020-06-05 21:32:05 +08:00
|
|
|
const currentUser = Users.findOne({ intId: requesterUserId }, { fields: { role: 1 } });
|
|
|
|
|
2019-04-25 04:48:16 +08:00
|
|
|
const subscriptionErrorHandler = {
|
|
|
|
onError: (error) => {
|
2019-06-29 05:45:50 +08:00
|
|
|
logger.error({
|
|
|
|
logCode: 'startup_client_subscription_error',
|
|
|
|
extraInfo: { error },
|
|
|
|
}, 'Error while subscribing to collections');
|
2019-04-25 04:48:16 +08:00
|
|
|
Session.set('codeError', error.error);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-07-18 05:00:33 +08:00
|
|
|
let subscriptionsHandlers = SUBSCRIPTIONS.map((name) => {
|
2019-08-23 23:51:10 +08:00
|
|
|
if ((!TYPING_INDICATOR_ENABLED && name.indexOf('typing') !== -1)
|
|
|
|
|| (!CHAT_ENABLED && name.indexOf('chat') !== -1)) return;
|
|
|
|
|
2020-06-05 21:32:05 +08:00
|
|
|
return Meteor.subscribe(name, subscriptionErrorHandler);
|
2019-07-18 05:00:33 +08:00
|
|
|
});
|
2019-04-25 04:48:16 +08:00
|
|
|
|
2020-06-05 21:32:05 +08:00
|
|
|
if (currentUser) {
|
|
|
|
subscriptionsHandlers.push(Meteor.subscribe('meetings', currentUser.role, subscriptionErrorHandler));
|
2021-09-11 03:44:27 +08:00
|
|
|
subscriptionsHandlers.push(Meteor.subscribe('users', currentUser.role, {
|
|
|
|
...subscriptionErrorHandler,
|
|
|
|
onStop: () => {
|
|
|
|
const event = new Event(EVENT_NAME);
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
},
|
|
|
|
}));
|
2020-06-05 21:32:05 +08:00
|
|
|
subscriptionsHandlers.push(Meteor.subscribe('breakouts', currentUser.role, subscriptionErrorHandler));
|
2021-08-04 23:34:52 +08:00
|
|
|
subscriptionsHandlers.push(Meteor.subscribe('guestUser', currentUser.role, subscriptionErrorHandler));
|
2020-06-05 21:32:05 +08:00
|
|
|
}
|
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
const annotationsHandler = Meteor.subscribe('annotations', {
|
2019-04-25 04:48:16 +08:00
|
|
|
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();
|
2019-04-25 04:48:16 +08:00
|
|
|
},
|
|
|
|
...subscriptionErrorHandler,
|
|
|
|
});
|
|
|
|
|
2019-07-18 05:00:33 +08:00
|
|
|
subscriptionsHandlers = subscriptionsHandlers.filter(obj => obj);
|
2019-04-25 04:48:16 +08:00
|
|
|
const ready = subscriptionsHandlers.every(handler => handler.ready());
|
2021-01-20 01:06:32 +08:00
|
|
|
let groupChatMessageHandler = {};
|
|
|
|
|
|
|
|
if (CHAT_ENABLED && ready) {
|
2021-12-02 01:47:08 +08:00
|
|
|
const chatsCount = GroupChat.find({
|
2021-01-20 01:06:32 +08:00
|
|
|
$or: [
|
|
|
|
{
|
|
|
|
meetingId,
|
|
|
|
access: PUBLIC_CHAT_TYPE,
|
|
|
|
chatId: { $ne: PUBLIC_GROUP_CHAT_ID },
|
|
|
|
},
|
|
|
|
{ meetingId, users: { $all: [requesterUserId] } },
|
|
|
|
],
|
2021-12-02 01:47:08 +08:00
|
|
|
}).count();
|
2021-04-14 01:35:46 +08:00
|
|
|
|
|
|
|
const subHandler = {
|
|
|
|
...subscriptionErrorHandler,
|
|
|
|
};
|
|
|
|
|
2021-12-02 01:47:08 +08:00
|
|
|
groupChatMessageHandler = Meteor.subscribe('group-chat-msg', chatsCount, subHandler);
|
2021-01-20 01:06:32 +08:00
|
|
|
}
|
2021-04-07 03:28:46 +08:00
|
|
|
|
|
|
|
// TODO: Refactor all the late subscribers
|
|
|
|
let usersPersistentDataHandler = {};
|
|
|
|
if (ready) {
|
2021-03-20 04:33:32 +08:00
|
|
|
usersPersistentDataHandler = Meteor.subscribe('users-persistent-data');
|
|
|
|
}
|
2019-04-25 04:48:16 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
subscriptionsReady: ready,
|
|
|
|
subscriptionsHandlers,
|
|
|
|
};
|
|
|
|
})(Subscriptions);
|