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';
|
2021-10-20 04:35:39 +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';
|
2021-10-20 04:35:39 +08:00
|
|
|
import {
|
|
|
|
localBreakoutsSync,
|
2021-11-20 03:34:37 +08:00
|
|
|
localBreakoutsHistorySync,
|
2021-10-20 04:35:39 +08:00
|
|
|
localGuestUsersSync,
|
|
|
|
localMeetingsSync,
|
|
|
|
localUsersSync,
|
2021-11-17 20:01:41 +08:00
|
|
|
} from '/client/collection-mirror-initializer';
|
2021-09-07 04:51:42 +08:00
|
|
|
import SubscriptionRegistry, { subscriptionReactivity } from '../../services/subscription-registry/subscriptionRegistry';
|
2022-03-09 22:19:25 +08:00
|
|
|
import { isChatEnabled } from '/imports/ui/services/features';
|
2019-08-23 23:17:32 +08:00
|
|
|
|
2019-04-25 04:48:16 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
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',
|
2021-10-16 03:07:13 +08:00
|
|
|
'presentation-pods', 'users-settings', 'guestUser', 'users-infos', 'meeting-time-remaining',
|
2021-06-13 23:36:43 +08:00
|
|
|
'local-settings', 'users-typing', 'record-meetings', 'video-streams',
|
2021-11-11 21:10:31 +08:00
|
|
|
'connection-status', 'voice-call-states', 'external-video-meetings', 'breakouts', 'breakouts-history',
|
2022-03-25 03:05:20 +08:00
|
|
|
'pads', 'pads-sessions', 'pads-updates', 'notifications', 'audio-captions',
|
2022-01-21 01:50:16 +08:00
|
|
|
'layout-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
|
|
|
|
2021-09-07 04:51:42 +08:00
|
|
|
let oldRole = '';
|
|
|
|
|
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);
|
2021-10-20 04:35:39 +08:00
|
|
|
Session.set('globalIgnoreDeletes', false);
|
2019-04-25 04:48:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { children } = this.props;
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withTracker(() => {
|
|
|
|
const { credentials } = Auth;
|
|
|
|
const { meetingId, requesterUserId } = credentials;
|
2021-10-20 04:35:39 +08:00
|
|
|
const userWillAuth = Session.get('userWillAuth');
|
|
|
|
// This if exist because when a unauth user try to subscribe to a publisher
|
|
|
|
// it returns a empty collection to the subscription
|
|
|
|
// and not rerun when the user is authenticated
|
|
|
|
if (userWillAuth) return {};
|
|
|
|
|
2019-05-29 01:32:59 +08:00
|
|
|
if (Session.get('codeError')) {
|
|
|
|
return {
|
|
|
|
subscriptionsReady: true,
|
|
|
|
};
|
|
|
|
}
|
2019-07-02 03:00:27 +08:00
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-09-07 04:51:42 +08:00
|
|
|
const currentUser = Users.findOne({ intId: requesterUserId }, { fields: { role: 1 } });
|
|
|
|
|
2019-07-18 05:00:33 +08:00
|
|
|
let subscriptionsHandlers = SUBSCRIPTIONS.map((name) => {
|
2021-09-07 04:51:42 +08:00
|
|
|
let subscriptionHandlers = subscriptionErrorHandler;
|
2019-08-23 23:51:10 +08:00
|
|
|
if ((!TYPING_INDICATOR_ENABLED && name.indexOf('typing') !== -1)
|
2022-03-09 22:19:25 +08:00
|
|
|
|| (!isChatEnabled() && name.indexOf('chat') !== -1)) return null;
|
2021-09-07 04:51:42 +08:00
|
|
|
|
|
|
|
if (name === 'users') {
|
|
|
|
subscriptionHandlers = {
|
|
|
|
...subscriptionHandlers,
|
|
|
|
onStop: () => {
|
|
|
|
const event = new Event(EVENT_NAME);
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2019-08-23 23:51:10 +08:00
|
|
|
|
2021-09-07 04:51:42 +08:00
|
|
|
return SubscriptionRegistry.createSubscription(name, subscriptionHandlers);
|
2019-07-18 05:00:33 +08:00
|
|
|
});
|
2019-04-25 04:48:16 +08:00
|
|
|
|
2021-09-07 04:51:42 +08:00
|
|
|
if (currentUser && (oldRole !== currentUser?.role)) {
|
|
|
|
// stop subscription from the client-side as the server-side only watch moderators
|
|
|
|
if (oldRole === 'VIEWER' && currentUser?.role === 'MODERATOR') {
|
|
|
|
// let this withTracker re-execute when a subscription is stopped
|
|
|
|
subscriptionReactivity.depend();
|
|
|
|
localBreakoutsSync.setIgnoreDeletes(true);
|
2021-11-20 03:34:37 +08:00
|
|
|
localBreakoutsHistorySync.setIgnoreDeletes(true);
|
2021-09-07 04:51:42 +08:00
|
|
|
localGuestUsersSync.setIgnoreDeletes(true);
|
|
|
|
localMeetingsSync.setIgnoreDeletes(true);
|
|
|
|
localUsersSync.setIgnoreDeletes(true);
|
2021-10-20 04:35:39 +08:00
|
|
|
// Prevent data being removed by subscription stop
|
2021-09-07 04:51:42 +08:00
|
|
|
// stop role dependent subscriptions
|
|
|
|
[
|
|
|
|
SubscriptionRegistry.getSubscription('meetings'),
|
|
|
|
SubscriptionRegistry.getSubscription('users'),
|
|
|
|
SubscriptionRegistry.getSubscription('breakouts'),
|
2021-11-11 21:10:31 +08:00
|
|
|
SubscriptionRegistry.getSubscription('breakouts-history'),
|
2021-09-07 04:51:42 +08:00
|
|
|
SubscriptionRegistry.getSubscription('guestUser'),
|
|
|
|
].forEach((item) => {
|
|
|
|
if (item) item.stop();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
oldRole = currentUser?.role;
|
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 = {};
|
|
|
|
|
2022-03-09 22:19:25 +08:00
|
|
|
if (isChatEnabled() && 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);
|