@@ -2,14 +2,24 @@
22
33 import {
44 LocalUser,
5+ RemoteUser,
6+ useIsConnected,
57 useJoin,
68 useLocalCameraTrack,
79 useLocalMicrophoneTrack,
810 usePublish,
11+ useRemoteUsers,
912 } from "agora-rtc-react";
1013 import { useCallback, useState } from "react";
14+import { AiOutlineAudio as UnmuteIcon } from "react-icons/ai";
15+import { AiOutlineAudioMuted as MuteIcon } from "react-icons/ai";
16+import { CiStreamOn as StreamOnIcon } from "react-icons/ci";
17+import { CiStreamOff as StreamOffIcon } from "react-icons/ci";
18+import { IoVideocamOutline as VideoOnIcon } from "react-icons/io5";
19+import { IoVideocamOffOutline as VideoOffIcon } from "react-icons/io5";
1120
1221 import PrimaryButton from "./primary-button";
22+import SecondaryButton from "./secondary-button";
1323
1424 export default function AgoraHost({
1525 config: { appId, channel, token },
@@ -18,20 +28,33 @@ export default function AgoraHost({
1828 }) {
1929 const [callStarted, setCallStarted] = useState(false);
2030 const [videoStarted, setVideoStarted] = useState(false);
21- const [muted, setMuted] = useState(false);
31+ const [audioStarted, setAudioStarted] = useState(false);
2232
23- const { localMicrophoneTrack } = useLocalMicrophoneTrack(!muted);
33+ const { localMicrophoneTrack } = useLocalMicrophoneTrack(audioStarted);
2434 const { localCameraTrack } = useLocalCameraTrack(videoStarted);
2535
26- const handleCall = useCallback(() => {
36+ const isConnected = useIsConnected();
37+
38+ const handleStarCall = useCallback(() => {
2739 setCallStarted(true);
28- setVideoStarted(true);
2940 }, []);
3041
42+ const handleEndCall = useCallback(() => {
43+ setCallStarted(false);
44+ }, []);
45+
46+ const handleToggleAudio = useCallback(() => {
47+ setAudioStarted(!audioStarted);
48+ }, [audioStarted]);
49+
50+ const handleToggleVideo = useCallback(() => {
51+ setVideoStarted(!videoStarted);
52+ }, [videoStarted]);
53+
3154 useJoin(
3255 {
3356 appid: appId,
34- channel: "stream-together",
57+ channel,
3558 token,
3659 },
3760 callStarted,
@@ -39,22 +62,82 @@ export default function AgoraHost({
3962
4063 usePublish([localMicrophoneTrack, localCameraTrack]);
4164
65+ const otherHosts = useRemoteUsers();
66+
4267 return (
43- <div className="flex flex-col gap-8">
44- <div style={{ width: 640, height: 480 }}>
68+ <div className="flex flex-col gap-8 w-full items-center">
69+ <div className="rounded-3xl overflow-hidden bg-black w-1/2 h-80">
4570 <LocalUser
4671 audioTrack={localMicrophoneTrack}
4772 videoTrack={localCameraTrack}
4873 cameraOn={videoStarted}
49- micOn={!muted}
74+ micOn={audioStarted}
5075 >
51- You
76+ <div className="flex flex-col justify-between h-full p-2">
77+ <p className="p-2">Your broadcast</p>
78+ {callStarted && isConnected ? (
79+ <div className="flex flex-row justify-center gap-4">
80+ <button
81+ onClick={handleToggleAudio}
82+ title={audioStarted ? "Mute" : "Unmute"}
83+ >
84+ <SecondaryButton>
85+ {audioStarted ? (
86+ <MuteIcon className="p-2" size="3em" />
87+ ) : (
88+ <UnmuteIcon className="p-2" size="3em" />
89+ )}
90+ </SecondaryButton>
91+ </button>
92+ <button
93+ onClick={handleToggleVideo}
94+ title={videoStarted ? "Turn video off" : "Turn video on"}
95+ >
96+ <SecondaryButton>
97+ {videoStarted ? (
98+ <VideoOffIcon className="p-2" size="3em" />
99+ ) : (
100+ <VideoOnIcon className="p-2" size="3em" />
101+ )}
102+ </SecondaryButton>
103+ </button>
104+ <button onClick={handleEndCall} title="End stream">
105+ <PrimaryButton>
106+ <StreamOffIcon className="p-1" size="3em" />
107+ </PrimaryButton>
108+ </button>
109+ </div>
110+ ) : callStarted ? (
111+ <div>Loading...</div>
112+ ) : (
113+ <div className="text-center">
114+ <button onClick={handleStarCall} title="Go live!">
115+ <PrimaryButton>
116+ <div className="flex flex-row items-center px-2 gap-2">
117+ <p>Go live!</p>
118+ <StreamOnIcon className="p-1" size="3em" />
119+ </div>
120+ </PrimaryButton>
121+ </button>
122+ </div>
123+ )}
124+ </div>
52125 </LocalUser>
53126 </div>
54127
55- <button onClick={handleCall}>
56- <PrimaryButton>Call</PrimaryButton>
57- </button>
128+ {otherHosts.map((host) => {
129+ console.log(host);
130+ return (
131+ <div
132+ key={host.uid}
133+ className="rounded-3xl overflow-hidden bg-black w-1/2 h-80"
134+ >
135+ <RemoteUser user={host}>
136+ <p className="p-4">{host.uid}</p>
137+ </RemoteUser>
138+ </div>
139+ );
140+ })}
58141 </div>
59142 );
60143 }