Skip to content

Commit

Permalink
feat: call offline hangup [WTEL-4031]
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohvinov committed Nov 9, 2023
1 parent 7c12dc4 commit 52e35dc
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/app/components/wt-omni-widget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ I don't remember why there's a keep-alive,

<script>
import eventBus from '@webitel/ui-sdk/src/scripts/eventBus';
import { mapActions } from 'vuex';
import WtOmniWidgetButtonsMenu from './wt-omni-widget-button/wt-omni-widget-buttons-menu.vue';
import WtOmniWidgetWindow from './wt-omni-widget-window/wt-omni-widget-window.vue';
import WtOmniWidgetPopup from './wt-omni-widget-popup/wt-omni-widget-popup.vue';
Expand Down Expand Up @@ -87,6 +88,9 @@ export default {
},
methods: {
...mapActions({
subsribeToNetworkConnectionStatus: 'SUBSCRIBE_TO_NETWORK_CONNECTION_STATUS',
}),
applyGlobalConfig() {
if(this.isPreviewMode === 'chat') this.activeChannel = WidgetChannel.CHAT; // Open chat preview if configuration contains chat preview property
if (this.config.view.lang) this.$i18n.locale = this.config.view.lang;
Expand Down Expand Up @@ -115,6 +119,7 @@ export default {
},
created() {
this.subsribeToNetworkConnectionStatus();
this.applyGlobalConfig();
eventBus.$on(GlobalEvent.SET_ACTIVE_WIDGET_CHANNEL, this.setActiveChannel);
},
Expand Down
14 changes: 14 additions & 0 deletions src/app/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@ Vue.use(Vuex);

const state = {
config: {},
offline: false,
};

const actions = {
SUBSCRIBE_TO_NETWORK_CONNECTION_STATUS: (context) => {
// don't need to unsubscribe because subscription should be active for the whole app lifecycle
window.addEventListener('offline', () => {
context.commit('SET_OFFLINE', true);
});
// don't need to unsubscribe because subscription should be active for the whole app lifecycle
window.addEventListener('online', () => {
context.commit('SET_OFFLINE', false);
});
},
INITIALIZE_SESSION: (context, payload) => Promise.allSettled([
context.dispatch('chat/SUBSCRIBE_TO_MESSAGES', payload),
context.dispatch('notifications/INITIALIZE'),
Expand All @@ -33,6 +44,9 @@ const mutations = {
...config,
};
},
SET_OFFLINE: (state, offline) => {
state.offline = offline;
},
};

export default new Vuex.Store({
Expand Down
37 changes: 37 additions & 0 deletions src/modules/call/components/wt-omni-widget-call-offline.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<section class="wt-omni-widget-call-offline">
<wt-icon
color="error"
icon="attention"
icon-prefix="wt-omni-widget"
></wt-icon>
<call-title-wrapper>
unlucky
<template #description>
unlucky x2
</template>
</call-title-wrapper>
</section>
</template>

<script>
import CallTitleWrapper from './utils/wt-omni-widget-call-title-wrapper.vue';
export default {
name: 'wt-omni-widget-call-offline',
components: { CallTitleWrapper },
};
</script>

<style lang="scss" scoped>
#wt-omni-widget {
.wt-omni-widget-call-offline {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
height: 100%;
gap: 32px;
}
}
</style>
23 changes: 22 additions & 1 deletion src/modules/call/components/wt-omni-widget-call-wrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ why there's d: contents; and this weird wrapper?

<script>
import getNamespacedState from '@webitel/ui-sdk/src/store/helpers/getNamespacedState';
import { mapState } from 'vuex';
import { mapState, mapActions } from 'vuex';
import SessionState from '../enums/SessionState.enum';
import ContentWrapper
from '../../../app/components/wt-omni-widget-window/wt-omni-widget-window-content-wrapper/wt-omni-widget-window-content-wrapper.vue';
Expand All @@ -26,6 +26,7 @@ import FooterWrapper
import CallStart from './wt-omni-widget-call-start.vue';
import CallRinging from './wt-omni-widget-call-ringing.vue';
import CallActive from './wt-omni-widget-call-active.vue';
import CallOffline from './wt-omni-widget-call-offline.vue';
export default {
name: 'wt-omni-widget-call-wrapper',
Expand All @@ -35,6 +36,7 @@ export default {
CallStart,
CallRinging,
CallActive,
CallOffline,
},
props: {
namespace: {
Expand All @@ -44,11 +46,16 @@ export default {
},
computed: {
...mapState({
offline: (state) => state.offline,
sessionState(state) {
return getNamespacedState(state, this.namespace).sessionState;
},
}),
callView() {
if (this.offline) {
return 'call-offline';
}
switch (this.sessionState) {
case SessionState.RINGING:
return 'call-ringing';
Expand All @@ -59,6 +66,20 @@ export default {
}
},
},
methods: {
...mapActions({
hangup(dispatch, payload) {
return dispatch(`${this.namespace}/HANGUP`, payload);
},
}),
},
watch: {
offline(value) {
if (value && this.sessionState !== SessionState.IDLE) {
this.hangup();
}
},
},
};
</script>

Expand Down

0 comments on commit 52e35dc

Please sign in to comment.