import type { NextPage, GetServerSideProps, InferGetServerSidePropsType } from 'next'; import { useRouter } from 'next/router'; import React, { ReactElement, useCallback, useEffect, useState } from 'react'; import styles from '../styles/Home.module.css'; interface TabsProps { children: ReactElement[]; selectedIndex?: number; onTabSelected?: (index: number) => void; } function Tabs(props: TabsProps) { const activeIndex = props.selectedIndex ?? 0; if (!props.children) { return <>; } let tabs = React.Children.map(props.children, (child, index) => { return ( ); }); return (
{tabs}
{props.children[activeIndex]}
); } function DemoMeetingTab({ label }: { label: string }) { const router = useRouter(); const startMeeting = () => { router.push(`/rooms/${generateRoomId()}`); }; return (

Try LiveKit Meet for free with our live demo project.

); } function CustomConnectionTab({ label }: { label: string }) { const [liveKitUrl, setLiveKitUrl] = useState(); const [token, setToken] = useState(); const router = useRouter(); const join = () => { router.push(`/custom/?liveKitUrl=${liveKitUrl}&token=${token}`); }; return (

Connect LiveKit Meet with a custom server using LiveKit Cloud or LiveKit Server.

{/* */} setLiveKitUrl(ev.target.value)}> {/* */} setToken(ev.target.value)}>
); } export const getServerSideProps: GetServerSideProps<{ tabIndex: number }> = async ({ query, res, }) => { res.setHeader('Cache-Control', 'public, max-age=7200'); const tabIndex = query.tab === 'custom' ? 1 : 0; return { props: { tabIndex } }; }; const Home = ({ tabIndex }: InferGetServerSidePropsType) => { const router = useRouter(); function onTabSelected(index: number) { const tab = index === 1 ? 'custom' : 'demo'; router.push({ query: { tab } }); } return ( <>
LiveKit Meet

Open source video conferencing app built on{' '} LiveKit Components ,{' '} LiveKit Cloud {' '} and Next.js.

); }; export default Home; function generateRoomId(): string { return `${randomString(4)}-${randomString(4)}`; } function randomString(length: number): string { let result = ''; const characters = 'abcdefghijklmnopqrstuvwxyz0123456789'; const charactersLength = characters.length; for (let i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; }