Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Call): introduce intermediary phase before joining call #13329

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/components/CallView/CallFailedDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!--
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->

<script setup lang="ts">
import { computed } from 'vue'

import IconAlertOctagon from 'vue-material-design-icons/AlertOctagon.vue'

import { t } from '@nextcloud/l10n'

import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'

import store from '../../store/index.js'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have useStore composable, it should be better to use it here


const props = defineProps({
token: {
type: String,
required: true,
},
})

const STATUS_ERRORS = {
400: t('spreed', 'Recording consent is required'),
403: t('spreed', 'This conversation is read-only'),
404: t('spreed', 'Conversation not found or not joined'),
412: t('spreed', "Lobby is still active and you're not a moderator"),
}
const userId = computed(() => store.getters.userId)
const connectionFailed = computed(() => store.getters.connectionFailed(props.token))
const connectionFailedDialgId = `connection-failed-${userId.value}`
const message = computed(() => {
if (connectionFailed.value) {
const statusCode = connectionFailed.value?.meta?.statuscode
if (STATUS_ERRORS[statusCode]) {
return STATUS_ERRORS[statusCode]
}
if (connectionFailed.value?.data?.error) {
return connectionFailed.value.data.error
}

return t('spreed', 'Please try to reload the page')
} else {
return ''
}
})

/**
*
*/
function clearConnectionFailedError() {
store.dispatch('clearConnectionFailed', props.token)
}

</script>

<template>
<NcModal class="connection-failed__modal"
:label-id="connectionFailedDialgId"
@close="clearConnectionFailedError">
<NcEmptyContent :name="t('spreed', 'Connection failed')"
:description="message">
<template #icon>
<IconAlertOctagon />
</template>
</NcEmptyContent>
</NcModal>
</template>
54 changes: 1 addition & 53 deletions src/components/CallView/shared/EmptyCallView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
<p v-if="message" class="emptycontent-additional">
{{ message }}
</p>
<p v-if="helper" class="emptycontent-additional">
{{ helper }}
</p>
<NcButton v-if="showLink"
type="primary"
@click.stop="handleCopyLink">
Expand All @@ -30,36 +27,25 @@

<script>
import IconAccountMultiple from 'vue-material-design-icons/AccountMultiple.vue'
import IconAlertOctagon from 'vue-material-design-icons/AlertOctagon.vue'
import IconLinkVariant from 'vue-material-design-icons/LinkVariant.vue'
import IconPhone from 'vue-material-design-icons/Phone.vue'

import { t } from '@nextcloud/l10n'

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'

import { CONVERSATION, PARTICIPANT } from '../../../constants.js'
import { copyConversationLinkToClipboard } from '../../../utils/handleUrl.ts'

const STATUS_ERRORS = {
400: t('spreed', 'Recording consent is required'),
403: t('spreed', 'This conversation is read-only'),
404: t('spreed', 'Conversation not found or not joined'),
412: t('spreed', "Lobby is still active and you're not a moderator"),
}

