Only sort frames when it's safe and pertinent

- Don't sort if a player is fullscreened. Fixes #12
- Force a sort when exiting fullscreen
- Only sort when the player list changes, not any resize
This commit is contained in:
Trysdyn Black 2025-03-18 23:24:45 -07:00
parent 2fab8e0664
commit c1aaac4923

View file

@ -9,6 +9,16 @@ xhr.onreadystatechange = function() {
disabledPlayers = []; disabledPlayers = [];
playerVolumeSettings = {}; playerVolumeSettings = {};
function webcallFrameSort() {
// If we're full screening a player this will break it, so don't
if (document.fullscreenElement) { return }
// Sort the players alphabetically by ID
Array.from(document.body.querySelectorAll(".frame"))
.sort((a, b) => a.id > b.id ? 1 : -1)
.forEach(node => document.body.appendChild(node))
}
// Auto-resize frames in a webcall interface // Auto-resize frames in a webcall interface
function webcallFrameResize() { function webcallFrameResize() {
// Figure out how many Frames are visible // Figure out how many Frames are visible
@ -57,11 +67,6 @@ function webcallFrameResize() {
element.style.width = w; element.style.width = w;
} }
) )
// Sort the players alphabetically by ID
Array.from(document.body.querySelectorAll(".frame"))
.sort((a, b) => a.id > b.id ? 1 : -1)
.forEach(node => document.body.appendChild(node))
} }
function createPlayer(stream, muted, volume) { function createPlayer(stream, muted, volume) {
@ -128,9 +133,10 @@ function createPlayer(stream, muted, volume) {
player.stateManager = manageState; player.stateManager = manageState;
player.on("stateChanged", player.stateManager); player.on("stateChanged", player.stateManager);
// Run a resize // Run a resize and sort
if (named_frames) { if (named_frames) {
webcallFrameResize(); webcallFrameResize();
webcallFrameSort();
} }
} }
@ -163,9 +169,10 @@ function destroyPlayerById(containerId) {
// Delete frame // Delete frame
document.getElementById(`frame_${containerId}`).remove(); document.getElementById(`frame_${containerId}`).remove();
// Run our resize // Run our resize and sort
if (named_frames) { if (named_frames) {
webcallFrameResize(); webcallFrameResize();
webcallFrameSort();
} }
} }
@ -232,6 +239,10 @@ function EmprexSetup() {
resize_timeout = setTimeout(webcallFrameResize, 250); resize_timeout = setTimeout(webcallFrameResize, 250);
}) })
// If we enter or exit full screen, call the webcall frame sort
// The sort will refuse to run if we're in full screen. So we need to sort once we leave it
addEventListener("fullscreenchange", webcallFrameSort);
// Update streams every 5 seconds, and immediately // Update streams every 5 seconds, and immediately
requestStreamList(); requestStreamList();
setInterval(requestStreamList, 5000); setInterval(requestStreamList, 5000);