xonecas.io
4828
Sr

stream-together / files

stream-together / app / [slug] / stream / page.tsx

1.8 KB
1"use client";
2
3import dynamic from "next/dynamic";
4import { useSearchParams } from "next/navigation";
5import { useEffect, useState } from "react";
6import { FaRegCopy as CopyIcon } from "react-icons/fa";
7import { IoMdCheckmark as CheckmarkIcon } from "react-icons/io";
8import { useCopyToClipboard } from "usehooks-ts";
9
10import { HOST, OWNER } from "@/lib/config";
11
12const AgoraProvider = dynamic(() => import("@/components/agora-provider"), {
13  ssr: false,
14});
15const AgoraHost = dynamic(() => import("@/components/agora-host"), {
16  ssr: false,
17});
18
19export default function HostPage() {
20  const [currentUrl, setCurrentUrl] = useState("");
21  const [copied, copy] = useCopyToClipboard();
22  const searchParams = useSearchParams();
23
24  const userType = searchParams.has("host") ? HOST : OWNER;
25
26  useEffect(() => {
27    if (typeof window !== "undefined") {
28      setCurrentUrl(window.location.href + "?host=1");
29    }
30  }, []);
31
32  return (
33    <AgoraProvider>
34      <div className="flex flex-col items-center gap-16">
35        {userType === OWNER && (
36          <div className="text-center p-8 bg-stone-800 shadow-md shadow-stone-800 rounded-2xl max-w-xl">
37            <p className="text-lg p-2">
38              Share this url with your co-host for them to join you!
39            </p>
40
41            <button
42              className="flex flex-row justify-between bg-stone-600 p-4 rounded-xl w-full"
43              onClick={() => copy(currentUrl)}
44            >
45              <pre className="min-w-0 max-w-full overflow-hidden overflow-ellipsis">
46                {currentUrl}
47              </pre>
48              {copied === currentUrl ? (
49                <CheckmarkIcon size="1.25em" />
50              ) : (
51                <CopyIcon size="1.25em" />
52              )}
53            </button>
54          </div>
55        )}
56
57        <AgoraHost userType={userType} />
58      </div>
59    </AgoraProvider>
60  );
61}