Split App into Header and Stream

This commit is contained in:
Leon Grünewald 2024-07-29 22:06:04 +02:00
parent 8c39f7e5d0
commit 136a6a7f90
3 changed files with 60 additions and 36 deletions

View file

@ -1,5 +1,8 @@
<script> <script>
import { onMount } from "svelte"; import { onMount } from "svelte";
import Header from "./lib/Header.svelte";
import Stream from "./lib/Stream.svelte";
let streams = []; let streams = [];
let fracsX = 0; let fracsX = 0;
let fracsY = 0; let fracsY = 0;
@ -8,39 +11,23 @@
onMount(() => { onMount(() => {
streams = new URLSearchParams(window.location.search).getAll("streams"); streams = new URLSearchParams(window.location.search).getAll("streams");
fracsX = Math.max(Math.ceil(streams.length / 2), 2);
fracsY = Math.max(Math.ceil(streams.length / 2), 2);
if (streams.length === 1) { if (streams.length === 1) {
fracsX = 1;
fracsY = 1; fracsY = 1;
fracsX = 1;
} else if (streams.length === 2) { } else if (streams.length === 2) {
fracsY = Math.max(Math.ceil(streams.length / 2), 2);
fracsX = 1; fracsX = 1;
fracsY = Math.max(Math.ceil(streams.length / 2), 2);
} else { } else {
fracsX = Math.max(Math.ceil(streams.length / 2), 2); fracsX = Math.max(Math.ceil(streams.length / 2), 2);
fracsY = Math.max(Math.ceil(streams.length / 2), 2);
} }
}); });
</script> </script>
<main> <main>
<div class="buttons"> {#if containerElement}
<button <Header {containerElement} />
on:click={() => { {/if}
showButtons = !showButtons;
}}>[{showButtons ? "x" : " "}]</button
>
{#if showButtons}
<button
on:click={() => {
if (containerElement) {
containerElement.requestFullscreen();
}
}}>Fullscreen</button
>
<!--<button>Placeholder</button>-->
{/if}
</div>
<div <div
bind:this={containerElement} bind:this={containerElement}
class="streams" class="streams"
@ -52,29 +39,16 @@
> >
{#if streams} {#if streams}
{#each streams as stream} {#each streams as stream}
<iframe title={stream} src={"https://vdo.ninja/?view=" + stream} <Stream {stream} />
></iframe>
{/each} {/each}
{/if} {/if}
</div> </div>
</main> </main>
<style> <style>
.buttons {
display: flex;
position: absolute;
top: 0;
left: 0;
}
.streams { .streams {
display: grid; display: grid;
height: 100vh; height: 100vh;
width: 100vw; width: 100vw;
} }
iframe {
width: 100%;
height: 100%;
}
</style> </style>

30
src/lib/Header.svelte Normal file
View file

@ -0,0 +1,30 @@
<script>
let showButtons = false;
export let containerElement = null;
</script>
<header>
<button
on:click={() => {
showButtons = !showButtons;
}}>[{showButtons ? "<" : ">"}]</button
>
{#if showButtons}
<button
on:click={() => {
if (containerElement) containerElement.requestFullscreen();
}}>Fullscreen</button
>
<!--<button>Placeholder</button>-->
{/if}
</header>
<style>
header {
width: 100vw;
display: flex;
position: absolute;
top: 0;
left: 0;
}
</style>

20
src/lib/Stream.svelte Normal file
View file

@ -0,0 +1,20 @@
<script>
export let stream;
</script>
<div class="stream-container">
<iframe title={stream} src={"https://vdo.ninja/?vol=0&view=" + stream}
></iframe>
</div>
<style>
.stream-container {
width: 100%;
height: 100%;
}
iframe {
width: 100%;
height: 100%;
}
</style>