feat: DM voice (draft)

This commit is contained in:
Tristan Yang
2023-05-09 21:35:22 +08:00
parent 6055a2d1e2
commit 118f802e86
9 changed files with 411 additions and 161 deletions
+15 -3
View File
@@ -19,7 +19,8 @@ import {
RenewLicenseResponse,
AgoraTokenResponse,
AgoraVoicingListResponse,
SystemCommon
SystemCommon,
AgoraChannelUsersResponse
} from "../../types/server";
import { Channel } from "../../types/channel";
import { ContentTypeKey } from "../../types/message";
@@ -130,7 +131,8 @@ export const serverApi = createApi({
return {
id: +id,
context,
memberCount: count
memberCount: count,
channelName: data.channel_name
};
});
dispatch(upsertVoiceList(arr));
@@ -140,6 +142,15 @@ export const serverApi = createApi({
}
}
}),
getAgoraUsersByChannel: builder.query<number[], string>({
query: (channel_name) => ({ url: `/admin/agora/channel/user/${channel_name}/false` }),
transformResponse: (resp: AgoraChannelUsersResponse) => {
if (resp.success && resp.data.channel_exist) {
return resp.data.users ?? [];
}
return [];
}
}),
updateAgoraConfig: builder.mutation<void, AgoraConfig>({
query: (data) => ({
url: `/admin/agora/config`,
@@ -405,5 +416,6 @@ export const {
useUpdateSystemCommonMutation,
useLazyGetSystemCommonQuery,
useGetSystemCommonQuery,
useGenerateAgoraTokenMutation
useGenerateAgoraTokenMutation,
useLazyGetAgoraUsersByChannelQuery
} = serverApi;
+20 -5
View File
@@ -4,8 +4,9 @@ import { ConnectionState } from "agora-rtc-sdk-ng";
import { resetAuthData } from "./auth.data";
export type VoiceBasicInfo = {
context: "channel" | "dm"
id: number,
context: "channel" | "dm",
from?: number,
id: number,// means to in dm context
}
export type VoicingInfo = {
@@ -34,9 +35,12 @@ export type VoicingMembers = {
pin?: number
}
export type VoiceInfo = {
channelName: string,
memberCount: number
} & VoiceBasicInfo
interface State {
callingFrom: number,
callingTo: number,
voicing: VoicingInfo | null,
voicingMembers: VoicingMembers,
list: VoiceInfo[]
@@ -47,6 +51,8 @@ interface State {
// members: []
// };
const initialState: State = {
callingFrom: 0,
callingTo: 0,
voicing: null,
voicingMembers: {
ids: [],
@@ -61,6 +67,11 @@ const voiceSlice = createSlice({
name: "voice",
initialState,
reducers: {
updateCalling(state, { payload }: PayloadAction<{ from: number, to?: number }>) {
const { from, to = 0 } = payload;
state.callingFrom = from;
state.callingTo = to;
},
updateVoicingInfo(state, { payload }: PayloadAction<VoicingInfo | null>) {
if (payload) {
state.voicing = { ...(state.voicing ?? {}), ...payload };
@@ -157,11 +168,15 @@ const voiceSlice = createSlice({
if (window.VOICE_CLIENT) {
window.VOICE_CLIENT.leave();
Object.entries(window.VOICE_TRACK_MAP).forEach(([uid, track]) => {
track?.close();
if (track && 'close' in track) {
track.close();
}
delete window.VOICE_TRACK_MAP[+uid];
});
Object.entries(window.VIDEO_TRACK_MAP).forEach(([uid, track]) => {
track?.close();
if (track && 'close' in track) {
track?.close();
}
delete window.VOICE_TRACK_MAP[+uid];
});
}
@@ -174,5 +189,5 @@ const voiceSlice = createSlice({
}
});
export const { updatePin, updateConnectionState, addVoiceMember, removeVoiceMember, upsertVoiceList, updateVoicingInfo, updateVoicingNetworkQuality, updateMuteStatus, updateVoicingMember, updateDeafenStatus } = voiceSlice.actions;
export const { updateCalling, updatePin, updateConnectionState, addVoiceMember, removeVoiceMember, upsertVoiceList, updateVoicingInfo, updateVoicingNetworkQuality, updateMuteStatus, updateVoicingMember, updateDeafenStatus } = voiceSlice.actions;
export default voiceSlice.reducer;