Fix audio and push alerts for user join

When validating tokens, the dummyUser created at the beginning is set
with validated=true. This means there won't be the state change that used
to occur from validated:false to validated:true (which detects the moment
joined the meeting) , therefore the alert code that expects for this change
won't run.
To fix this for audio alerts, we now detect when user join by observing
additions in Users's collection. This is actually good because we start
observing this only once (in componentDidMount), differently we used to do,
by calling this every time the tracker was activated.

To distinguish between the user addition that initially populates user's
collection from those that happens after user join (which are the ones we
want), we store the initial state (at componentDidMount) and compare it
with new additions. If the user added is present at the initial state,
then it is an addition to populates the collection, otherwise this is a real
user addition (happened after user joined the meeting)

Partially fixes #11399
This commit is contained in:
Mario Jr 2021-03-01 18:31:37 -03:00
parent 859520fe2c
commit 9c92c14a6e

View File

@ -77,6 +77,10 @@ class Base extends Component {
componentDidMount() {
const { animations } = this.props;
const {
userID: localUserId,
} = Auth;
if (animations) HTML.classList.add('animationsEnabled');
if (!animations) HTML.classList.add('animationsDisabled');
@ -84,6 +88,47 @@ class Base extends Component {
document.addEventListener(event, Base.handleFullscreenChange);
});
Session.set('isFullscreen', false);
const users = Users.find({
meetingId: Auth.meetingID,
validated: true,
userId: { $ne: localUserId },
}, { fields: { name: 1, userId: 1 } });
users.observeChanges({
changed: (id, userFields) => {
const subscriptionsReady = Session.get('subscriptionsReady');
if (!subscriptionsReady || !userFields.name) return;
const {
userJoinAudioAlerts,
userJoinPushAlerts,
} = Settings.application;
if (!userJoinAudioAlerts && !userJoinPushAlerts) return;
if (userJoinAudioAlerts) {
AudioService.playAlertSound(`${Meteor.settings.public.app.cdn
+ Meteor.settings.public.app.basename}`
+ '/resources/sounds/userJoin.mp3');
}
if (userJoinPushAlerts) {
notify(
<FormattedMessage
id="app.notification.userJoinPushAlert"
description="Notification for a user joins the meeting"
values={{
0: userFields.name,
}}
/>,
'info',
'user',
);
}
},
});
}
componentDidUpdate(prevProps, prevState) {
@ -224,14 +269,11 @@ const BaseContainer = withTracker(() => {
const {
locale,
animations,
userJoinAudioAlerts,
userJoinPushAlerts,
} = Settings.application;
const {
credentials,
loggedIn,
userID: localUserId,
} = Auth;
const { meetingId } = credentials;
@ -328,34 +370,6 @@ const BaseContainer = withTracker(() => {
},
});
if (userJoinAudioAlerts || userJoinPushAlerts) {
Users.find({}, { fields: { validated: 1, name: 1, userId: 1 } }).observe({
changed: (newDocument) => {
if (newDocument.validated && newDocument.name && newDocument.userId !== localUserId) {
if (userJoinAudioAlerts) {
AudioService.playAlertSound(`${Meteor.settings.public.app.cdn
+ Meteor.settings.public.app.basename}`
+ '/resources/sounds/userJoin.mp3');
}
if (userJoinPushAlerts) {
notify(
<FormattedMessage
id="app.notification.userJoinPushAlert"
description="Notification for a user joins the meeting"
values={{
0: newDocument.name,
}}
/>,
'info',
'user',
);
}
}
},
});
}
if (getFromUserSettings('bbb_show_participants_on_login', true) && !deviceInfo.type().isPhone) {
Session.set('openPanel', 'userlist');
if (CHAT_ENABLED && getFromUserSettings('bbb_show_public_chat_on_login', !Meteor.settings.public.chat.startClosed)) {