Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Hide meetLowLevel client side and put roomName outside user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
alimtunc committed Jul 5, 2023
1 parent 478609b commit c59b043
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ module.exports = {
layers: 'writable',
settings: 'writable',
meet: 'writable',
meetLowLevel: 'writable',
meetHighLevel: 'writable',
jitsiMeetJS: 'writable',
zoneManager: 'writable',
Expand Down
44 changes: 20 additions & 24 deletions core/modules/meet/client/meet-low-level.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,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) => {
Expand Down Expand Up @@ -276,7 +275,7 @@ const getOptions = () => ({
__end: true,
})

meetLowLevel = {
export const meetLowLevel = {
connectionStarted: false,
room: undefined,
roomName: undefined,
Expand Down Expand Up @@ -324,10 +323,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()
Expand Down
2 changes: 2 additions & 0 deletions core/modules/meet/client/tracks/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { meetLowLevel } from '../meet-low-level'

const updateTrackMuteState = (track, template) => {
if (template.isMuted) {
template.isMuted.set(track.isMuted())
Expand Down
31 changes: 25 additions & 6 deletions core/modules/meet/server/meet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 })
Expand All @@ -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
},
Expand Down
9 changes: 2 additions & 7 deletions core/server/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c59b043

Please sign in to comment.