2026-04-08 17:10:20 +00:00
|
|
|
<script lang="ts">
|
2026-09-26 07:30:16 +00:00
|
|
|
import {removeUndefined} from "@welshman/lib"
|
2026-04-08 17:10:20 +00:00
|
|
|
import cx from "classnames"
|
|
|
|
|
import {Track} from "livekit-client"
|
|
|
|
|
import Pin from "@assets/icons/pin.svg?dataurl"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2026-09-26 07:30:16 +00:00
|
|
|
import {computeAdaptiveGrid} from "@lib/tileGrid"
|
|
|
|
|
import type {AdaptiveTileGrid} from "@lib/tileGrid"
|
2026-04-08 17:10:20 +00:00
|
|
|
import ProfileCircle from "@app/components/ProfileCircle.svelte"
|
|
|
|
|
import VideoCallTile from "@app/components/VideoCallTile.svelte"
|
2026-05-21 20:58:53 +00:00
|
|
|
import VoiceParticipantMediaBadges from "@app/components/VoiceParticipantMediaBadges.svelte"
|
2026-04-08 17:10:20 +00:00
|
|
|
import {
|
|
|
|
|
toggleVideoPrimaryTile,
|
|
|
|
|
videoPrimaryTileKey,
|
2026-06-26 22:56:49 +00:00
|
|
|
currentCallSession,
|
|
|
|
|
callTargetRoom,
|
2026-05-21 20:58:53 +00:00
|
|
|
mediaStateByIdentity,
|
2026-07-20 23:34:06 +00:00
|
|
|
participantMediaState,
|
2026-05-21 20:58:53 +00:00
|
|
|
pubkeyFromLiveKitIdentity,
|
2026-07-20 23:34:06 +00:00
|
|
|
videoTrackRevision,
|
2026-06-26 22:56:49 +00:00
|
|
|
} from "@app/call"
|
2026-09-26 07:30:16 +00:00
|
|
|
import {getVideoTileKey, getVideoTiles} from "@app/callEngine"
|
|
|
|
|
import type {VideoTile} from "@app/callEngine"
|
2026-08-22 20:12:11 +00:00
|
|
|
import {deriveDisplaysByPubkey} from "@app/social"
|
2026-04-08 17:10:20 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
url: string
|
|
|
|
|
h: string
|
|
|
|
|
class?: string
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-14 17:43:19 +00:00
|
|
|
type TileLayoutVariant = "spotlight" | "default" | "strip"
|
2026-04-08 17:10:20 +00:00
|
|
|
|
2026-08-27 23:54:30 +00:00
|
|
|
const {url, h, class: className}: Props = $props()
|
2026-04-08 17:10:20 +00:00
|
|
|
|
|
|
|
|
const videoTiles = $derived.by(() => {
|
2026-09-24 18:23:21 +00:00
|
|
|
// LiveKit mutates remoteParticipants and tracks in place, so these stores are what change.
|
2026-07-20 23:34:06 +00:00
|
|
|
void $participantMediaState
|
|
|
|
|
void $videoTrackRevision
|
2026-04-08 17:10:20 +00:00
|
|
|
|
2026-09-26 07:30:16 +00:00
|
|
|
return $currentCallSession && $callTargetRoom?.url === url && $callTargetRoom?.h === h
|
|
|
|
|
? getVideoTiles($currentCallSession)
|
|
|
|
|
: []
|
2026-04-08 17:10:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const primaryTile = $derived.by(() => {
|
|
|
|
|
const k = $videoPrimaryTileKey
|
2026-09-21 16:48:35 +00:00
|
|
|
if (k === undefined) {
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
2026-09-26 07:30:16 +00:00
|
|
|
return videoTiles.find(t => getVideoTileKey(t) === k)
|
2026-04-08 17:10:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const secondaryTiles = $derived.by(() => {
|
|
|
|
|
const p = primaryTile
|
2026-09-21 16:48:35 +00:00
|
|
|
if (p === undefined) {
|
|
|
|
|
return videoTiles
|
|
|
|
|
}
|
2026-09-26 07:30:16 +00:00
|
|
|
const pk = getVideoTileKey(p)
|
|
|
|
|
return videoTiles.filter(t => getVideoTileKey(t) !== pk)
|
2026-04-08 17:10:20 +00:00
|
|
|
})
|
|
|
|
|
|
2026-08-14 17:43:19 +00:00
|
|
|
let gridWidth = $state(0)
|
|
|
|
|
let gridHeight = $state(0)
|
|
|
|
|
|
2026-04-08 17:10:20 +00:00
|
|
|
const useSpotlightLayout = $derived(primaryTile !== undefined)
|
2026-08-14 17:43:19 +00:00
|
|
|
const useMultiGrid = $derived(!useSpotlightLayout)
|
|
|
|
|
|
|
|
|
|
const tileGrid = $derived<AdaptiveTileGrid | undefined>(
|
|
|
|
|
useMultiGrid ? computeAdaptiveGrid(videoTiles.length, gridWidth, gridHeight) : undefined,
|
|
|
|
|
)
|
2026-04-08 17:10:20 +00:00
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
|
const k = $videoPrimaryTileKey
|
2026-09-21 16:48:35 +00:00
|
|
|
if (k === undefined) {
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-09-26 07:30:16 +00:00
|
|
|
if (!videoTiles.some(t => getVideoTileKey(t) === k)) {
|
2026-04-08 17:10:20 +00:00
|
|
|
videoPrimaryTileKey.set(undefined)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-22 20:12:11 +00:00
|
|
|
const displays = $derived(
|
|
|
|
|
deriveDisplaysByPubkey(
|
|
|
|
|
removeUndefined(videoTiles.map(t => pubkeyFromLiveKitIdentity(t.liveKitIdentity))),
|
|
|
|
|
url,
|
|
|
|
|
),
|
|
|
|
|
)
|
2026-04-08 17:10:20 +00:00
|
|
|
|
2026-09-26 07:30:16 +00:00
|
|
|
const labelFor = (liveKitIdentity: string, source: VideoTile["source"]) => {
|
2026-06-26 22:56:49 +00:00
|
|
|
const pk = pubkeyFromLiveKitIdentity(liveKitIdentity)
|
2026-08-22 20:12:11 +00:00
|
|
|
const name = (pk && $displays.get(pk)) || "Unknown"
|
|
|
|
|
|
2026-04-08 17:10:20 +00:00
|
|
|
return source === Track.Source.ScreenShare ? `${name} · screen` : name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const showTileGrid = $derived(videoTiles.length > 0)
|
|
|
|
|
|
|
|
|
|
const spotlightHandlerFor = (key: string) => () => {
|
|
|
|
|
toggleVideoPrimaryTile(key)
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-09-26 07:30:16 +00:00
|
|
|
{#snippet videoTile(tile: VideoTile, layout: TileLayoutVariant)}
|
2026-06-26 22:56:49 +00:00
|
|
|
{@const media = $mediaStateByIdentity(tile.liveKitIdentity)}
|
2026-08-10 18:14:46 +00:00
|
|
|
{@const label = labelFor(tile.liveKitIdentity, tile.source)}
|
2026-04-08 17:10:20 +00:00
|
|
|
<div
|
|
|
|
|
class={cx(
|
2026-09-24 18:23:21 +00:00
|
|
|
// bg-surface-more so a camera-off tile reads as its own card instead of blending into the panel.
|
2026-08-13 16:01:08 +00:00
|
|
|
"relative isolate overflow-hidden rounded-2xl border border-line shadow-sm",
|
2026-04-08 17:10:20 +00:00
|
|
|
layout === "spotlight" && "min-h-0 flex-1",
|
2026-08-14 17:43:19 +00:00
|
|
|
layout === "default" && "min-h-0 h-full w-full",
|
2026-04-08 17:10:20 +00:00
|
|
|
layout === "strip" && "aspect-video w-44 shrink-0",
|
2026-08-13 16:01:08 +00:00
|
|
|
tile.source === Track.Source.ScreenShare ? "bg-black" : "bg-surface-more",
|
2026-04-08 17:10:20 +00:00
|
|
|
)}>
|
|
|
|
|
{#if tile.track}
|
|
|
|
|
<VideoCallTile
|
|
|
|
|
track={tile.track}
|
|
|
|
|
muted={tile.isLocal}
|
|
|
|
|
fit={tile.source === Track.Source.ScreenShare ? "contain" : "cover"}
|
|
|
|
|
class="pointer-events-none absolute inset-0" />
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="absolute inset-0 flex items-center justify-center">
|
2026-06-26 22:56:49 +00:00
|
|
|
<ProfileCircle pubkey={pubkeyFromLiveKitIdentity(tile.liveKitIdentity)} {url} size={14} />
|
2026-04-08 17:10:20 +00:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
2026-05-21 20:58:53 +00:00
|
|
|
{#if tile.track}
|
|
|
|
|
<div class="pointer-events-none absolute left-1 top-1 z-10">
|
|
|
|
|
<VoiceParticipantMediaBadges
|
|
|
|
|
muted={media.muted}
|
|
|
|
|
cameraOn={media.cameraOn}
|
|
|
|
|
showCamera={tile.source === Track.Source.Camera}
|
|
|
|
|
size={3} />
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2026-06-18 10:52:04 +00:00
|
|
|
<span
|
2026-07-27 22:38:23 +00:00
|
|
|
class="pointer-events-none absolute bottom-1 left-1 max-w-[calc(100%-0.5rem)] truncate rounded bg-surface/80 px-1.5 py-0.5 text-xs">
|
2026-08-10 18:14:46 +00:00
|
|
|
{label}{tile.isLocal ? " (you)" : ""}
|
2026-04-08 17:10:20 +00:00
|
|
|
</span>
|
|
|
|
|
{#if videoTiles.length > 1}
|
2026-09-26 07:30:16 +00:00
|
|
|
{@const pinned = $videoPrimaryTileKey === getVideoTileKey(tile)}
|
2026-04-08 17:10:20 +00:00
|
|
|
<Button
|
|
|
|
|
data-tip={pinned ? "Exit spotlight" : "Spotlight"}
|
2026-08-10 18:14:46 +00:00
|
|
|
aria-label={pinned ? `Exit spotlight for ${label}` : `Spotlight ${label}`}
|
2026-04-08 17:10:20 +00:00
|
|
|
aria-pressed={pinned}
|
|
|
|
|
class={cx(
|
2026-06-24 20:56:53 +00:00
|
|
|
`button button-${pinned ? "primary" : "ghost"} button-xs button-square`,
|
|
|
|
|
"absolute right-1 top-1 z-20",
|
|
|
|
|
!pinned && "bg-surface",
|
2026-04-08 17:10:20 +00:00
|
|
|
)}
|
2026-09-26 07:30:16 +00:00
|
|
|
onclick={spotlightHandlerFor(getVideoTileKey(tile))}>
|
2026-04-08 17:10:20 +00:00
|
|
|
<Icon icon={Pin} size={3} />
|
|
|
|
|
</Button>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
|
|
|
|
|
{#snippet videoPanelBody()}
|
|
|
|
|
{#if showTileGrid}
|
|
|
|
|
{#if useSpotlightLayout && primaryTile}
|
|
|
|
|
<div class="flex min-h-0 flex-1 flex-col gap-2 overflow-hidden">
|
|
|
|
|
{@render videoTile(primaryTile, "spotlight")}
|
|
|
|
|
{#if secondaryTiles.length > 0}
|
|
|
|
|
<div
|
|
|
|
|
class="flex max-h-40 shrink-0 flex-row gap-2 overflow-x-auto overflow-y-hidden py-0.5">
|
2026-09-26 07:30:16 +00:00
|
|
|
{#each secondaryTiles as tile (getVideoTileKey(tile))}
|
2026-04-08 17:10:20 +00:00
|
|
|
{@render videoTile(tile, "strip")}
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{:else if useMultiGrid}
|
2026-08-14 17:43:19 +00:00
|
|
|
<div
|
|
|
|
|
bind:clientWidth={gridWidth}
|
|
|
|
|
bind:clientHeight={gridHeight}
|
2026-08-27 23:54:30 +00:00
|
|
|
class="min-h-0 flex-1 overflow-y-auto [scrollbar-gutter:stable_both-edges]">
|
2026-08-14 17:43:19 +00:00
|
|
|
{#if tileGrid}
|
|
|
|
|
<div class="flex flex-col items-center gap-2">
|
2026-08-22 17:32:51 +00:00
|
|
|
{#each tileGrid.rows as row, rowIndex (rowIndex)}
|
2026-08-14 17:43:19 +00:00
|
|
|
{@const offset = tileGrid.rows
|
|
|
|
|
.slice(0, rowIndex)
|
|
|
|
|
.reduce((sum, r) => sum + r.columnCount, 0)}
|
|
|
|
|
<div
|
|
|
|
|
class="flex flex-nowrap justify-center gap-2"
|
|
|
|
|
style={`max-width: ${row.rowWidth}px`}>
|
2026-09-26 07:30:16 +00:00
|
|
|
{#each videoTiles.slice(offset, offset + row.columnCount) as tile (getVideoTileKey(tile))}
|
2026-08-14 17:43:19 +00:00
|
|
|
<div
|
|
|
|
|
class="overflow-hidden rounded-2xl shrink-0"
|
|
|
|
|
style={`width: ${row.tileWidth}px; height: ${row.tileHeight}px`}>
|
|
|
|
|
{@render videoTile(tile, "default")}
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2026-04-08 17:10:20 +00:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{:else}
|
|
|
|
|
<div
|
2026-08-13 16:01:08 +00:00
|
|
|
class="flex min-h-[12rem] flex-1 flex-col items-center justify-center gap-2 rounded-2xl border border-line bg-surface-more p-4 text-center text-sm opacity-80">
|
2026-07-20 23:34:06 +00:00
|
|
|
<p>Waiting for participants…</p>
|
2026-04-08 17:10:20 +00:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{/snippet}
|
|
|
|
|
|
2026-08-27 23:54:30 +00:00
|
|
|
<div class={cx("flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden p-2", className)}>
|
|
|
|
|
{@render videoPanelBody()}
|
|
|
|
|
</div>
|