xonecas.io
4828
Sr

stream-together / files

stream-together / components / agora-provider.tsx

882 bytes
1"use client";
2
3import { AgoraRTCProvider, IAgoraRTCClient } from "agora-rtc-react";
4import { useEffect, useState } from "react";
5import { ImSpinner10 } from "react-icons/im";
6
7export default function AgoraProvider({
8  children,
9}: Readonly<{
10  children: React.ReactNode;
11}>) {
12  const [client, setClient] = useState<IAgoraRTCClient | null>(null);
13
14  useEffect(() => {
15    const initializeAgoraSDK = async () => {
16      const AgoraRTC = (await import("agora-rtc-react")).default;
17      const agoraClient = AgoraRTC.createClient({ mode: "rtc", codec: "vp8" });
18
19      setClient(agoraClient);
20    };
21
22    initializeAgoraSDK();
23  }, []);
24
25  return client ? (
26    <AgoraRTCProvider client={client}>{children}</AgoraRTCProvider>
27  ) : (
28    <div className="flex flex-col flex-grow items-center justify-center">
29      <ImSpinner10 size="4rem" className="animate-spin" />
30    </div>
31  );
32}