fix: join myself

This commit is contained in:
Tristan Yang
2023-03-30 11:36:30 +08:00
parent 7f655a5653
commit c1fc7040ad
2 changed files with 15 additions and 11 deletions
+13 -4
View File
@@ -1,4 +1,5 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { KEY_UID } from "../config";
export type VoiceBasicInfo = {
context: "channel" | "dm"
@@ -50,8 +51,8 @@ const voiceSlice = createSlice({
initialState,
reducers: {
updateVoicingInfo(state, { payload }: PayloadAction<VoicingInfo | null>) {
if (payload && state.voicing) {
state.voicing = { ...state.voicing, ...payload };
if (payload) {
state.voicing = { ...(state.voicing ?? {}), ...payload };
} else {
// reset
state.voicing = payload;
@@ -64,6 +65,12 @@ const voiceSlice = createSlice({
updateMuteStatus(state, { payload }: PayloadAction<boolean>) {
if (state.voicing) {
state.voicing.muted = payload;
// 更新登录用户在member list的状态
const loginUid = localStorage.getItem(KEY_UID) ?? 0;
const idx = state.voicingMembers.ids.findIndex((uid) => uid == loginUid);
if (idx > -1) {
state.voicingMembers.byId[+loginUid].muted = payload;
}
}
},
updateVoicingNetworkQuality(state, { payload }: PayloadAction<number>) {
@@ -75,8 +82,10 @@ const voiceSlice = createSlice({
state.list = payload;
},
addVoiceMember(state, { payload }: PayloadAction<number>) {
if (!state.voicingMembers.ids.includes(payload)) {
state.voicingMembers.ids.push(payload);
const notExisted = !state.voicingMembers.ids.includes(payload);
console.log("add voice member", payload, notExisted, state.voicingMembers.ids);
if (notExisted) {
state.voicingMembers.ids = [...state.voicingMembers.ids, payload];
state.voicingMembers.byId[payload] = {
speakingVolume: 0,
muted: false
+2 -7
View File
@@ -55,7 +55,7 @@ const Voice = () => {
case "ServerTimeOut": {
dispatch(removeVoiceMember(+user.uid as number));
console.log(user + "has left the channel");
console.log(user, "has left the channel");
}
break;
@@ -98,13 +98,8 @@ const Voice = () => {
});
// 有新用户加入
agoraEngine.on("user-joined", async (user) => {
// console.log(user.uid, !!localTrack, agoraEngine.channelName, " has joined the channel");
// if (localTrack) {
// joined
console.log(user.uid, !!localTrack, agoraEngine.channelName, " has joined the channel");
dispatch(addVoiceMember(+user.uid));
// } else {
// tmpUids.push(+user.uid);
// }
});
window.VOICE_CLIENT = agoraEngine;
};