import { PayloadAction, createSlice } from '@reduxjs/toolkit'; import { Logger } from '../../utils/Log'; import { ICurrentCallState } from './types'; import { currentCallService } from '../../services/calls'; const logger = new Logger('conversationsSlice'); const initialState: ICurrentCallState = { isMuted: false, isSpeakerOn: false, startingCall: false } const currentCallSlice = createSlice({ name: 'currentCall', initialState, reducers: { retrieveCurrentCall(){ currentCallService.retrieveCurrentCall(); }, muteCurrentCall(){ currentCallService.mute(); }, unMuteCurrentCall(state){ currentCallService.unMute(); }, getMicState(){ currentCallService.getMicState(); }, setMicStateUpdates(state, action: PayloadAction){ state.isMuted = action.payload; }, switchSpeakerState(){ currentCallService.sendSwitchSpeakerState(); }, getSpeakerState(){ currentCallService.getSpeakerState(); }, setSpeakerStateUpdates(state, action:PayloadAction){ state.isSpeakerOn = action.payload; }, sendDTMFSignal(state, action: PayloadAction){ currentCallService.sendDTMF(action.payload); }, switchMicState(){ currentCallService.switchMicState(); } } }); // Export action creators and reducer export const { retrieveCurrentCall, muteCurrentCall, unMuteCurrentCall, getMicState, setMicStateUpdates, switchSpeakerState, getSpeakerState, setSpeakerStateUpdates, sendDTMFSignal, switchMicState } = currentCallSlice.actions; export default currentCallSlice.reducer;