Load-test: emulate jitsi-meet stage view behavior, if selected. (#8957)

This commit is contained in:
Jonathan Lennox 2021-04-06 16:31:26 -04:00 committed by GitHub
parent fc3a743372
commit 31c0ba4481
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 74 additions and 12 deletions

View File

@ -14,6 +14,7 @@ const {
remoteVideo = isHuman,
remoteAudio = isHuman,
autoPlayVideo = config.testing.noAutoPlayVideo !== true,
stageView = config.disableTileView
} = params;
let {
@ -35,6 +36,8 @@ const remoteTracks = {};
let maxFrameHeight = 0;
let selectedParticipant = null;
window.APP = {
conference: {
getStats() {
@ -85,7 +88,8 @@ window.APP = {
localVideo,
remoteVideo,
remoteAudio,
autoPlayVideo
autoPlayVideo,
stageView
};
}
};
@ -100,12 +104,17 @@ function updateMaxFrameHeight() {
let newMaxFrameHeight;
if (numParticipants <= 2) {
newMaxFrameHeight = 720;
} else if (numParticipants <= 4) {
newMaxFrameHeight = 360;
} else {
newMaxFrameHeight = 180;
if (stageView) {
newMaxFrameHeight = 2160;
}
else {
if (numParticipants <= 2) {
newMaxFrameHeight = 720;
} else if (numParticipants <= 4) {
newMaxFrameHeight = 360;
} else {
newMaxFrameHeight = 180;
}
}
if (room && maxFrameHeight !== newMaxFrameHeight) {
@ -137,6 +146,36 @@ function updateLastN() {
room.setLastN(lastN);
}
/**
* Helper function to query whether a participant ID is a valid ID
* for stage view.
*/
function isValidStageViewParticipant(id) {
return (id !== room.myUserId() && room.getParticipantById(id));
}
/**
* Simple emulation of jitsi-meet's stage view participant selection behavior.
* Doesn't take into account pinning or screen sharing, and the initial behavior
* is slightly different.
* @returns Whether the selected participant changed.
*/
function selectStageViewParticipant(selected, previous) {
let newSelectedParticipant;
if (isValidStageViewParticipant(selected)) {
newSelectedParticipant = selected;
}
else {
newSelectedParticipant = previous.find(isValidStageViewParticipant);
}
if (newSelectedParticipant && newSelectedParticipant !== selectedParticipant) {
selectedParticipant = newSelectedParticipant;
return true;
}
return false;
}
/**
* Simple emulation of jitsi-meet's selectParticipants behavior
*/
@ -144,9 +183,16 @@ function selectParticipants() {
if (!connected) {
return;
}
/* jitsi-meet's current Tile View behavior. */
const ids = room.getParticipants().map(participant => participant.getId());
room.selectParticipants(ids);
if (stageView) {
if (selectedParticipant) {
room.selectParticipants([selectedParticipant]);
}
}
else {
/* jitsi-meet's current Tile View behavior. */
const ids = room.getParticipants().map(participant => participant.getId());
room.selectParticipants(ids);
}
}
/**
@ -154,8 +200,10 @@ function selectParticipants() {
*/
function setNumberOfParticipants() {
$('#participants').text(numParticipants);
selectParticipants();
updateMaxFrameHeight();
if (!stageView) {
selectParticipants();
updateMaxFrameHeight();
}
updateLastN();
}
@ -170,6 +218,17 @@ function onConnectionEstablished() {
updateLastN();
}
/**
* Handles dominant speaker changed.
* @param id
*/
function onDominantSpeakerChanged(selected, previous) {
if (selectStageViewParticipant(selected, previous)) {
selectParticipants();
}
updateMaxFrameHeight();
}
/**
* Handles local tracks.
* @param tracks Array with JitsiTrack objects
@ -292,6 +351,9 @@ function onConnectionSuccess() {
room.on(JitsiMeetJS.events.conference.CONNECTION_ESTABLISHED, onConnectionEstablished);
room.on(JitsiMeetJS.events.conference.USER_JOINED, onUserJoined);
room.on(JitsiMeetJS.events.conference.USER_LEFT, onUserLeft);
if (stageView) {
room.on(JitsiMeetJS.events.conference.DOMINANT_SPEAKER_CHANGED, onDominantSpeakerChanged);
}
const devices = [];