feat: voice dashboard

This commit is contained in:
Tristan Yang
2023-03-24 11:05:51 +08:00
parent ecfa3b8f24
commit da00f3b797
10 changed files with 100 additions and 32 deletions
+30 -24
View File
@@ -3,20 +3,24 @@ import AgoraRTC from "agora-rtc-sdk-ng";
import useConfig from '../../../common/hook/useConfig';
import { useDispatch } from 'react-redux';
import { updateVoiceStatus } from '../../../app/slices/auth.data';
import { useLazyGetAgoraTokenQuery } from '../../../app/services/server';
import VoiceManagement from './VoiceManagement';
import JoinVoice from './JoinVoice';
type Props = {
channel: string,
id: number,
uid: number,
voicing?: boolean;
}
const Dashboard = ({ voicing, uid, channel }: Props) => {
const Dashboard = ({ id, voicing, uid, channel }: Props) => {
const dispatch = useDispatch();
console.log("aaaaa");
const [generateToken] = useLazyGetAgoraTokenQuery();
const { agoraConfig } = useConfig("agora");
useEffect(() => {
console.log("aaa", agoraConfig);
console.log("agora config", agoraConfig);
const startConnect = async () => {
// Create an instance of the Agora Engine
const agoraEngine = AgoraRTC.createClient({ mode: "rtc", codec: "vp8" });
@@ -27,17 +31,16 @@ const Dashboard = ({ voicing, uid, channel }: Props) => {
await agoraEngine.subscribe(user, mediaType);
console.log("subscribe success");
// // Subscribe and play the remote audio track.
// if (mediaType == "audio")
// {
// channelParameters.remoteUid=user.uid;
// // Get the RemoteAudioTrack object from the AgoraRTCRemoteUser object.
// channelParameters.remoteAudioTrack = user.audioTrack;
// // Play the remote audio track.
// channelParameters.remoteAudioTrack.play();
// console.log("Remote user connected: " + user.uid);
// Subscribe and play the remote audio track.
if (mediaType == "audio") {
// channelParameters.remoteUid=user.uid;
// // Get the RemoteAudioTrack object from the AgoraRTCRemoteUser object.
// channelParameters.remoteAudioTrack = user.audioTrack;
// Play the remote audio track.
user.audioTrack?.play();
console.log("Remote user connected: " + user.uid);
// }
}
// Listen for the "user-unpublished" event.
agoraEngine.on("user-unpublished", user => {
@@ -47,14 +50,19 @@ const Dashboard = ({ voicing, uid, channel }: Props) => {
});
// Join a channel.
console.log("join data ", agoraConfig);
await agoraEngine.join(agoraConfig!.app_id, agoraConfig!.rtm_key, agoraConfig!.rtm_secret, uid);
console.log("Joined channel: " + agoraConfig!.rtm_key);
// // Create a local audio track from the microphone audio.
// channelParameters.localAudioTrack = await AgoraRTC.createMicrophoneAudioTrack();
// // Publish the local audio track in the channel.
// await agoraEngine.publish(channelParameters.localAudioTrack);
// console.log("Publish success!");
dispatch(updateVoiceStatus(true));
const { isError, data } = await generateToken(id);
if (!isError && data) {
const { channel_name, app_id, agora_token, uid } = data;
await agoraEngine.join(app_id, channel_name, agora_token, uid);
console.table(data);
// Create a local audio track from the microphone audio.
const localAudioTrack = await AgoraRTC.createMicrophoneAudioTrack();
// Publish the local audio track in the channel.
await agoraEngine.publish(localAudioTrack);
console.log("Publish success!");
dispatch(updateVoiceStatus(true));
}
};
if (!voicing && agoraConfig) {
@@ -62,9 +70,7 @@ const Dashboard = ({ voicing, uid, channel }: Props) => {
}
}, [voicing, agoraConfig, uid, channel]);
return (
<div>Dashboard</div>
);
return voicing ? <VoiceManagement /> : <JoinVoice />;
};
export default Dashboard;