diff --git a/.eslintrc.js b/.eslintrc.js index 8e5d6c99..edb54415 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -87,7 +87,6 @@ module.exports = { layers: 'writable', settings: 'writable', meet: 'writable', - meetLowLevel: 'writable', meetHighLevel: 'writable', jitsiMeetJS: 'writable', zoneManager: 'writable', diff --git a/core/modules/meet/client/meet-low-level.js b/core/modules/meet/client/meet-low-level.js index 9e1871b1..0d04d218 100644 --- a/core/modules/meet/client/meet-low-level.js +++ b/core/modules/meet/client/meet-low-level.js @@ -125,26 +125,25 @@ const onUsersComeCloser = (e, template) => { if (jitsiMeetJS && !template.connection.get() && !meetLowLevel.connectionStarted) { meetLowLevel.connectionStarted = true - const roomName = users[0]?.profile?.meetRoomName - - if (!roomName) { - const usersIds = users.map((user) => user._id).concat(Meteor.userId()) - Meteor.call('computeMeetLowLevelRoomName', usersIds, (err, computedRoomName) => { - if (!computedRoomName) { - lp.notif.error('Unable to load a room, please try later') - return - } - meetLowLevel.roomName = computedRoomName - meetLowLevel.connect() - }) - } else { - meetLowLevel.roomName = roomName - Meteor.users.update(Meteor.userId(), { - $set: { 'profile.meetRoomName': roomName }, - }) - meetLowLevel.connect() - } + Meteor.call('getUserRoomName', users[0]._id, (err, roomName) => { + if (!roomName) { + const usersIds = users.map((user) => user._id).concat(Meteor.userId()) + Meteor.call('computeMeetLowLevelRoomName', usersIds, (err, computedRoomName) => { + if (!computedRoomName) { + lp.notif.error('Unable to load a room, please try later') + return + } + + meetLowLevel.roomName = computedRoomName + meetLowLevel.connect() + }) + } else { + meetLowLevel.roomName = roomName + Meteor.call('updateUserRoomName', roomName) + meetLowLevel.connect(roomName) + } + }) } users.forEach((user) => { @@ -277,7 +276,7 @@ const getOptions = () => ({ __end: true, }) -meetLowLevel = { +export const meetLowLevel = { connectionStarted: false, room: undefined, roomName: undefined, @@ -325,10 +324,7 @@ meetLowLevel = { async disconnect() { this.connectionStarted = false - Meteor.users.update(Meteor.userId(), { - $unset: { 'profile.meetRoomName': 1 }, - }) - + Meteor.call('updateUserRoomName', undefined) if (this.room?.room) { try { this.room.leave() diff --git a/core/modules/meet/client/tracks/utils.js b/core/modules/meet/client/tracks/utils.js index cb4c9c25..b75393a2 100644 --- a/core/modules/meet/client/tracks/utils.js +++ b/core/modules/meet/client/tracks/utils.js @@ -1,3 +1,5 @@ +import { meetLowLevel } from '../meet-low-level' + const updateTrackMuteState = (track, template) => { if (template.isMuted) { template.isMuted.set(track.isMuted()) diff --git a/core/modules/meet/server/meet.js b/core/modules/meet/server/meet.js index 310757a0..72f2b32a 100644 --- a/core/modules/meet/server/meet.js +++ b/core/modules/meet/server/meet.js @@ -50,6 +50,11 @@ const computeRoomToken = (user, roomName, moderator = false) => { ) } +const updateUserRoomName = (roomName) => { + const updateObject = roomName ? { $set: { 'meet.roomName': roomName } } : { $unset: { 'meet.roomName': 1 } } + Meteor.users.update(Meteor.userId(), updateObject) +} + Meteor.methods({ computeMeetRoomAccess(zoneId) { if (!this.userId) return undefined @@ -75,9 +80,26 @@ Meteor.methods({ return { roomName, token } }, + updateUserRoomName(roomName) { + check(roomName, Match.Maybe(String)) + const user = Meteor.user() + if (user.meet.roomName === roomName) return + + log('updateUserRoomName: start', { roomName }) + updateUserRoomName(roomName) + log('updateUserRoomName: end', { roomName }) + }, + getUserRoomName(userId) { + check(userId, Match.OneOf(null, Match.Id)) + const user = Meteor.users.findOne({ _id: userId || Meteor.userId() }, { fields: { 'meet.roomName': 1 } }) + if (!user) return + + log('getUserRoomName: start', { userId: userId }) + return user.meet?.roomName + log('getUserRoomName: end', { userId: userId }) + }, computeMeetLowLevelRoomName(usersIds) { if (!this.userId) return undefined - check(usersIds, Array) log('computeMeetLowLevelRoomName: start', { usersIds }) @@ -86,12 +108,9 @@ Meteor.methods({ .sort((a, b) => a.localeCompare(b)) .join('-') .toLowerCase() + updateUserRoomName(meetRoomName) - Meteor.users.update(Meteor.userId(), { - $set: { 'profile.meetRoomName': meetRoomName }, - }) - - log('computeMeetLowLevelRoomName: start', { meetRoomName }) + log('computeMeetLowLevelRoomName: end', { meetRoomName }) return meetRoomName }, diff --git a/core/server/accounts.js b/core/server/accounts.js index 9444c7b3..0d14654f 100644 --- a/core/server/accounts.js +++ b/core/server/accounts.js @@ -28,13 +28,8 @@ Accounts.validateNewUser(() => true) Accounts.onLogin((param) => { const user = Meteor.users.findOne(param.user._id) - if (user.profile.meetRoomName) { - Meteor.users.update(user._id, { - $unset: { - 'profile.meetRoomName': 1, - }, - }) - } + // We should be sure that user room name is reset on login + Meteor.call('updateUserRoomName', undefined) log('onLogin: start', { userId: user._id,