2026-04-08 17:10:20 +00:00
|
|
|
<script lang="ts">
|
2026-08-22 20:12:11 +00:00
|
|
|
import {removeUndefined, spec} 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"
|
|
|
|
|
import ProfileCircle from "@app/components/ProfileCircle.svelte"
|
|
|
|
|
import VideoCallTile from "@app/components/VideoCallTile.svelte"
|
2026-08-13 16:01:08 +00:00
|
|
|
import CallControlBar from "@app/components/CallControlBar.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 {
|
|
|
|
|
VideoCallLayout,
|
|
|
|
|
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-08-14 17:43:19 +00:00
|
|
|
computeAdaptiveGrid,
|
|
|
|
|
type AdaptiveTileGrid,
|
2026-06-26 22:56:49 +00:00
|
|
|
} from "@app/call"
|
2026-08-22 20:12:11 +00:00
|
|
|
import {deriveDisplaysByPubkey} from "@app/social"
|
2026-04-08 17:10:20 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
layout: VideoCallLayout
|
|
|
|
|
mobile?: boolean
|
|
|
|
|
url: string
|
|
|
|
|
h: string
|
|
|
|
|
class?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type VideoTileData = {
|
2026-06-26 22:56:49 +00:00
|
|
|
liveKitIdentity: string
|
2026-04-08 17:10:20 +00:00
|
|
|
isLocal: boolean
|
|
|
|
|
trackSid: string
|
|
|
|
|
track: Track | undefined
|
|
|
|
|
source: Track.Source.Camera | Track.Source.ScreenShare
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-14 17:43:19 +00:00
|
|
|
type TileLayoutVariant = "spotlight" | "default" | "strip"
|
2026-04-08 17:10:20 +00:00
|
|
|
|
|
|
|
|
const {layout, mobile = false, url, h, class: className = ""}: Props = $props()
|
|
|
|
|
|
|
|
|
|
const isViewingCurrentCallRoom = $derived(
|
2026-06-26 22:56:49 +00:00
|
|
|
$callTargetRoom?.url === url && $callTargetRoom?.h === h,
|
2026-04-08 17:10:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const showVideoContent = $derived(
|
|
|
|
|
isViewingCurrentCallRoom &&
|
2026-08-10 18:14:46 +00:00
|
|
|
(layout === VideoCallLayout.Split || layout === VideoCallLayout.Video),
|
2026-04-08 17:10:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const videoTiles = $derived.by(() => {
|
2026-06-26 22:56:49 +00:00
|
|
|
const session = $currentCallSession
|
2026-07-20 23:34:06 +00:00
|
|
|
// LiveKit mutates remoteParticipants/tracks in place; these stores are what
|
|
|
|
|
// actually change on join/leave and track subscribe/unsubscribe.
|
|
|
|
|
void $participantMediaState
|
|
|
|
|
void $videoTrackRevision
|
2026-06-26 22:56:49 +00:00
|
|
|
if (!session || $callTargetRoom?.url !== url || $callTargetRoom?.h !== h) {
|
2026-04-08 17:10:20 +00:00
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-26 22:56:49 +00:00
|
|
|
const livekit = session.livekit
|
2026-04-08 17:10:20 +00:00
|
|
|
const videoTiles: VideoTileData[] = []
|
2026-06-26 22:56:49 +00:00
|
|
|
const user = livekit.localParticipant
|
2026-04-08 17:10:20 +00:00
|
|
|
|
|
|
|
|
if (session.cameraOn) {
|
|
|
|
|
const localPub = user.getTrackPublication(Track.Source.Camera)
|
|
|
|
|
videoTiles.push({
|
2026-06-26 22:56:49 +00:00
|
|
|
liveKitIdentity: user.identity,
|
2026-04-08 17:10:20 +00:00
|
|
|
isLocal: true,
|
|
|
|
|
trackSid: localPub?.trackSid ?? "local-camera",
|
|
|
|
|
track: localPub?.track,
|
|
|
|
|
source: Track.Source.Camera,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (session.screenShareOn) {
|
|
|
|
|
const localPub = user.getTrackPublication(Track.Source.ScreenShare)
|
|
|
|
|
videoTiles.push({
|
2026-06-26 22:56:49 +00:00
|
|
|
liveKitIdentity: user.identity,
|
2026-04-08 17:10:20 +00:00
|
|
|
isLocal: true,
|
|
|
|
|
trackSid: localPub?.trackSid ?? "local-screen",
|
|
|
|
|
track: localPub?.track,
|
|
|
|
|
source: Track.Source.ScreenShare,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-26 22:56:49 +00:00
|
|
|
for (const rp of livekit.remoteParticipants.values()) {
|
2026-04-08 17:10:20 +00:00
|
|
|
const camPub = rp.getTrackPublication(Track.Source.Camera)
|
2026-07-20 23:34:06 +00:00
|
|
|
// Camera off mutes the publication rather than unsubscribing; still render avatar.
|
|
|
|
|
if (camPub?.isSubscribed && camPub.track && !camPub.isMuted) {
|
2026-04-08 17:10:20 +00:00
|
|
|
videoTiles.push({
|
2026-06-26 22:56:49 +00:00
|
|
|
liveKitIdentity: rp.identity,
|
2026-04-08 17:10:20 +00:00
|
|
|
isLocal: false,
|
|
|
|
|
trackSid: camPub.trackSid,
|
|
|
|
|
track: camPub.track,
|
|
|
|
|
source: Track.Source.Camera,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const screenPub = rp.getTrackPublication(Track.Source.ScreenShare)
|
2026-07-20 23:34:06 +00:00
|
|
|
if (screenPub?.isSubscribed && screenPub.track && !screenPub.isMuted) {
|
2026-04-08 17:10:20 +00:00
|
|
|
videoTiles.push({
|
2026-06-26 22:56:49 +00:00
|
|
|
liveKitIdentity: rp.identity,
|
2026-04-08 17:10:20 +00:00
|
|
|
isLocal: false,
|
|
|
|
|
trackSid: screenPub.trackSid,
|
|
|
|
|
track: screenPub.track,
|
|
|
|
|
source: Track.Source.ScreenShare,
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-07-28 16:16:26 +00:00
|
|
|
if (!videoTiles.some(spec({liveKitIdentity: rp.identity}))) {
|
2026-05-21 20:58:53 +00:00
|
|
|
videoTiles.push({
|
2026-06-26 22:56:49 +00:00
|
|
|
liveKitIdentity: rp.identity,
|
2026-05-21 20:58:53 +00:00
|
|
|
isLocal: false,
|
|
|
|
|
trackSid: `avatar-${rp.identity}`,
|
|
|
|
|
track: undefined,
|
|
|
|
|
source: Track.Source.Camera,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
if (!videoTiles.some(spec({liveKitIdentity: user.identity}))) {
|
2026-05-21 20:58:53 +00:00
|
|
|
videoTiles.push({
|
2026-06-26 22:56:49 +00:00
|
|
|
liveKitIdentity: user.identity,
|
2026-05-21 20:58:53 +00:00
|
|
|
isLocal: true,
|
|
|
|
|
trackSid: "local-avatar",
|
|
|
|
|
track: undefined,
|
|
|
|
|
source: Track.Source.Camera,
|
|
|
|
|
})
|
2026-04-08 17:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return videoTiles
|
|
|
|
|
})
|
|
|
|
|
|
2026-06-26 22:56:49 +00:00
|
|
|
/** LiveKit identity + source only — LiveKit can change trackSid after publish, which broke spotlight + stale-key effect. */
|
|
|
|
|
const tileKey = (t: VideoTileData) => `${t.liveKitIdentity}\x1f${t.source}`
|
2026-04-08 17:10:20 +00:00
|
|
|
|
|
|
|
|
const primaryTile = $derived.by(() => {
|
|
|
|
|
const k = $videoPrimaryTileKey
|
|
|
|
|
if (k === undefined) return undefined
|
|
|
|
|
return videoTiles.find(t => tileKey(t) === k)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const secondaryTiles = $derived.by(() => {
|
|
|
|
|
const p = primaryTile
|
|
|
|
|
if (p === undefined) return videoTiles
|
|
|
|
|
const pk = tileKey(p)
|
|
|
|
|
return videoTiles.filter(t => tileKey(t) !== pk)
|
|
|
|
|
})
|
|
|
|
|
|
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
|
|
|
|
|
if (k === undefined) return
|
|
|
|
|
if (!videoTiles.some(t => tileKey(t) === k)) {
|
|
|
|
|
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-06-26 22:56:49 +00:00
|
|
|
const labelFor = (liveKitIdentity: string, source: VideoTileData["source"]) => {
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const panelChrome = $derived(
|
2026-08-27 23:06:10 +00:00
|
|
|
mobile
|
|
|
|
|
? cx(
|
|
|
|
|
"flex min-h-0 w-full flex-1 flex-col gap-2 overflow-y-auto overflow-x-hidden bg-surface px-2 pt-4 md:hidden pb-[calc(3.5rem+var(--saib))]",
|
|
|
|
|
className,
|
|
|
|
|
)
|
|
|
|
|
: "flex min-h-0 w-full min-w-0 flex-1 flex-col gap-2 overflow-hidden bg-surface px-2 pb-2 pt-4",
|
2026-04-08 17:10:20 +00:00
|
|
|
)
|
2026-08-27 23:06:10 +00:00
|
|
|
|
|
|
|
|
// Desktop: `className` (the instance's own visibility/sizing, e.g. "hidden ...
|
|
|
|
|
// md:flex") lives on this wrapper rather than on panelChrome, so the floating
|
|
|
|
|
// control bar below shares its box — a `relative` box that's already sized to
|
|
|
|
|
// the real (chat-sidebar-aware) video pane width, since RoomChat now lays the
|
|
|
|
|
// chat sidebar out as a flex sibling instead of an absolute overlay. Centering
|
|
|
|
|
// the controls against this box (instead of the viewport) is what keeps them
|
|
|
|
|
// centered in the actual remaining space as that width animates open/closed.
|
|
|
|
|
const desktopWrapperClass = $derived(cx("relative flex min-h-0 flex-1 flex-col", className))
|
2026-04-08 17:10:20 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-08-14 17:43:19 +00:00
|
|
|
{#snippet videoTile(tile: VideoTileData, 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-08-13 16:01:08 +00:00
|
|
|
// bg-surface-more (rather than bg-surface, same as the panel behind it) so a
|
|
|
|
|
// camera-off tile reads as its own card instead of blending into the panel.
|
|
|
|
|
"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}
|
|
|
|
|
{@const pinned = $videoPrimaryTileKey === tileKey(tile)}
|
|
|
|
|
<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
|
|
|
)}
|
|
|
|
|
onclick={spotlightHandlerFor(tileKey(tile))}>
|
|
|
|
|
<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">
|
|
|
|
|
{#each secondaryTiles as tile (tileKey(tile))}
|
|
|
|
|
{@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}
|
|
|
|
|
class="min-h-0 flex-1 overflow-y-auto [scrollbar-gutter:stable]">
|
|
|
|
|
{#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`}>
|
|
|
|
|
{#each videoTiles.slice(offset, offset + row.columnCount) as tile (tileKey(tile))}
|
|
|
|
|
<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}
|
|
|
|
|
|
|
|
|
|
{#if showVideoContent}
|
2026-08-27 23:06:10 +00:00
|
|
|
{#if mobile}
|
|
|
|
|
<div class={panelChrome}>
|
|
|
|
|
{@render videoPanelBody()}
|
|
|
|
|
</div>
|
|
|
|
|
<!-- fixed (viewport-relative), not absolute within panelChrome — panelChrome's
|
|
|
|
|
flex-computed height isn't guaranteed to reach the real viewport bottom, so
|
|
|
|
|
an absolute child positioned against its box can end up overlapping the
|
|
|
|
|
fixed bottom nav bar. Matches the same bottom-nav-clearing offset the old
|
|
|
|
|
chat FAB used.
|
2026-08-13 16:01:08 +00:00
|
|
|
|
2026-08-27 23:06:10 +00:00
|
|
|
RoomChat mounts both a desktop and a mobile VideoCallContent instance at
|
|
|
|
|
once while connected, each gated by its own `class` prop — this instance
|
|
|
|
|
is the mobile one, so it's the only copy visible below md. -->
|
|
|
|
|
<div
|
|
|
|
|
class="left-content pointer-events-none fixed right-sai z-popover flex justify-center bottom-[calc(4.5rem+var(--saib))] md:hidden">
|
|
|
|
|
<CallControlBar {url} {h} />
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
|
|
|
|
<!-- desktopWrapperClass carries this instance's own visibility ("hidden ...
|
|
|
|
|
md:flex") and is `relative`, so the control bar below is `absolute` against
|
|
|
|
|
the real (chat-sidebar-aware) video pane box rather than the viewport —
|
|
|
|
|
it re-centers automatically as that box's width animates. -->
|
|
|
|
|
<div class={desktopWrapperClass}>
|
|
|
|
|
<div class={panelChrome}>
|
|
|
|
|
{@render videoPanelBody()}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="pointer-events-none absolute inset-x-0 bottom-4 z-popover flex justify-center">
|
|
|
|
|
<CallControlBar {url} {h} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2026-04-08 17:10:20 +00:00
|
|
|
{/if}
|