@@ -1,6 +1,6 @@
11 "use client";
22
3-import {
3+import AgoraRTC, {
44 LocalUser,
55 RemoteUser,
66 useIsConnected,
@@ -10,14 +10,16 @@ import {
1010 usePublish,
1111 useRemoteUsers,
1212 } from "agora-rtc-react";
13-import { useCallback, useState } from "react";
13+import { useCallback, useEffect, useState } from "react";
1414 import { AiOutlineAudio as UnmuteIcon } from "react-icons/ai";
1515 import { AiOutlineAudioMuted as MuteIcon } from "react-icons/ai";
1616 import { CiStreamOn as StreamOnIcon } from "react-icons/ci";
1717 import { CiStreamOff as StreamOffIcon } from "react-icons/ci";
18+import { GoGear as GearIcon } from "react-icons/go";
1819 import { IoVideocamOutline as VideoOnIcon } from "react-icons/io5";
1920 import { IoVideocamOffOutline as VideoOffIcon } from "react-icons/io5";
2021
22+import { Modal } from "./modal";
2123 import PrimaryButton from "./primary-button";
2224 import SecondaryButton from "./secondary-button";
2325
@@ -26,12 +28,33 @@ export default function AgoraHost({
2628 }: {
2729 config: { appId: string; channel: string; token: string };
2830 }) {
31+ const [showSettingsModal, setShowSettingsModal] = useState(false);
32+
2933 const [callStarted, setCallStarted] = useState(false);
3034 const [videoStarted, setVideoStarted] = useState(false);
3135 const [audioStarted, setAudioStarted] = useState(false);
3236
37+ const [availableCameras, setAvailableCameras] = useState<
38+ { id: string; label: string }[]
39+ >([]);
40+ const [selectedCameraId, setSelectedCameraId] = useState("");
41+
42+ useEffect(() => {
43+ const getCameras = async () => {
44+ const cameras = await AgoraRTC.getCameras();
45+ setAvailableCameras(
46+ cameras.map((c) => ({ id: c.deviceId, label: c.label })),
47+ );
48+ // Choose the first one as a default
49+ setSelectedCameraId(cameras[0].deviceId);
50+ };
51+ getCameras();
52+ }, []);
53+
3354 const { localMicrophoneTrack } = useLocalMicrophoneTrack(audioStarted);
34- const { localCameraTrack } = useLocalCameraTrack(videoStarted);
55+ const { localCameraTrack } = useLocalCameraTrack(videoStarted, {
56+ cameraId: selectedCameraId,
57+ });
3558
3659 const isConnected = useIsConnected();
3760
@@ -138,6 +161,51 @@ export default function AgoraHost({
138161 </div>
139162 );
140163 })}
164+
165+ <Modal
166+ openButton={
167+ <button onClick={() => setShowSettingsModal(!showSettingsModal)}>
168+ <SecondaryButton>
169+ <div className="py-2 px-4 flex flex-row gap-2 items-center">
170+ <GearIcon size="2em" />
171+ <p>Settings</p>
172+ </div>
173+ </SecondaryButton>
174+ </button>
175+ }
176+ showModal={showSettingsModal}
177+ >
178+ <div className="p-4 bg-stone-800 rounded-2xl flex flex-col gap-4">
179+ <div>
180+ <h4 className="font-bold pb-4">Select your video device:</h4>
181+ {availableCameras.map((c) => {
182+ return (
183+ <label key={c.id} className="flex flex-row gap-2">
184+ <input
185+ type="radio"
186+ name="selected-camera"
187+ value={c.id}
188+ checked={c.id === selectedCameraId}
189+ onChange={(e) => {
190+ const id = e.target.value;
191+ setSelectedCameraId(id);
192+ }}
193+ />
194+ <div>{c.label}</div>
195+ </label>
196+ );
197+ })}
198+ </div>
199+
200+ <div className="text-center">
201+ <button onClick={() => setShowSettingsModal(false)}>
202+ <PrimaryButton>
203+ <p className="px-4 py-2">Close</p>
204+ </PrimaryButton>
205+ </button>
206+ </div>
207+ </div>
208+ </Modal>
141209 </div>
142210 );
143211 }