Add twitch support

This commit is contained in:
Leon Grünewald 2024-08-04 15:48:28 +02:00
parent 89339aa5ce
commit 9dab3638d5
3 changed files with 72 additions and 7 deletions

View file

@ -8,9 +8,14 @@
let fracsY = 0; let fracsY = 0;
let containerElement; let containerElement;
let showButtons = false; let showButtons = false;
let showSettings = false;
onMount(() => { onMount(() => {
streams = new URLSearchParams(window.location.search).getAll("streams"); const urlSearchParams = new URLSearchParams(window.location.search);
streams = [...urlSearchParams.entries()].map(([type, streamId]) => ({
type,
streamId,
}));
switch (streams.length) { switch (streams.length) {
case 1: case 1:
@ -31,11 +36,31 @@
fracsY = 3; fracsY = 3;
} }
}); });
function onKeyDown() {}
</script> </script>
<svelte:body on:keydown={onKeyDown} />
<main> <main>
{#if containerElement} {#if containerElement}
<Header {containerElement} /> <Header {containerElement} bind:showSettings />
{/if}
{#if showSettings}
<div class="settings">
<h2>Settings</h2>
<form>
<label>
Stream
<input type="text" name="url" />
</label>
<input type="submit" />
</form>
<div>
{#each streams as stream}
<button on:click={() => {}}>{stream.streamId}</button>
{/each}
</div>
</div>
{/if} {/if}
<div <div
bind:this={containerElement} bind:this={containerElement}
@ -47,17 +72,32 @@
", 1fr)"} ", 1fr)"}
> >
{#if streams} {#if streams}
{#each streams as stream} {#each streams as { type, streamId }}
<Stream {stream} /> <Stream {type} stream={streamId} />
{/each} {/each}
{/if} {/if}
</div> </div>
</main> </main>
<style> <style>
main {
position: relative;
}
.streams { .streams {
display: grid; display: grid;
height: 100vh; height: 100vh;
width: 100vw; width: 100vw;
} }
.settings {
padding: 1rem;
background-color: #0000000a;
position: absolute;
width: 50vh;
height: 50vh;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style> </style>

View file

@ -1,6 +1,7 @@
<script> <script>
let showButtons = false; let showButtons = false;
export let containerElement = null; export let showSettings;
export let containerElement;
</script> </script>
<header> <header>
@ -10,6 +11,13 @@
}}>[{showButtons ? "<" : ">"}]</button }}>[{showButtons ? "<" : ">"}]</button
> >
{#if showButtons} {#if showButtons}
<button
on:click={() => {
showSettings = !showSettings;
}}
>
Settings</button
>
<button <button
on:click={() => { on:click={() => {
if (containerElement) containerElement.requestFullscreen(); if (containerElement) containerElement.requestFullscreen();

View file

@ -1,10 +1,27 @@
<script> <script>
export let stream; export let stream;
export let type;
let src;
let data;
switch (type) {
case "twitch":
data = { channel: stream, parent: window.location.host };
src = "https://player.twitch.tv/?" + new URLSearchParams(data);
break;
case "vdo":
data = { view: stream, bitrate: 4000, proaudio: true };
src = "https://vdo.ninja/?" + new URLSearchParams(data);
break;
default:
break;
}
</script> </script>
<div class="stream-container"> <div class="stream-container">
<iframe title={stream} src={"https://vdo.ninja/?vol=0&view=" + stream} {#if src && data}
></iframe> <iframe title={stream} {src}></iframe>
{/if}
</div> </div>
<style> <style>