sort talking users by start time

This commit is contained in:
KDSBrowne 2019-11-20 15:08:36 +00:00
parent 4ccec9203f
commit 2fb55a9325
3 changed files with 25 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import VoiceUsers from '/imports/api/voice-users';
import flat from 'flat';
import { spokeTimeoutHandles, clearSpokeTimeout } from '/imports/api/common/server/helpers';
const TALKING_TIMEOUT = 3000;
const TALKING_TIMEOUT = 6000;
export default function updateVoiceUser(meetingId, voiceUser) {
check(meetingId, String);
@ -31,8 +31,14 @@ export default function updateVoiceUser(meetingId, voiceUser) {
};
if (voiceUser.talking) {
const user = VoiceUsers.findOne({ meetingId, intId }, {
fields: {
startTime: 1,
},
});
if (user && !user.startTime) modifier.$set.startTime = Date.now();
modifier.$set.spoke = true;
modifier.$set.startTime = Date.now();
modifier.$set.endTime = null;
clearSpokeTimeout(meetingId, intId);
}
@ -59,6 +65,7 @@ export default function updateVoiceUser(meetingId, voiceUser) {
const spokeDelay = ((Date.now() - endTime) < TALKING_TIMEOUT);
if (talking || spokeDelay) return;
modifier.$set.spoke = false;
modifier.$set.startTime = null;
VoiceUsers.update(selector, modifier, cb);
}
}, TALKING_TIMEOUT);

View File

@ -4,6 +4,7 @@ import VoiceUsers from '/imports/api/voice-users';
import Auth from '/imports/ui/services/auth';
import TalkingIndicator from './component';
import { makeCall } from '/imports/ui/services/api';
import Service from './service';
const APP_CONFIG = Meteor.settings.public.app;
const { enableTalkingIndicator } = APP_CONFIG;
@ -25,7 +26,7 @@ export default withTracker(() => {
voiceUserId: 1,
muted: 1,
},
}).fetch();
}).fetch().sort(Service.sortVoiceUsers);
if (usersTalking) {
for (let i = 0; i < usersTalking.length; i += 1) {

View File

@ -0,0 +1,14 @@
const sortByStartTime = (a, b) => {
if (a.startTime < b.startTime) return -1;
if (a.startTime > b.startTime) return 1;
return 0;
};
const sortVoiceUsers = (a, b) => {
const sort = sortByStartTime(a, b);
return sort;
};
export default {
sortVoiceUsers,
};