chore: floating button for incoming call
This commit is contained in:
@@ -1,30 +1,77 @@
|
||||
const state = {
|
||||
activeCall: null,
|
||||
incomingCall: null,
|
||||
};
|
||||
|
||||
const getters = {
|
||||
getActiveCall: $state => $state.activeCall,
|
||||
hasActiveCall: $state => !!$state.activeCall,
|
||||
getIncomingCall: $state => $state.incomingCall,
|
||||
hasIncomingCall: $state => !!$state.incomingCall,
|
||||
};
|
||||
|
||||
const actions = {
|
||||
setActiveCall({ commit }, callData) {
|
||||
console.log('Setting active call in store:', callData);
|
||||
if (!callData || !callData.callSid) {
|
||||
throw new Error('Invalid call data provided');
|
||||
}
|
||||
|
||||
commit('SET_ACTIVE_CALL', callData);
|
||||
|
||||
// If we're in a browser environment, try to set the app state
|
||||
// Update app state if in browser environment
|
||||
if (typeof window !== 'undefined' && window.app?.$data) {
|
||||
window.app.$data.showCallWidget = true;
|
||||
}
|
||||
},
|
||||
|
||||
clearActiveCall({ commit }) {
|
||||
commit('CLEAR_ACTIVE_CALL');
|
||||
|
||||
// Update app state if in browser environment
|
||||
if (typeof window !== 'undefined' && window.app?.$data) {
|
||||
window.app.$data.showCallWidget = false;
|
||||
}
|
||||
},
|
||||
|
||||
setIncomingCall({ commit, state }, callData) {
|
||||
if (!callData || !callData.callSid) {
|
||||
throw new Error('Invalid call data provided');
|
||||
}
|
||||
|
||||
// Don't set as incoming if call is already active
|
||||
if (state.activeCall?.callSid === callData.callSid) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't set as incoming if call is already incoming
|
||||
if (state.incomingCall?.callSid === callData.callSid) {
|
||||
return;
|
||||
}
|
||||
|
||||
commit('SET_INCOMING_CALL', callData);
|
||||
|
||||
// Update app state if in browser environment
|
||||
if (typeof window !== 'undefined' && window.app && window.app.$data) {
|
||||
window.app.$data.showCallWidget = true;
|
||||
}
|
||||
},
|
||||
clearActiveCall({ commit }) {
|
||||
console.log('Clearing active call in store');
|
||||
commit('CLEAR_ACTIVE_CALL');
|
||||
|
||||
// If we're in a browser environment, try to clear the app state
|
||||
if (typeof window !== 'undefined' && window.app && window.app.$data) {
|
||||
window.app.$data.showCallWidget = false;
|
||||
clearIncomingCall({ commit }) {
|
||||
commit('CLEAR_INCOMING_CALL');
|
||||
},
|
||||
|
||||
acceptIncomingCall({ commit, state }) {
|
||||
const incomingCall = state.incomingCall;
|
||||
if (!incomingCall) {
|
||||
throw new Error('No incoming call to accept');
|
||||
}
|
||||
|
||||
// Move incoming call to active call
|
||||
commit('SET_ACTIVE_CALL', {
|
||||
...incomingCall,
|
||||
isJoined: true,
|
||||
});
|
||||
commit('CLEAR_INCOMING_CALL');
|
||||
},
|
||||
};
|
||||
|
||||
@@ -35,6 +82,12 @@ const mutations = {
|
||||
CLEAR_ACTIVE_CALL($state) {
|
||||
$state.activeCall = null;
|
||||
},
|
||||
SET_INCOMING_CALL($state, callData) {
|
||||
$state.incomingCall = callData;
|
||||
},
|
||||
CLEAR_INCOMING_CALL($state) {
|
||||
$state.incomingCall = null;
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
Reference in New Issue
Block a user