feat: voice dashboard
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user