export default {

name: 'EmptyCallView',

components: {
NcButton,
IconAccountMultiple,
IconAlertOctagon,
IconLinkVariant,
IconPhone,
NcLoadingIcon,
},

props: {
Expand All @@ -85,14 +71,6 @@ export default {
return this.$store.getters.getToken()
},

isConnecting() {
return this.$store.getters.isConnecting(this.token)
},

connectionFailed() {
return this.$store.getters.connectionFailed(this.token)
},

conversation() {
return this.$store.getters.conversation(this.token)
},
Expand Down Expand Up @@ -138,24 +116,14 @@ export default {
},

emptyCallViewIcon() {
if (this.connectionFailed) {
return IconAlertOctagon
} else if (this.isConnecting) {
return NcLoadingIcon
} else if (this.isPhoneConversation) {
if (this.isPhoneConversation) {
return IconPhone
} else {
return this.isPublicConversation ? IconLinkVariant : IconAccountMultiple
}
},

title() {
if (this.connectionFailed) {
return t('spreed', 'Connection failed')
}
if (this.isConnecting) {
return t('spreed', 'Connecting โ€ฆ')
}
if (this.isPhoneConversation) {
return t('spreed', 'Calling โ€ฆ')
}
Expand All @@ -165,27 +133,7 @@ export default {
return t('spreed', 'Waiting for others to join the call โ€ฆ')
},

helper() {
return this.connectionFailed ? t('spreed', 'Please try to reload the page') : ''
},

message() {
if (this.connectionFailed) {
const statusCode = this.connectionFailed?.meta?.statuscode
if (STATUS_ERRORS[statusCode]) {
return STATUS_ERRORS[statusCode]
}
if (this.connectionFailed?.data?.error) {
return this.connectionFailed.data.error
}

return t('spreed', 'Something went wrong')
}

if (this.isConnecting) {
return ''
}

if (this.isPasswordRequestConversation || this.isFileConversation) {
return ''
}
Expand Down
19 changes: 18 additions & 1 deletion src/components/TopBar/CallButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
html: true
}"
:aria-label="startCallLabel"
:disabled="startCallButtonDisabled || loading"
:disabled="startCallButtonDisabled || loading || isConnecting"
:type="startCallButtonType"
@click="handleClick">
<template #icon>
Expand All @@ -27,6 +27,7 @@
{{ startCallLabel }}
</template>
</NcButton>

<NcButton v-else-if="showLeaveCallButton && canEndForAll && isPhoneRoom"
id="call_button"
:aria-label="endCallLabel"
Expand Down Expand Up @@ -84,6 +85,7 @@
{{ t('spreed', 'End call for everyone') }}
</NcActionButton>
</NcActions>
<CallFailedDialog v-if="connectionFailed" :token="token" />
</div>
</template>

Expand All @@ -106,6 +108,8 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import { useIsMobile } from '@nextcloud/vue/dist/Composables/useIsMobile.js'
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip.js'

import CallFailedDialog from '../CallView/CallFailedDialog.vue'

import { useIsInCall } from '../../composables/useIsInCall.js'
import { ATTENDEE, CALL, CONVERSATION, PARTICIPANT } from '../../constants.js'
import { callSIPDialOut } from '../../services/callsService.js'
Expand All @@ -124,6 +128,7 @@ export default {
},

components: {
CallFailedDialog,
NcActions,
NcActionButton,
NcButton,
Expand Down Expand Up @@ -279,6 +284,10 @@ export default {
return t('spreed', 'Join call')
}

if (this.isConnecting) {
return t('spreed', 'Connecting...')
}

return this.silentCall ? t('spreed', 'Start call silently') : t('spreed', 'Start call')
},

Expand Down Expand Up @@ -355,6 +364,14 @@ export default {
isInLobby() {
return this.$store.getters.isInLobby
},

isConnecting() {
return this.$store.getters.isConnecting(this.token)
},

connectionFailed() {
return this.$store.getters.connectionFailed(this.token)
},
},

watch: {
Expand Down
1 change: 1 addition & 0 deletions src/services/callsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const joinCall = async function(token, flags, silent, recordingConsent) {
return await signalingJoinCall(token, flags, silent, recordingConsent)
} catch (error) {
console.debug('Error while joining call: ', error)
throw error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe remove try-catch block here, since it's not needed?

}
}

Expand Down
63 changes: 37 additions & 26 deletions src/store/participantsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,27 +321,29 @@ const mutations = {
if (state.inCall[token] && state.inCall[token][sessionId]) {
Vue.delete(state.inCall[token], sessionId)
}

if (state.connecting[token] && state.connecting[token][sessionId]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can keep this resetting (in case it survives somehow). Maybe via commit('finishedConnecting')?

Vue.delete(state.connecting[token], sessionId)
}
} else {
if (!state.inCall[token]) {
Vue.set(state.inCall, token, {})
}
Vue.set(state.inCall[token], sessionId, flags)

if (!state.connecting[token]) {
Vue.set(state.connecting, token, {})
}
Vue.set(state.connecting[token], sessionId, flags)
}
},

connectionFailed(state, { token, payload }) {
Vue.set(state.connectionFailed, token, payload)
},

clearConnectionFailed(state, token) {
Vue.delete(state.connectionFailed, token)
},

connecting(state, { token, sessionId, flags }) {
if (!state.connecting[token]) {
Vue.set(state.connecting, token, {})
}
Vue.set(state.connecting[token], sessionId, flags)
},

finishedConnecting(state, { token, sessionId }) {
if (state.connecting[token] && state.connecting[token][sessionId]) {
Vue.delete(state.connecting[token], sessionId)
Expand Down Expand Up @@ -777,6 +779,8 @@ const actions = {
},

async joinCall({ commit, getters }, { token, participantIdentifier, flags, silent, recordingConsent }) {
commit('connecting', { token, sessionId: participantIdentifier.sessionId, flags })

if (!participantIdentifier?.sessionId) {
console.error('Trying to join call without sessionId')
return
Expand All @@ -788,28 +792,31 @@ const actions = {
return
}

commit('setInCall', {
token,
sessionId: participantIdentifier.sessionId,
flags,
// Preparing the event listener for the signaling-join-call event
EventBus.once('signaling-join-call', () => {
commit('setInCall', {
token,
sessionId: participantIdentifier.sessionId,
flags,
})
commit('finishedConnecting', { token, sessionId: participantIdentifier.sessionId })
})

const actualFlags = await joinCall(token, flags, silent, recordingConsent)

const updatedData = {
inCall: actualFlags,
}
commit('updateParticipant', { token, attendeeId: attendee.attendeeId, updatedData })

EventBus.once('signaling-users-in-room', () => {
// Preparing the event listener for the signaling-join-call-failed event
EventBus.once('signaling-join-call-failed', () => {
commit('finishedConnecting', { token, sessionId: participantIdentifier.sessionId })
})

setTimeout(() => {
// If by accident we never receive a users list, just switch to
// "Waiting for others to join the call โ€ฆ" after some seconds.
commit('finishedConnecting', { token, sessionId: participantIdentifier.sessionId })
}, 10000)
Comment on lines -808 to -812
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's guaranteed to receive one of the above signaling events as we are the base server

try {
const actualFlags = await joinCall(token, flags, silent, recordingConsent)
const updatedData = {
inCall: actualFlags,
}
commit('updateParticipant', { token, attendeeId: attendee.attendeeId, updatedData })
} catch (e) {
console.error(e)

}
},

async leaveCall({ commit, getters }, { token, participantIdentifier, all = false }) {
Expand Down Expand Up @@ -1128,6 +1135,10 @@ const actions = {
setPhoneMute(context, { callid, value }) {
context.commit('setPhoneMute', { callid, value })
},

clearConnectionFailed(context, token) {
context.commit('clearConnectionFailed', token)
}
}

export default { state, mutations, getters, actions }
3 changes: 2 additions & 1 deletion src/utils/signaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,12 @@ Signaling.Base.prototype.joinCall = function(token, flags, silent, recordingCons
.catch(function(e) {
reject(new Error())
console.error('Connection failed, reason: ', e)
this._trigger('joinCallFailed', [token])
store.commit('connectionFailed', {
token,
payload: e.response?.data?.ocs,
})
})
}.bind(this))
})
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/webrtc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function startCall(signaling, configuration, silent, recordingConsent) {
signaling.joinCall(pendingJoinCallToken, flags, silent, recordingConsent).then(() => {
startedCall(flags)
}).catch(error => {
signalingLeaveCall(pendingJoinCallToken)
failedToStartCall(error)
})
}
Expand Down
Loading