fix: join myself
This commit is contained in:
+13
-4
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user