From f633b6cb979b9b157d12b23093a32daa2f17c9e4 Mon Sep 17 00:00:00 2001 From: Sergii Leonenko Date: Tue, 6 Jul 2021 22:12:49 +0300 Subject: [PATCH] TT#129211 Extract registration of RTC:Engine global events from store Change-Id: Ia2237c5a730e389ea433ab88c468db219631ac7f --- quasar.conf.js | 1 + src/boot/rtc-engine.js | 70 +++++++++++++++++++++++++++++++++++++++ src/plugins/rtc-engine.js | 2 +- src/store/index.js | 63 +---------------------------------- 4 files changed, 73 insertions(+), 63 deletions(-) create mode 100644 src/boot/rtc-engine.js diff --git a/quasar.conf.js b/quasar.conf.js index cf86ade1..c77a2fc8 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -30,6 +30,7 @@ module.exports = function (ctx) { // https://quasar.dev/quasar-cli/boot-files boot: [ 'config', + 'rtc-engine', 'filters', 'vuelidate', 'i18n', diff --git a/src/boot/rtc-engine.js b/src/boot/rtc-engine.js new file mode 100644 index 00000000..aa5b7fed --- /dev/null +++ b/src/boot/rtc-engine.js @@ -0,0 +1,70 @@ +import Vue from 'vue' +import RtcEnginePlugin from 'src/plugins/rtc-engine' +import CallPlugin from 'src/plugins/call' +import ConferencePlugin from 'src/plugins/conference' +import { errorVisibilityTimeout } from 'src/store/call' + +export default ({ Vue, store }) => { + Vue.use(RtcEnginePlugin) + Vue.use(CallPlugin) + Vue.use(ConferencePlugin) + + rtcEngine(store) + call(store) + conference(store) +} + +function rtcEngine (store) { + Vue.$rtcEngine.setNgcpApiBaseUrl(Vue.$config.baseHttpUrl) + Vue.$rtcEngine.onSipNetworkConnected(() => { + store.commit('call/enableCall') + }).onSipNetworkDisconnected(() => { + store.commit('call/disableCall') + }).onConferenceNetworkConnected(() => { + store.commit('conference/enableConferencing') + }).onConferenceNetworkDisconnected(() => { + store.commit('conference/disableConferencing') + }) +} + +function call (store) { + Vue.$call.onIncoming(() => { + store.commit('call/incomingCall', { + number: Vue.$call.getNumber() + }) + }).onRemoteMedia((remoteMediaStream) => { + store.commit('call/establishCall', remoteMediaStream) + }).onEnded((reason) => { + Vue.$call.end() + store.commit('call/endCall', reason) + setTimeout(() => { + store.commit('call/inputNumber') + }, errorVisibilityTimeout) + }) +} + +function conference (store) { + Vue.$conference.onConferenceParticipantJoined((participant) => { + store.commit('conference/participantJoined', participant) + participant.onMediaStream(() => { + store.commit('conference/removeRemoteMedia', participant.id) + store.commit('conference/addRemoteMedia', participant.id) + }).onMediaEnded(() => { + store.commit('conference/removeRemoteMedia', participant.id) + }) + }).onConferenceParticipantLeft((participant) => { + store.commit('conference/participantLeft', participant) + store.commit('conference/removeRemoteMedia', participant.id) + store.commit('conference/setSelectedParticipant', participant.id) + }).onConferenceEvent((event) => { + store.commit('conference/event', event) + }).onConferenceMessage((message) => { + store.commit('conference/message', message) + }).onConferenceFile((file) => { + store.commit('conference/file', file) + }).onLocalMediaStreamEnded(() => { + store.commit('conference/disposeLocalMedia') + }).onConferenceEnded(() => { + store.dispatch('conference/leave') + }) +} diff --git a/src/plugins/rtc-engine.js b/src/plugins/rtc-engine.js index 952b1bab..551b43e1 100644 --- a/src/plugins/rtc-engine.js +++ b/src/plugins/rtc-engine.js @@ -179,6 +179,6 @@ export class RtcEnginePlugin { export default { install (Vue) { Vue.$rtcEngine = RtcEnginePlugin.getInstance() - Vue.$rtcEngine.setNgcpApiJwt(localStorage.getItem('jwt')) + Vue.$rtcEngine.setNgcpApiJwt(localStorage.getItem('jwt')) // TODO: probably should be replaced with "getJwt" function } } diff --git a/src/store/index.js b/src/store/index.js index b54564e7..7644ef82 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -5,7 +5,7 @@ import { date } from 'quasar' import CallBlockingModule from './call-blocking' import CallForwardingModule from './call-forwarding' -import CallModule, { errorVisibilityTimeout } from './call' +import CallModule from './call' import CallRecordingsModule from './call-recordings' import CallSettingsModule from './call-settings' import ConversationsModule from './conversations' @@ -28,14 +28,8 @@ import VoiceboxModule from './voicebox' import ConferenceModule from './conference' import DashboardModule from './dashboard' -import RtcEnginePlugin from 'src/plugins/rtc-engine' -import CallPlugin from 'src/plugins/call' -import ConferencePlugin from 'src/plugins/conference' import { INTERNAL_DATE_FORMAT_SLASH, INTERNAL_DATE_FORMAT_DASH, INTERNAL_DATE_FORMAT_DASH_HOUR } from 'src/constants' -Vue.use(RtcEnginePlugin) -Vue.use(CallPlugin) -Vue.use(ConferencePlugin) Vue.use(Vuex) /* @@ -72,7 +66,6 @@ export default function (/* { ssrContext } */) { callForwarding: CallForwardingModule, pbxAutoAttendants: PbxAutoAttendants, dashboard: DashboardModule - }, state: { route: null @@ -131,60 +124,6 @@ export default function (/* { ssrContext } */) { } } }, - plugins: [ - function rtcEngine (store) { - Vue.$rtcEngine.setNgcpApiBaseUrl(Vue.$config.baseHttpUrl) - Vue.$rtcEngine.onSipNetworkConnected(() => { - store.commit('call/enableCall') - }).onSipNetworkDisconnected(() => { - store.commit('call/disableCall') - }).onConferenceNetworkConnected(() => { - store.commit('conference/enableConferencing') - }).onConferenceNetworkDisconnected(() => { - store.commit('conference/disableConferencing') - }) - }, - function call (store) { - Vue.$call.onIncoming(() => { - store.commit('call/incomingCall', { - number: Vue.$call.getNumber() - }) - }).onRemoteMedia((remoteMediaStream) => { - store.commit('call/establishCall', remoteMediaStream) - }).onEnded((reason) => { - Vue.$call.end() - store.commit('call/endCall', reason) - setTimeout(() => { - store.commit('call/inputNumber') - }, errorVisibilityTimeout) - }) - }, - function conference (store) { - Vue.$conference.onConferenceParticipantJoined((participant) => { - store.commit('conference/participantJoined', participant) - participant.onMediaStream(() => { - store.commit('conference/removeRemoteMedia', participant.id) - store.commit('conference/addRemoteMedia', participant.id) - }).onMediaEnded(() => { - store.commit('conference/removeRemoteMedia', participant.id) - }) - }).onConferenceParticipantLeft((participant) => { - store.commit('conference/participantLeft', participant) - store.commit('conference/removeRemoteMedia', participant.id) - store.commit('conference/setSelectedParticipant', participant.id) - }).onConferenceEvent((event) => { - store.commit('conference/event', event) - }).onConferenceMessage((message) => { - store.commit('conference/message', message) - }).onConferenceFile((file) => { - store.commit('conference/file', file) - }).onLocalMediaStreamEnded(() => { - store.commit('conference/disposeLocalMedia') - }).onConferenceEnded(() => { - store.dispatch('conference/leave') - }) - } - ], // enable strict mode (adds overhead!) // for dev mode only strict: process.env.DEV