style: format ts file with prettier
This commit is contained in:
+56
-46
@@ -1,53 +1,55 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { KEY_UID } from "../config";
|
||||
import { ConnectionState } from "agora-rtc-sdk-ng";
|
||||
import { resetAuthData } from "./auth.data";
|
||||
|
||||
import { ChatContext } from "@/types/common";
|
||||
import { KEY_UID } from "../config";
|
||||
import { resetAuthData } from "./auth.data";
|
||||
|
||||
export type VoiceBasicInfo = {
|
||||
context: ChatContext,
|
||||
from?: number,
|
||||
id: number,// means to in dm context
|
||||
}
|
||||
context: ChatContext;
|
||||
from?: number;
|
||||
id: number; // means to in dm context
|
||||
};
|
||||
|
||||
export type VoicingInfo = {
|
||||
downlinkNetworkQuality?: number,
|
||||
joining?: boolean,
|
||||
connectionState?: ConnectionState
|
||||
} & VoiceBasicInfo & VoicingMemberInfo
|
||||
downlinkNetworkQuality?: number;
|
||||
joining?: boolean;
|
||||
connectionState?: ConnectionState;
|
||||
} & VoiceBasicInfo &
|
||||
VoicingMemberInfo;
|
||||
|
||||
export type VoicingMemberInfo = {
|
||||
speakingVolume?: number,
|
||||
muted?: boolean,
|
||||
deafen?: boolean,
|
||||
video?: boolean,
|
||||
shareScreen?: boolean
|
||||
}
|
||||
speakingVolume?: number;
|
||||
muted?: boolean;
|
||||
deafen?: boolean;
|
||||
video?: boolean;
|
||||
shareScreen?: boolean;
|
||||
};
|
||||
|
||||
export type VoicingMembers = {
|
||||
ids: number[],
|
||||
ids: number[];
|
||||
byId: {
|
||||
[key: number]: VoicingMemberInfo
|
||||
},
|
||||
pin?: number
|
||||
}
|
||||
[key: number]: VoicingMemberInfo;
|
||||
};
|
||||
pin?: number;
|
||||
};
|
||||
export type VoiceInfo = {
|
||||
channelName: string,
|
||||
memberCount: number
|
||||
} & VoiceBasicInfo
|
||||
channelName: string;
|
||||
memberCount: number;
|
||||
} & VoiceBasicInfo;
|
||||
export type DeviceInfo = Pick<MediaDeviceInfo, "deviceId" | "groupId" | "kind" | "label">;
|
||||
export type MediaDeviceKind = "audioinput" | "audiooutput" | "videoinput"
|
||||
export type MediaDeviceKind = "audioinput" | "audiooutput" | "videoinput";
|
||||
interface State {
|
||||
callingFrom: number,
|
||||
callingTo: number,
|
||||
calling: boolean,
|
||||
voicing: VoicingInfo | null,
|
||||
voicingMembers: VoicingMembers,
|
||||
list: VoiceInfo[],
|
||||
devices: DeviceInfo[],
|
||||
audioInputDeviceId: string,
|
||||
audioOutputDeviceId: string,
|
||||
videoInputDeviceId: string,
|
||||
callingFrom: number;
|
||||
callingTo: number;
|
||||
calling: boolean;
|
||||
voicing: VoicingInfo | null;
|
||||
voicingMembers: VoicingMembers;
|
||||
list: VoiceInfo[];
|
||||
devices: DeviceInfo[];
|
||||
audioInputDeviceId: string;
|
||||
audioOutputDeviceId: string;
|
||||
videoInputDeviceId: string;
|
||||
}
|
||||
const initialState: State = {
|
||||
calling: false,
|
||||
@@ -68,7 +70,10 @@ const voiceSlice = createSlice({
|
||||
name: "voice",
|
||||
initialState,
|
||||
reducers: {
|
||||
updateCallInfo(state, { payload }: PayloadAction<{ from: number, to?: number, calling?: boolean }>) {
|
||||
updateCallInfo(
|
||||
state,
|
||||
{ payload }: PayloadAction<{ from: number; to?: number; calling?: boolean }>
|
||||
) {
|
||||
const { from, to = 0, calling } = payload;
|
||||
state.callingFrom = from;
|
||||
state.callingTo = to;
|
||||
@@ -80,9 +85,9 @@ const voiceSlice = createSlice({
|
||||
state.devices = payload;
|
||||
if (payload.length > 0) {
|
||||
// 默认选择第一个
|
||||
const audioInputDevice = payload.find(v => v.kind == "audioinput");
|
||||
const audioOutputDevice = payload.find(v => v.kind == "audiooutput");
|
||||
const videoInputDevice = payload.find(v => v.kind == "videoinput");
|
||||
const audioInputDevice = payload.find((v) => v.kind == "audioinput");
|
||||
const audioOutputDevice = payload.find((v) => v.kind == "audiooutput");
|
||||
const videoInputDevice = payload.find((v) => v.kind == "videoinput");
|
||||
if (audioInputDevice) {
|
||||
state.audioInputDeviceId = audioInputDevice.deviceId;
|
||||
}
|
||||
@@ -97,7 +102,10 @@ const voiceSlice = createSlice({
|
||||
updateCalling(state, { payload }: PayloadAction<boolean>) {
|
||||
state.calling = payload;
|
||||
},
|
||||
updateSelectDeviceId(state, { payload }: PayloadAction<{ kind: MediaDeviceKind, value: string }>) {
|
||||
updateSelectDeviceId(
|
||||
state,
|
||||
{ payload }: PayloadAction<{ kind: MediaDeviceKind; value: string }>
|
||||
) {
|
||||
const { kind, value } = payload;
|
||||
switch (kind) {
|
||||
case "audioinput":
|
||||
@@ -152,7 +160,6 @@ const voiceSlice = createSlice({
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
// reset
|
||||
state.voicing = payload;
|
||||
@@ -177,7 +184,7 @@ const voiceSlice = createSlice({
|
||||
state.list = payload;
|
||||
} else {
|
||||
const { id, context } = payload;
|
||||
const idx = state.list.findIndex(v => v.id == id && v.context == context);
|
||||
const idx = state.list.findIndex((v) => v.id == id && v.context == context);
|
||||
if (idx > -1) {
|
||||
state.list.splice(idx, 1, payload);
|
||||
} else {
|
||||
@@ -203,14 +210,17 @@ const voiceSlice = createSlice({
|
||||
delete state.voicingMembers.byId[payload];
|
||||
}
|
||||
},
|
||||
updateVoicingMember(state, { payload }: PayloadAction<{ uid: number, info: VoicingMemberInfo }>) {
|
||||
updateVoicingMember(
|
||||
state,
|
||||
{ payload }: PayloadAction<{ uid: number; info: VoicingMemberInfo }>
|
||||
) {
|
||||
const idx = state.voicingMembers.ids.findIndex((uid) => uid == payload.uid);
|
||||
if (idx > -1) {
|
||||
const { uid, info } = payload;
|
||||
state.voicingMembers.byId[uid] = { ...state.voicingMembers.byId[uid], ...info };
|
||||
}
|
||||
},
|
||||
updatePin(state, { payload }: PayloadAction<{ uid: number, action: "pin" | "unpin" }>) {
|
||||
updatePin(state, { payload }: PayloadAction<{ uid: number; action: "pin" | "unpin" }>) {
|
||||
const idx = state.voicingMembers.ids.findIndex((uid) => uid == payload.uid);
|
||||
if (idx > -1) {
|
||||
state.voicingMembers.pin = payload.action == "pin" ? payload.uid : undefined;
|
||||
@@ -223,13 +233,13 @@ const voiceSlice = createSlice({
|
||||
if (window.VOICE_CLIENT) {
|
||||
window.VOICE_CLIENT.leave();
|
||||
Object.entries(window.VOICE_TRACK_MAP).forEach(([uid, track]) => {
|
||||
if (track && 'close' in track) {
|
||||
if (track && "close" in track) {
|
||||
track.close();
|
||||
}
|
||||
delete window.VOICE_TRACK_MAP[+uid];
|
||||
});
|
||||
Object.entries(window.VIDEO_TRACK_MAP).forEach(([uid, track]) => {
|
||||
if (track && 'close' in track) {
|
||||
if (track && "close" in track) {
|
||||
track?.close();
|
||||
}
|
||||
delete window.VOICE_TRACK_MAP[+uid];
|
||||
|
||||
Reference in New Issue
Block a user