Skip to content

Commit

Permalink
detach player when resized away to conserve bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
schlawg committed Mar 16, 2024
1 parent 56dbc1b commit ea2d2ad
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions ui/analyse/src/study/relay/videoPlayerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ export function renderVideoPlayer(relay: RelayCtrl): VNode | undefined {
}

export function onWindowResize(redraw: Redraw) {
let cols = 0;
let showingVideo = false;
window.addEventListener(
'resize',
() => {
player?.cover(document.getElementById('video-player-placeholder') ?? undefined);
const newCols = Number(window.getComputedStyle(document.body).getPropertyValue('--cols'));
if (newCols === cols) return;
cols = newCols;
const allow = window.getComputedStyle(document.body).getPropertyValue('--allow-video') === 'true';
const placeholder = document.getElementById('video-player-placeholder') ?? undefined;
player?.cover(allow ? placeholder : undefined);
if (showingVideo === allow && !!placeholder) return;
showingVideo = allow && !!placeholder;
redraw();
},
{ passive: true },
Expand All @@ -47,18 +48,12 @@ class VideoPlayer {
if (document.body.contains(this.iframe)) document.body.removeChild(this.iframe);
return;
}
const placement = {
left: el.offsetLeft,
top: el.offsetTop,
width: el.offsetWidth,
height: el.offsetHeight,
};
this.animationFrameId = requestAnimationFrame(() => {
this.iframe.style.display = 'block';
this.iframe.style.left = `${placement.left}px`;
this.iframe.style.top = `${placement.top}px`;
this.iframe.style.width = `${placement.width}px`;
this.iframe.style.height = `${placement.height}px`;
this.iframe.style.left = `${el!.offsetLeft}px`;
this.iframe.style.top = `${el!.offsetTop}px`;
this.iframe.style.width = `${el!.offsetWidth}px`;
this.iframe.style.height = `${el!.offsetHeight}px`;
if (!document.body.contains(this.iframe)) document.body.appendChild(this.iframe);
});
}
Expand Down

0 comments on commit ea2d2ad

Please sign in to comment.