fix: show videos in iframes, close #222

This commit is contained in:
Xylight committed 2023-12-12 16:08:46 -08:00
1 parent d75fcb328f
commit 0557b520ef
4 files changed
+40 -17

No files matched your search

@@ -30,6 +30,10 @@
export let opened = !$userSettings.embeds.clickToView
const urlToEmbed = (inputUrl: string) => {
if (type == 'video') {
return inputUrl
}
if (type == 'youtube') {
const url = new URL(inputUrl)
const videoID = url.searchParams.get('v')
@@ -56,6 +60,12 @@
text: 'YouTube Video',
}
}
case 'video': {
return {
icon: VideoCamera,
text: 'Video',
}
}
default: {
return {
icon: PuzzlePiece,
@@ -70,18 +80,25 @@
</script>
{#if opened}
<iframe
src={embedUrl}
title="Embed player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen
class="aspect-video rounded-xl dark:bg-zinc-900"
/>
{#if type == 'video'}
<!-- svelte-ignore a11y-media-has-caption -->
<video controls class="rounded-xl aspect-video">
<source src={url} />
</video>
{:else}
<iframe
src={embedUrl}
title="Embed player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen
class="aspect-video rounded-xl dark:bg-zinc-900"
/>
{/if}
{:else}
<button
on:click={() => (opened = true)}
class="aspect-video w-full h-full z-0 overflow-hidden relative rounded-xl flex flex-col gap-2 items-center justify-center"
class="aspect-video w-full h-full z-0 overflow-hidden relative rounded-xl flex flex-col gap-2 items-center justify-center text-white"
>
{#if thumbnail}
<img
@@ -5,6 +5,7 @@
bestImageURL,
postLink,
type MediaType,
iframeType,
} from '$lib/components/lemmy/post/helpers.js'
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
import { userSettings } from '$lib/settings.js'
@@ -95,7 +96,7 @@
{:else if type == 'iframe' && (view == 'cozy' || view == 'card') && post.url}
<PostIframe
thumbnail={post.thumbnail_url}
type="youtube"
type={iframeType(post)}
url={post.url}
{opened}
/>