Adds support for rendering video with cover or contain (#28)
This commit is contained in:
parent
d310075a3d
commit
feecd83ce1
@ -11,6 +11,7 @@ title: 'LiveKit Agent Playground'
|
|||||||
description: 'LiveKit Agent Playground allows you to test your LiveKit Agent integration by connecting to your LiveKit Cloud or self-hosted instance.'
|
description: 'LiveKit Agent Playground allows you to test your LiveKit Agent integration by connecting to your LiveKit Cloud or self-hosted instance.'
|
||||||
github_link: 'https://github.com/livekit-examples/agent-playground'
|
github_link: 'https://github.com/livekit-examples/agent-playground'
|
||||||
theme_color: 'cyan'
|
theme_color: 'cyan'
|
||||||
|
video_fit: 'cover' # 'contain' or 'cover'
|
||||||
outputs:
|
outputs:
|
||||||
audio: true # Enable or disable audio output
|
audio: true # Enable or disable audio output
|
||||||
video: true # Enable or disable video output
|
video: true # Enable or disable video output
|
||||||
|
|||||||
@ -57,6 +57,7 @@ export interface PlaygroundProps {
|
|||||||
showQR?: boolean;
|
showQR?: boolean;
|
||||||
onConnect: (connect: boolean, opts?: { token: string; url: string }) => void;
|
onConnect: (connect: boolean, opts?: { token: string; url: string }) => void;
|
||||||
metadata?: PlaygroundMeta[];
|
metadata?: PlaygroundMeta[];
|
||||||
|
videoFit?: "contain" | "cover";
|
||||||
}
|
}
|
||||||
|
|
||||||
const headerHeight = 56;
|
const headerHeight = 56;
|
||||||
@ -72,6 +73,7 @@ export default function Playground({
|
|||||||
defaultColor,
|
defaultColor,
|
||||||
onConnect,
|
onConnect,
|
||||||
metadata,
|
metadata,
|
||||||
|
videoFit,
|
||||||
}: PlaygroundProps) {
|
}: PlaygroundProps) {
|
||||||
const [agentState, setAgentState] = useState<AgentState>("offline");
|
const [agentState, setAgentState] = useState<AgentState>("offline");
|
||||||
const [themeColor, setThemeColor] = useState(defaultColor);
|
const [themeColor, setThemeColor] = useState(defaultColor);
|
||||||
@ -201,12 +203,13 @@ export default function Playground({
|
|||||||
useDataChannel(onDataReceived);
|
useDataChannel(onDataReceived);
|
||||||
|
|
||||||
const videoTileContent = useMemo(() => {
|
const videoTileContent = useMemo(() => {
|
||||||
|
const videoFitClassName = `object-${videoFit}`;
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col w-full grow text-gray-950 bg-black rounded-sm border border-gray-800 relative">
|
<div className="flex flex-col w-full grow text-gray-950 bg-black rounded-sm border border-gray-800 relative">
|
||||||
{agentVideoTrack ? (
|
{agentVideoTrack ? (
|
||||||
<VideoTrack
|
<VideoTrack
|
||||||
trackRef={agentVideoTrack}
|
trackRef={agentVideoTrack}
|
||||||
className="absolute top-1/2 -translate-y-1/2 object-cover object-position-center w-full h-full"
|
className={`absolute top-1/2 -translate-y-1/2 ${videoFitClassName} object-position-center w-full h-full`}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col items-center justify-center gap-2 text-gray-700 text-center h-full w-full">
|
<div className="flex flex-col items-center justify-center gap-2 text-gray-700 text-center h-full w-full">
|
||||||
@ -216,7 +219,7 @@ export default function Playground({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}, [agentVideoTrack]);
|
}, [agentVideoTrack, videoFit]);
|
||||||
|
|
||||||
const audioTileContent = useMemo(() => {
|
const audioTileContent = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -7,6 +7,7 @@ export type AppConfig = {
|
|||||||
description: string;
|
description: string;
|
||||||
github_link?: string;
|
github_link?: string;
|
||||||
theme_color?: string;
|
theme_color?: string;
|
||||||
|
video_fit?: "cover" | "contain";
|
||||||
outputs: {
|
outputs: {
|
||||||
audio: boolean;
|
audio: boolean;
|
||||||
video: boolean;
|
video: boolean;
|
||||||
@ -24,6 +25,7 @@ const defaultConfig: AppConfig = {
|
|||||||
title: "Agents Playground",
|
title: "Agents Playground",
|
||||||
description: "A playground for testing LiveKit Agents",
|
description: "A playground for testing LiveKit Agents",
|
||||||
theme_color: "cyan",
|
theme_color: "cyan",
|
||||||
|
video_fit: "cover",
|
||||||
outputs: {
|
outputs: {
|
||||||
audio: true,
|
audio: true,
|
||||||
video: true,
|
video: true,
|
||||||
|
|||||||
@ -159,6 +159,7 @@ export default function Home() {
|
|||||||
defaultColor={appConfig?.theme_color ?? "cyan"}
|
defaultColor={appConfig?.theme_color ?? "cyan"}
|
||||||
onConnect={handleConnect}
|
onConnect={handleConnect}
|
||||||
metadata={metadata}
|
metadata={metadata}
|
||||||
|
videoFit={appConfig?.video_fit ?? "cover"}
|
||||||
/>
|
/>
|
||||||
<RoomAudioRenderer />
|
<RoomAudioRenderer />
|
||||||
<StartAudio label="Click to enable audio playback" />
|
<StartAudio label="Click to enable audio playback" />
|
||||||
|
|||||||
@ -37,6 +37,8 @@ const safelist = [
|
|||||||
'bg-black',
|
'bg-black',
|
||||||
'bg-white',
|
'bg-white',
|
||||||
'transparent',
|
'transparent',
|
||||||
|
'object-cover',
|
||||||
|
'object-contain',
|
||||||
...shadowNames,
|
...shadowNames,
|
||||||
...textShadowNames,
|
...textShadowNames,
|
||||||
...shades.flatMap(shade => [
|
...shades.flatMap(shade => [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user