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';
|
2021-10-20 04:35:39 +08:00
|
|
|
import Users from '/imports/api/users';
|
2023-07-08 04:46:36 +08:00
|
|
|
import { localCollectionRegistry } from '/client/collection-mirror-initializer';
|
|
|
|
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
|
|
|
|
2024-03-07 01:28:18 +08:00
|
|
|
const CHAT_CONFIG = window.meetingClientSettings.public.chat;
|
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 = [
|
2024-02-23 23:01:53 +08:00
|
|
|
// 'users',
|
2024-03-26 19:57:28 +08:00
|
|
|
// 'meetings',
|
2024-04-20 03:27:01 +08:00
|
|
|
// 'captions',
|
2024-03-07 00:08:32 +08:00
|
|
|
// 'voiceUsers',
|
2023-07-08 04:46:36 +08:00
|
|
|
'screenshare',
|
|
|
|
'users-settings',
|
|
|
|
'users-infos',
|
|
|
|
'meeting-time-remaining',
|
2024-04-24 01:02:28 +08:00
|
|
|
// 'record-meetings',
|
2023-07-08 04:46:36 +08:00
|
|
|
'video-streams',
|
|
|
|
'voice-call-states',
|
2024-04-18 03:59:10 +08:00
|
|
|
// 'breakouts',
|
2024-04-19 00:16:44 +08:00
|
|
|
// 'breakouts-history',
|
2023-07-08 04:46:36 +08:00
|
|
|
'pads',
|
|
|
|
'pads-sessions',
|
|
|
|
'pads-updates',
|
2024-04-19 08:43:26 +08:00
|
|
|
// 'notifications',
|
2023-07-08 04:46:36 +08:00
|
|
|
'layout-meetings',
|
|
|
|
'user-reaction',
|
|
|
|
'timer',
|
2019-04-25 04:48:16 +08:00
|
|
|
];
|
2022-10-28 21:33:21 +08:00
|
|
|
const {
|
|
|
|
localBreakoutsSync,
|
|
|
|
localBreakoutsHistorySync,
|
|
|
|
localGuestUsersSync,
|
|
|
|
localMeetingsSync,
|
|
|
|
localUsersSync,
|
|
|
|
} = localCollectionRegistry;
|
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 {
|
2024-03-13 22:11:58 +08:00
|
|
|
componentDidMount() {
|
|
|
|
Session.set('subscriptionsReady', false);
|
|
|
|
}
|
|
|
|
|
2019-04-25 04:48:16 +08:00
|
|
|
componentDidUpdate() {
|
|
|
|
const { subscriptionsReady } = this.props;
|
2024-03-26 19:57:28 +08:00
|
|
|
const clientSettings = JSON.parse(sessionStorage.getItem('clientStartupSettings') || '{}')
|
|
|
|
console.log('clientSettings', clientSettings);
|
|
|
|
if (subscriptionsReady || clientSettings.skipMeteorConnection) {
|
2019-04-25 04:48:16 +08:00
|
|
|
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;
|
2024-03-13 22:11:58 +08:00
|
|
|
const { requesterUserId } = credentials;
|
2024-03-28 01:41:50 +08:00
|
|
|
const clientSettings = JSON.parse(sessionStorage.getItem('clientStartupSettings') || '{}');
|
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) => {
|
2023-07-08 04:46:36 +08:00
|
|
|
logger.error(
|
|
|
|
{
|
|
|
|
logCode: 'startup_client_subscription_error',
|
|
|
|
extraInfo: { error },
|
|
|
|
},
|
|
|
|
'Error while subscribing to collections'
|
|
|
|
);
|
2023-11-28 22:18:56 +08:00
|
|
|
console.log('-------------------------', {error});
|
2019-04-25 04:48:16 +08:00
|
|
|
Session.set('codeError', error.error);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-03-28 01:41:50 +08:00
|
|
|
const currentUser = Users.findOne({ userId: requesterUserId }, { fields: { role: 1 } });
|
2021-09-07 04:51:42 +08:00
|
|
|
|
2019-07-18 05:00:33 +08:00
|
|
|
let subscriptionsHandlers = SUBSCRIPTIONS.map((name) => {
|
2024-03-26 19:57:28 +08:00
|
|
|
if (clientSettings.skipMeteorConnection) return null;
|
2021-09-07 04:51:42 +08:00
|
|
|
let subscriptionHandlers = subscriptionErrorHandler;
|
2023-07-08 04:46:36 +08:00
|
|
|
if (
|
|
|
|
(!TYPING_INDICATOR_ENABLED && name.indexOf('typing') !== -1) ||
|
|
|
|
(!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
|
|
|
|
2023-07-08 04:46:36 +08:00
|
|
|
if (currentUser && oldRole !== currentUser?.role) {
|
2021-09-07 04:51:42 +08:00
|
|
|
// 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'),
|
2024-04-19 00:16:44 +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
|
|
|
}
|
|
|
|
|
2023-07-08 04:46:36 +08:00
|
|
|
subscriptionsHandlers = subscriptionsHandlers.filter((obj) => obj);
|
2024-03-26 19:57:28 +08:00
|
|
|
const ready = subscriptionsHandlers
|
|
|
|
.every((handler) => handler.ready() || clientSettings.skipMeteorConnection);
|
2021-04-07 03:28:46 +08:00
|
|
|
// TODO: Refactor all the late subscribers
|
|
|
|
if (ready) {
|
2023-07-08 04:46:36 +08:00
|
|
|
Object.values(localCollectionRegistry).forEach((localCollection) =>
|
|
|
|
localCollection.checkForStaleData()
|
2022-10-28 21:33:21 +08:00
|
|
|
);
|
2021-03-20 04:33:32 +08:00
|
|
|
}
|
2024-03-26 19:57:28 +08:00
|
|
|
|
2019-04-25 04:48:16 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
subscriptionsReady: ready,
|
|
|
|
subscriptionsHandlers,
|
|
|
|
};
|
|
|
|
})(Subscriptions);
|