xonecas.io
4828
Sr

stream-together / commit c1f2d02

Started to clean up for deployment

Added an environment file with the required fields
Remove the /new page since we now have an environment
Improved the rendering of the video element, now it maintains the 4/3
aspect ratio

sean2024-06-28 c1f2d025bf2f931bc7062b6fac5f67c2a9aabc45 parent 7dccb18

6 files changed

.env.sample+5−0
@@ -0,0 +1,5 @@
1+# Get these values from AgoraIO's console
2+# https://console.agora.io/
3+NEXT_PUBLIC_APP_ID=
4+NEXT_PUBLIC_CHANNEL=
5+NEXT_PUBLIC_TOKEN=
app/[slug]/host/page.tsx+2−2
@@ -34,7 +34,7 @@ export default function StreamSetupPage({
3434 return (
3535 <AgoraProvider>
3636 <div className="flex flex-col items-center gap-16">
37- <div className="w-1/2 text-center">
37+ <div className="max-w-xl w-full text-center">
3838 <p className="text-lg p-2">
3939 Share this url with your co-host for them to join you!
4040 </p>
@@ -52,7 +52,7 @@ export default function StreamSetupPage({
5252 </button>
5353 </div>
5454
55- <AgoraHost config={{ appId, channel, token }} />
55+ <AgoraHost />
5656 </div>
5757 </AgoraProvider>
5858 );
app/new/layout.tsx+0−9
@@ -1,9 +0,0 @@
1-import AppLayout from "@/components/app-layout";
2-
3-export default function NewLayout({
4- children,
5-}: Readonly<{
6- children: React.ReactNode;
7-}>) {
8- return <AppLayout>{children}</AppLayout>;
9-}
app/new/page.tsx+0−104
@@ -1,104 +0,0 @@
1-"use client";
2-
3-import Link from "next/link";
4-import { useRouter } from "next/navigation";
5-import { useCallback, useState } from "react";
6-import { useLocalStorage } from "usehooks-ts";
7-
8-import { pacifico } from "@/components/pacifico-font";
9-import PrimaryButton from "@/components/primary-button";
10-import slugify from "@/lib/slugify";
11-
12-export default function NewStreamPage() {
13- const [appId, setAppId] = useLocalStorage("app-id", "");
14- const [token, setToken] = useLocalStorage("token", "");
15- const [channel, setChannel] = useLocalStorage("channel", "");
16- const [error, setError] = useState("");
17- const router = useRouter();
18-
19- const handleChange = useCallback(
20- (e: React.ChangeEvent<HTMLInputElement>) => {
21- const name: string = e.target.name;
22-
23- if (name === "app-id") setAppId(e.target.value);
24- if (name === "token") setToken(e.target.value);
25- if (name === "channel") setChannel(e.target.value);
26-
27- // Clear the error if it exists after a new change
28- if (error) setError("");
29- },
30- [error, setAppId, setToken, setChannel],
31- );
32-
33- const handleNextClick = useCallback(() => {
34- if (!appId || !token || !channel) setError("All fields are required.");
35- else {
36- const slug = slugify(channel);
37- router.push("/" + slug + "/host");
38- }
39- }, [appId, token, channel, router]);
40-
41- return (
42- <div className="flex flex-col items-center gap-8">
43- <h3
44- className={`text-2xl font-bold p-16 text-rose-300 ${pacifico.className}`}
45- >
46- Please fill in the details bellow,
47- </h3>
48- <p>
49- All this information can be acquired from the{" "}
50- <Link
51- className="text-rose-600 active:text-rose-300 visited:text-rose-800"
52- target="_blank"
53- href="https://console.agora.io/v2/project-management"
54- >
55- AgoraIO Console
56- </Link>
57- </p>
58- <div className="w-1/2 flex flex-col gap-4">
59- <label>Tell us your App ID from AgoraIO</label>
60- <input
61- className="text-stone-200 bg-stone-800 rounded-xl p-4 w-full placeholder:text-stone-700"
62- name="app-id"
63- type="text"
64- value={appId}
65- onChange={handleChange}
66- placeholder="Your app id here..."
67- />
68- </div>
69-
70- <div className="w-1/2 flex flex-col gap-4">
71- <label>Tell us your AgoraIO token</label>
72- <input
73- className="text-stone-200 bg-stone-800 rounded-xl p-4 w-full placeholder:text-stone-700"
74- name="token"
75- type="text"
76- value={token}
77- onChange={handleChange}
78- placeholder="Your token here..."
79- />
80- </div>
81-
82- <div className="w-1/2 flex flex-col gap-4">
83- <label>Tell us your AgoraIO channel name</label>
84- <input
85- className="text-stone-200 bg-stone-800 rounded-xl p-4 w-full placeholder:text-stone-700"
86- name="channel"
87- type="text"
88- value={channel}
89- onChange={handleChange}
90- placeholder="Your token here..."
91- />
92- </div>
93-
94- <div className="w-1/2 flex flex-col gap-4">
95- <button onClick={handleNextClick}>
96- <PrimaryButton>
97- <p className="px-4 py-2">Next</p>
98- </PrimaryButton>
99- </button>
100- {error && <p className="text-rose-600">{error}</p>}
101- </div>
102- </div>
103- );
104-}
app/page.tsx+51−6
@@ -1,17 +1,62 @@
1-import Link from "next/link";
1+"use client";
2+
3+import { useRouter } from "next/navigation";
4+import { useCallback, useState } from "react";
5+
6+import slugify from "@/lib/slugify";
27
38 import Logo from "../components/logo";
49 import PrimaryButton from "../components/primary-button";
510
611 export default function Home() {
12+ const [title, setTitle] = useState("");
13+ const [error, setError] = useState("");
14+
15+ const router = useRouter();
16+
17+ const handleChange = useCallback(
18+ (e: React.ChangeEvent<HTMLInputElement>) => {
19+ setTitle(e.target.value);
20+ // Clear the error if it exists after a new change
21+ if (error) setError("");
22+ },
23+ [error, setTitle],
24+ );
25+
26+ const handleNextClick = useCallback(() => {
27+ if (!title) setError("Please tell us the title of your stream first.");
28+ else {
29+ const slug = slugify(title);
30+ router.push("/" + slug + "/host");
31+ }
32+ }, [title, router]);
33+
734 return (
835 <main className="flex min-h-screen flex-col items-center justify-start p-8 gap-20">
936 <Logo />
10- <Link href="/new">
11- <PrimaryButton>
12- <p className="px-4 py-2 text-2xl">Go live now!</p>
13- </PrimaryButton>
14- </Link>
37+
38+ <div className="w-1/2 flex flex-col gap-4">
39+ <label>What is the title of your stream?</label>
40+ <input
41+ className="text-stone-200 bg-stone-800 rounded-xl p-4 w-full placeholder:text-stone-700"
42+ name="title"
43+ type="text"
44+ value={title}
45+ onChange={handleChange}
46+ placeholder="Stream title here..."
47+ />
48+ {error && <p className="text-rose-600">{error}</p>}
49+ </div>
50+
51+ <div className="w-1/2 flex flex-col gap-4">
52+ <div className="text-center">
53+ <button onClick={handleNextClick}>
54+ <PrimaryButton>
55+ <p className="px-4 py-2">Go Live!</p>
56+ </PrimaryButton>
57+ </button>
58+ </div>
59+ </div>
1560 </main>
1661 );
1762 }
components/agora-host-video.tsx+7−7
@@ -23,11 +23,11 @@ import { Modal } from "./modal";
2323 import PrimaryButton from "./primary-button";
2424 import SecondaryButton from "./secondary-button";
2525
26-export default function AgoraHost({
27- config: { appId, channel, token },
28-}: {
29- config: { appId: string; channel: string; token: string };
30-}) {
26+const appId = process.env.NEXT_PUBLIC_APP_ID ?? "";
27+const token = process.env.NEXT_PUBLIC_TOKEN ?? "";
28+const channel = process.env.NEXT_PUBLIC_CHANNEL ?? "";
29+
30+export default function AgoraHost() {
3131 const [showSettingsModal, setShowSettingsModal] = useState(false);
3232
3333 const [callStarted, setCallStarted] = useState(false);
@@ -89,7 +89,7 @@ export default function AgoraHost({
8989
9090 return (
9191 <div className="flex flex-col gap-8 w-full items-center">
92- <div className="rounded-3xl overflow-hidden bg-black w-1/2 h-80">
92+ <div className="rounded-3xl overflow-hidden bg-black w-full max-w-2xl aspect-[4/3]">
9393 <LocalUser
9494 audioTrack={localMicrophoneTrack}
9595 videoTrack={localCameraTrack}
@@ -153,7 +153,7 @@ export default function AgoraHost({
153153 return (
154154 <div
155155 key={host.uid}
156- className="rounded-3xl overflow-hidden bg-black w-1/2 h-80"
156+ className="rounded-3xl overflow-hidden bg-black w-full max-w-2xl aspect-[4/3]"
157157 >
158158 <RemoteUser user={host}>
159159 <p className="p-4">{host.uid}</p>