-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from brendantwh/voice
Add Agora.io for voice chat
- Loading branch information
Showing
5 changed files
with
368 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// credits to https://github.com/AgoraIO-Extensions/agora-rtc-react/issues/181#issuecomment-1886586029 | ||
|
||
"use client"; | ||
|
||
import { useState, useEffect, ReactNode, useRef } from "react"; | ||
import type { ClientConfig, IAgoraRTCClient } from "agora-rtc-react"; | ||
import dynamic from "next/dynamic"; | ||
|
||
const AgoraRTCProviderPrimitive = dynamic( | ||
() => | ||
import("agora-rtc-react").then(({ AgoraRTCProvider }) => AgoraRTCProvider), | ||
{ | ||
ssr: false, | ||
}, | ||
); | ||
|
||
export default function AgoraRTCProvider(props: { | ||
clientConfig: ClientConfig; | ||
children: ReactNode; | ||
}) { | ||
const clientConfigRef = useRef<ClientConfig>(props.clientConfig); | ||
const [client, setClient] = useState<IAgoraRTCClient>(); | ||
|
||
useEffect(() => { | ||
const initSdk = async () => { | ||
const AgoraRTC = (await import("agora-rtc-react")).default; | ||
setClient(AgoraRTC.createClient(clientConfigRef.current)); | ||
}; | ||
initSdk(); | ||
}, []); | ||
|
||
return ( | ||
client && ( | ||
<AgoraRTCProviderPrimitive client={client}> | ||
{props.children} | ||
</AgoraRTCProviderPrimitive> | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.