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 Users from '/imports/api/users';
|
|
|
|
import Annotations from '/imports/api/annotations';
|
|
|
|
import AnnotationsTextService from '/imports/ui/components/whiteboard/annotations/text/service';
|
2019-10-23 09:26:25 +08:00
|
|
|
import AnnotationsLocal, { initAnnotationsStreamListener } from '/imports/ui/components/whiteboard/service';
|
2019-10-25 04:48:03 +08:00
|
|
|
import { initCursorStreamListener } from '/imports/ui/components/cursor/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-08-22 20:05:06 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
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',
|
2019-09-07 00:50:31 +08:00
|
|
|
'network-information', 'ping-pong', 'local-settings', 'users-typing', 'record-meetings', 'video-streams',
|
2019-04-25 04:48:16 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { children } = this.props;
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
2019-07-18 05:00:33 +08:00
|
|
|
return Meteor.subscribe(
|
|
|
|
name,
|
|
|
|
credentials,
|
|
|
|
subscriptionErrorHandler,
|
|
|
|
);
|
|
|
|
});
|
2019-04-25 04:48:16 +08:00
|
|
|
|
|
|
|
let groupChatMessageHandler = {};
|
2019-05-07 04:32:45 +08:00
|
|
|
// let annotationsHandler = {};
|
2019-04-25 04:48:16 +08:00
|
|
|
|
2019-07-18 05:00:33 +08:00
|
|
|
if (CHAT_ENABLED) {
|
|
|
|
const chats = GroupChat.find({
|
|
|
|
$or: [
|
|
|
|
{
|
|
|
|
meetingId,
|
|
|
|
access: PUBLIC_CHAT_TYPE,
|
|
|
|
chatId: { $ne: PUBLIC_GROUP_CHAT_ID },
|
|
|
|
},
|
|
|
|
{ meetingId, users: { $all: [requesterUserId] } },
|
|
|
|
],
|
|
|
|
}).fetch();
|
|
|
|
|
|
|
|
const chatIds = chats.map(chat => chat.chatId);
|
|
|
|
|
|
|
|
groupChatMessageHandler = Meteor.subscribe('group-chat-msg', credentials, chatIds, subscriptionErrorHandler);
|
|
|
|
subscriptionsHandlers.push(groupChatMessageHandler);
|
|
|
|
}
|
2019-04-25 04:48:16 +08:00
|
|
|
|
2019-08-30 00:26:07 +08:00
|
|
|
const User = Users.findOne({ intId: requesterUserId }, { fields: { role: 1 } });
|
2019-04-25 04:48:16 +08:00
|
|
|
|
|
|
|
if (User) {
|
2019-08-22 20:05:06 +08:00
|
|
|
const userIsModerator = User.role === ROLE_MODERATOR;
|
|
|
|
Meteor.subscribe('users', credentials, userIsModerator, subscriptionErrorHandler);
|
|
|
|
Meteor.subscribe('breakouts', credentials, userIsModerator, subscriptionErrorHandler);
|
|
|
|
Meteor.subscribe('meetings', credentials, userIsModerator, subscriptionErrorHandler);
|
2019-12-04 23:42:41 +08:00
|
|
|
logger.debug({ logCode: 'startup_client_subscription_init_streamers', extraInfo: { role: User.role } }, 'Calling init streamers functions');
|
2019-10-25 02:03:05 +08:00
|
|
|
initAnnotationsStreamListener();
|
2019-10-25 04:48:03 +08:00
|
|
|
initCursorStreamListener();
|
2019-04-25 04:48:16 +08:00
|
|
|
}
|
|
|
|
|
2019-05-07 04:32:45 +08:00
|
|
|
const annotationsHandler = Meteor.subscribe('annotations', credentials, {
|
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());
|
|
|
|
|
|
|
|
return {
|
|
|
|
subscriptionsReady: ready,
|
|
|
|
subscriptionsHandlers,
|
|
|
|
};
|
|
|
|
})(Subscriptions);
|