|
1 | | -'use client'; |
| 1 | +"use client"; |
2 | 2 |
|
3 | | -import { App } from '@/components/app'; |
| 3 | +import Link from "next/link"; |
| 4 | +import { PowerIcon, TriangleAlertIcon } from "lucide-react"; |
4 | 5 |
|
5 | | -import { TokenSource } from 'livekit-client'; |
6 | | -import { SessionProvider, useSession } from '@livekit/components-react'; |
| 6 | +import { Button } from "@/components/ui/button"; |
| 7 | +import { motion, AnimatePresence } from "motion/react"; |
7 | 8 |
|
8 | | -const TOKEN_SOURCE = TokenSource.literal({ |
9 | | - serverUrl: process.env.NEXT_PUBLIC_LIVEKIT_URL as string, |
10 | | - participantToken: process.env.NEXT_PUBLIC_LIVEKIT_TOKEN as string, |
11 | | -}); |
| 9 | +const armConfigured = Boolean( |
| 10 | + process.env.NEXT_PUBLIC_ROBOT_IDENTITY && |
| 11 | + process.env.NEXT_PUBLIC_ROBOT_LIVEKIT_URL && |
| 12 | + process.env.NEXT_PUBLIC_ROBOT_LIVEKIT_TOKEN, |
| 13 | +); |
12 | 14 |
|
13 | | -export default function Home() { |
14 | | - const session = useSession(TOKEN_SOURCE); |
| 15 | +const roverConfigured = Boolean( |
| 16 | + process.env.NEXT_PUBLIC_ROVER_IDENTITY && |
| 17 | + process.env.NEXT_PUBLIC_ROVER_LIVEKIT_URL && |
| 18 | + process.env.NEXT_PUBLIC_ROVER_LIVEKIT_TOKEN, |
| 19 | +); |
| 20 | + |
| 21 | +function EmptyState() { |
| 22 | + return ( |
| 23 | + <div className="border-input bg-card flex max-w-md flex-col items-center gap-3 rounded-lg border px-6 py-8 text-center backdrop-blur-lg"> |
| 24 | + <TriangleAlertIcon className="text-foreground size-12" /> |
| 25 | + <h1 className="font-mono text-sm uppercase tracking-wide"> |
| 26 | + No robots configured |
| 27 | + </h1> |
| 28 | + <p className="text-muted-foreground font-mono text-xs leading-relaxed"> |
| 29 | + Define{" "} |
| 30 | + <code className="bg-card text-foreground rounded px-1 py-0.5"> |
| 31 | + NEXT_PUBLIC_ROBOT_* |
| 32 | + </code>{" "} |
| 33 | + and/or{" "} |
| 34 | + <code className="bg-card text-foreground rounded px-1 py-0.5"> |
| 35 | + NEXT_PUBLIC_ROVER_* |
| 36 | + </code>{" "} |
| 37 | + env vars in{" "} |
| 38 | + <code className="bg-card text-foreground rounded px-1 py-0.5"> |
| 39 | + .env.local |
| 40 | + </code>{" "} |
| 41 | + and restart the dev server. |
| 42 | + </p> |
| 43 | + </div> |
| 44 | + ); |
| 45 | +} |
15 | 46 |
|
| 47 | +export default function Home() { |
16 | 48 | return ( |
17 | | - <SessionProvider session={session}> |
18 | | - <App /> |
19 | | - </SessionProvider> |
| 49 | + <AnimatePresence> |
| 50 | + {!armConfigured && !roverConfigured ? ( |
| 51 | + <motion.div |
| 52 | + initial={{ opacity: 0, scale: 0.9 }} |
| 53 | + animate={{ opacity: 1, scale: 1 }} |
| 54 | + exit={{ opacity: 0, scale: 0.9 }} |
| 55 | + className="relative grid h-dvh place-items-center" |
| 56 | + > |
| 57 | + <EmptyState /> |
| 58 | + </motion.div> |
| 59 | + ) : ( |
| 60 | + <motion.div |
| 61 | + initial={{ opacity: 0 }} |
| 62 | + animate={{ opacity: 1 }} |
| 63 | + exit={{ opacity: 0 }} |
| 64 | + className="relative grid h-dvh place-items-center gap-4" |
| 65 | + > |
| 66 | + <div className="bg-card border-input rounded-lg border p-8 backdrop-blur-lg w-full max-w-sm"> |
| 67 | + <h1 className="text-2xl uppercase tracking-wide mb-4"> |
| 68 | + TeleOp Web UI |
| 69 | + </h1> |
| 70 | + <p className="uppercase mb-2">Connect to:</p> |
| 71 | + <div className="flex gap-2 justify-center"> |
| 72 | + {armConfigured && ( |
| 73 | + <Link href="/robot" className="grow"> |
| 74 | + <Button |
| 75 | + size="lg" |
| 76 | + variant="outline" |
| 77 | + className="font-mono uppercase w-full" |
| 78 | + > |
| 79 | + <PowerIcon className="size-4 justify-self-start" /> |
| 80 | + <span className="grow text-left">Robot</span> |
| 81 | + </Button> |
| 82 | + </Link> |
| 83 | + )} |
| 84 | + {roverConfigured && ( |
| 85 | + <Link href="/rover" className="grow"> |
| 86 | + <Button |
| 87 | + size="lg" |
| 88 | + variant="outline" |
| 89 | + className="font-mono uppercase w-full" |
| 90 | + > |
| 91 | + <PowerIcon className="size-4 justify-self-start" /> |
| 92 | + <span className="grow text-left">Rover</span> |
| 93 | + </Button> |
| 94 | + </Link> |
| 95 | + )} |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + </motion.div> |
| 99 | + )} |
| 100 | + </AnimatePresence> |
20 | 101 | ); |
21 | 102 | } |
0 commit comments