bigbluebutton-Github/bigbluebutton-html5/imports/api/voice-users/server/modifiers/updateVoiceUser.js
prlanzarin 001ab9554c video: added voice activity stream sorting, made stream sorting extensible
Video streams can be sorted by voice floor activity in the client according to FreeSWITCH´s floor events. The feature works together with pagination, essentially giving an Last-N like experience while not disrupting too much

Made video stream sorting extensible in a way. The sorting modes for pagination and unbounded can be configured in settings.yml and new sorting modes can be added to the stream sorting util under video-provider. Inline docs explain how to do that

Changed how the stream ID attribute from video-streams collection was passed to downstream components; we had an array map that was executed every change just to map stream to cameraId, which is bizarre. So I changed the cameraId usage in downstream components to be conformat with the collection attributes and shaved off the map where it wasnt needed

Add better selectors to video-list-item container´s VoiceUser fetch
2021-04-12 19:06:07 +00:00

89 lines
2.3 KiB
JavaScript

import { Match, check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import VoiceUsers from '/imports/api/voice-users';
import flat from 'flat';
import { spokeTimeoutHandles, clearSpokeTimeout } from '/imports/api/common/server/helpers';
const TALKING_TIMEOUT = 6000;
export default function updateVoiceUser(meetingId, voiceUser) {
check(meetingId, String);
check(voiceUser, {
intId: String,
voiceUserId: String,
talking: Match.Maybe(Boolean),
muted: Match.Maybe(Boolean),
voiceConf: String,
joined: Match.Maybe(Boolean),
floor: Match.Maybe(Boolean),
lastFloorTime: Match.Maybe(String),
});
const { intId } = voiceUser;
const selector = {
meetingId,
intId,
};
const modifier = {
$set: Object.assign(
flat(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.endTime = null;
clearSpokeTimeout(meetingId, intId);
}
if (!voiceUser.talking) {
const timeoutHandle = Meteor.setTimeout(() => {
const user = VoiceUsers.findOne({ meetingId, intId }, {
fields: {
endTime: 1,
talking: 1,
},
});
if (user) {
const { endTime, talking } = user;
const spokeDelay = ((Date.now() - endTime) < TALKING_TIMEOUT);
if (talking || spokeDelay) return;
modifier.$set.spoke = false;
modifier.$set.startTime = null;
try {
const numberAffected = VoiceUsers.update(selector, modifier);
if (numberAffected) {
Logger.debug('Update voiceUser', { voiceUser: intId, meetingId });
}
} catch (err) {
Logger.error(`Update voiceUser=${intId}: ${err}`);
}
}
}, TALKING_TIMEOUT);
spokeTimeoutHandles[`${meetingId}-${intId}`] = timeoutHandle;
modifier.$set.endTime = Date.now();
}
try {
const numberAffected = VoiceUsers.update(selector, modifier);
if (numberAffected) {
Logger.debug('Update voiceUser', { voiceUser: intId, meetingId });
}
} catch (err) {
Logger.error(`Update voiceUser=${intId}: ${err}`);
}
}