From d5c80fc0603918579c081819ab2d727d693fc07d Mon Sep 17 00:00:00 2001 From: Bohdan Zhemelinskyi Date: Thu, 4 Nov 2021 15:16:47 +0000 Subject: [PATCH] Improvement based on comments --- .../server/modifiers/updateRandomViewer.js | 131 +++++++++++------- .../modal/random-user/component.jsx | 12 +- .../modal/random-user/container.jsx | 60 ++++---- 3 files changed, 122 insertions(+), 81 deletions(-) diff --git a/bigbluebutton-html5/imports/api/meetings/server/modifiers/updateRandomViewer.js b/bigbluebutton-html5/imports/api/meetings/server/modifiers/updateRandomViewer.js index 1c74e037d9..5fba33692d 100644 --- a/bigbluebutton-html5/imports/api/meetings/server/modifiers/updateRandomViewer.js +++ b/bigbluebutton-html5/imports/api/meetings/server/modifiers/updateRandomViewer.js @@ -2,22 +2,20 @@ import Meetings from '/imports/api/meetings'; import Logger from '/imports/startup/server/logger'; import { check } from 'meteor/check'; -const SELECT_RANDOM_USER_ENABLED = Meteor.settings.public.selectRandomUser.enabled; - const SELECT_RANDOM_USER_COUNTDOWN = Meteor.settings.public.selectRandomUser.countdown; -//Time intervals in milliseconds -//for iteration in animation +// Time intervals in milliseconds +// for iteration in animation. let intervals = [0, 200, 450, 750, 1100, 1500]; -//Used to togle to the first value of intervals to -//differenciare whether this function has been called +// Used to togle to the first value of intervals to +// differenciare whether this function has been called let updateIndicator = true; -//A finction that toggles -//the first interval on each call -function toggleIndicator(){ - if(updateIndicator){ +// A finction that toggles +// the first interval on each call +function toggleIndicator() { + if (updateIndicator) { intervals[0] = 1; } else { intervals[0] = 0; @@ -25,15 +23,33 @@ function toggleIndicator(){ updateIndicator = !updateIndicator; } -//All possible combinations of 3 elements -//to to speed up randomizing -const optionsFor3 = [ +function getFiveRandom(userList, userIds) { + let IDs = userIds.slice(); + for (let i = 0; i < intervals.length - 1; i++) { + if (IDs.length === 0) { // we used up all the options + IDs = userIds.slice(); // start over + let userId = IDs.splice(0, 1); + if (userList[userList.length] === [userId, intervals[i]]) { // If we start over with the one we finnished, change it + IDs.push(userId); + userId = IDs.splice(0, 1); + } + userList.push([userId, intervals[i]]); + } else { + const userId = IDs.splice(Math.floor(Math.random() * IDs.length), 1); + userList.push([userId, intervals[i]]); + } + } +} + +// All possible combinations of 3 elements +// to speed up randomizing +const optionsFor3 = [ [0, 1, 2], [0, 2, 1], [1, 2, 0], [1, 0, 2], [2, 0, 1], - [2, 1, 0] + [2, 1, 0], ]; export default function updateRandomUser(meetingId, userIds, choice, requesterId) { @@ -55,29 +71,60 @@ export default function updateRandomUser(meetingId, userIds, choice, requesterId const chosenUser = userIds[choice]; if (choice < 0) { // no viewer - userList = [[requesterId,intervals[0]], [requesterId,0], [requesterId,0], [requesterId,0], [requesterId,0], [requesterId,0]]; - } - - else if (numberOfUsers == 1) { //If user is only one, obviously it is the chosen one - userList = [[userIds[0],intervals[0]], [userIds[0],0], [userIds[0],0], [userIds[0],0], [userIds[0],0], [userIds[0],0]]; - } - - else if(!SELECT_RANDOM_USER_COUNTDOWN) { //If animation is disabled, we only care about the chosen one - userList = [[chosenUser,intervals[0]], [chosenUser,0], [chosenUser,0], [chosenUser,0], [chosenUser,0], [chosenUser,0]]; - } - - else if(numberOfUsers == 2){ // If there are only two users, we can just chow them in turns + userList = [ + [requesterId, intervals[0]], + [requesterId, 0], + [requesterId, 0], + [requesterId, 0], + [requesterId, 0], + [requesterId, 0], + ]; + } else if (numberOfUsers === 1) { // If user is only one, obviously it is the chosen one + userList = [ + [userIds[0], intervals[0]], + [userIds[0], 0], + [userIds[0], 0], + [userIds[0], 0], + [userIds[0], 0], + [userIds[0], 0], + ]; + } + + else if (!SELECT_RANDOM_USER_COUNTDOWN) { // If animation is disabled, we only care about the chosen one + userList = [ + [chosenUser, intervals[0]], + [chosenUser, 0], + [chosenUser, 0], + [chosenUser, 0], + [chosenUser, 0], + [chosenUser, 0], + ]; + } + + else if (numberOfUsers === 2) { // If there are only two users, we can just chow them in turns const IDs = userIds.slice(); IDs.splice(choice, 1); - userList = [[IDs[0],intervals[0]], [chosenUser,intervals[1]], [IDs[0],intervals[2]], [chosenUser,intervals[3]], [IDs[0],intervals[4]], [chosenUser,intervals[5]]]; - } - - else if(numberOfUsers == 3){ //If there are 3 users, the number of combinations is small, so we'll use that + userList = [ + [IDs[0], intervals[0]], + [chosenUser, intervals[1]], + [IDs[0], intervals[2]], + [chosenUser, intervals[3]], + [IDs[0], intervals[4]], + [chosenUser, intervals[5]], + ]; + } else if (numberOfUsers === 3) { // If there are 3 users, the number of combinations is small, so we'll use that const option = Math.floor(Math.random() * 6); const order = optionsFor3[option]; - userList = [[userIds[order[0]],intervals[0]], [userIds[order[1]],intervals[1]], [userIds[order[2]],intervals[2]], [userIds[order[0]],intervals[3]], [userIds[order[1]],intervals[4]], [chosenUser,intervals[5]]]; - } - + userList = [ + [userIds[order[0]], intervals[0]], + [userIds[order[1]], intervals[1]], + [userIds[order[2]], intervals[2]], + [userIds[order[0]], intervals[3]], + [userIds[order[1]], intervals[4]], + [chosenUser, intervals[5]], + ]; + } + else { // We generate 5 users randomly, just for animation, and last one is the chosen one getFiveRandom(userList, userIds); userList.push([chosenUser, intervals[intervals.length]]); @@ -98,21 +145,3 @@ export default function updateRandomUser(meetingId, userIds, choice, requesterId Logger.error(`Setting randomly selected userId and interval = ${userList} by requesterId=${requesterId} in meetingId=${meetingId}`); } } - -function getFiveRandom(userList, userIds){ - let IDs = userIds.slice(); - for(let i = 0; i < intervals.length - 1; i++ ){ - if(IDs == 0) { // we used up all the options - IDs = userIds.slice(); //start over - let userId = IDs.splice(0, 1); - if(userList[userList.length] == [userId, intervals[i]]){ //If we start over with the one we finnished, change it - IDs.push(userId); - userId = IDs.splice(0, 1) - } - userList.push([userId, intervals[i]]); - } else { - const userId = IDs.splice(Math.floor(Math.random() * IDs.length), 1); - userList.push([userId, intervals[i]]); - } - } -} diff --git a/bigbluebutton-html5/imports/ui/components/modal/random-user/component.jsx b/bigbluebutton-html5/imports/ui/components/modal/random-user/component.jsx index 461fb1e429..b90c48c037 100644 --- a/bigbluebutton-html5/imports/ui/components/modal/random-user/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/modal/random-user/component.jsx @@ -56,7 +56,7 @@ class RandomUserSelect extends Component { props.randomUserReq(); } - if(SELECT_RANDOM_USER_COUNTDOWN) { + if (SELECT_RANDOM_USER_COUNTDOWN) { this.state = { count: 0, }; @@ -86,8 +86,8 @@ class RandomUserSelect extends Component { } componentDidUpdate(prevProps, prevState) { - if(SELECT_RANDOM_USER_COUNTDOWN) { - if (this.props.currentUser.presenter && this.state.count == 0) { + if (SELECT_RANDOM_USER_COUNTDOWN) { + if (this.props.currentUser.presenter && this.state.count === 0) { this.iterateSelection(); } @@ -105,7 +105,7 @@ class RandomUserSelect extends Component { } reselect() { - if(SELECT_RANDOM_USER_COUNTDOWN) { + if (SELECT_RANDOM_USER_COUNTDOWN) { this.setState({ count: 0, }); @@ -169,7 +169,7 @@ class RandomUserSelect extends Component { {selectedUser.name} {currentUser.presenter - && countDown == 0 + && countDown === 0 && (