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

perf(participants): update participants session status from signaling #12556

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
69 changes: 58 additions & 11 deletions src/composables/useGetParticipants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import debounce from 'debounce'
import { ref, nextTick, computed, watch, onBeforeUnmount, onMounted } from 'vue'
import { ref, computed, watch, onBeforeUnmount, onMounted } from 'vue'

import { subscribe, unsubscribe } from '@nextcloud/event-bus'

import { useIsInCall } from './useIsInCall.js'
import { useStore } from './useStore.js'
import { CONVERSATION } from '../constants.js'
import { EventBus } from '../services/EventBus.js'
import { useSignalingStore } from '../stores/signaling.ts'

/**
* @param {import('vue').Ref} isActive whether the participants tab is active
Expand All @@ -23,8 +23,7 @@ export function useGetParticipants(isActive = ref(true), isTopBar = true) {
const token = computed(() => store.getters.getToken())
const conversation = computed(() => store.getters.conversation(token.value))
const isInCall = useIsInCall()
const isOneToOneConversation = computed(() => conversation.value?.type === CONVERSATION.TYPE.ONE_TO_ONE
|| conversation.value?.type === CONVERSATION.TYPE.ONE_TO_ONE_FORMER)
const participantsInitialised = computed(() => store.getters.participantsInitialised(token.value))
let fetchingParticipants = false
let pendingChanges = true

Expand All @@ -34,48 +33,93 @@ export function useGetParticipants(isActive = ref(true), isTopBar = true) {
*/
function initialiseGetParticipants() {
EventBus.on('joined-conversation', onJoinedConversation)

EventBus.on('signaling-users-in-room', updateUsersFromInternalSignaling)
EventBus.on('signaling-users-joined', updateUsersJoinedFromStandaloneSignaling)
EventBus.on('signaling-users-left', updateUsersLeftFromStandaloneSignaling)
EventBus.on('signaling-users-changed', updateUsersChangedFromStandaloneSignaling)
EventBus.on('signaling-all-users-changed-in-call-to-disconnected', updateUsersCallDisconnectedFromStandaloneSignaling)
// FIXME this works only temporary until signaling is fixed to be only on the calls
// Then we have to search for another solution. Maybe the room list which we update
// periodically gets a hash of all online sessions?
EventBus.on('signaling-participant-list-changed', debounceUpdateParticipants)
EventBus.on('signaling-participant-list-changed', debouncePostponedUpdateParticipants)
subscribe('guest-promoted', onJoinedConversation)
}

const updateUsersFromInternalSignaling = async ([participants]) => {
const signalingStore = useSignalingStore()
const hasUnknownSessions = signalingStore.updateParticipantsFromInternalSignaling(token.value, participants)
if (hasUnknownSessions) {
debounceUpdateParticipants()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

RFC: Maybe we need to update immediately here?

Should happen in two cases:

  • we don't have a list yet, so we already fetching it, (then request will be cancelled);
  • a new participant (guest) joined and not in the list yet (would be a disaster for webinars, where new people are joining every time)

Copy link
Contributor Author

@Antreesy Antreesy Jun 24, 2024

Choose a reason for hiding this comment

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

Kept as-is, so will be updated in 3-15s

  • add trigger to cancel this request (if everyone was found in very first server response, but data wasn't there yet)
  • OR
  • Do not make an immediate request, get everyone as unknown and trigger debounce interval (will be anyway for conversation, just not provoke another one)

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree to keep it as-is.

As we know from signaling message what attendees are joining, what about create a temporary participant with the info available and data will be completed once fetched ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't have enough information to show a participant from signaling until fetch. And we got all the actual info from it, there's no need to complete it later.
Though we can consider cache participants list 🤔

}
}
const updateUsersJoinedFromStandaloneSignaling = async ([participants]) => {
const signalingStore = useSignalingStore()
const hasUnknownSessions = signalingStore.updateParticipantsJoinedFromStandaloneSignaling(token.value, participants)
if (hasUnknownSessions) {
debounceUpdateParticipants()
}
}
const updateUsersLeftFromStandaloneSignaling = ([signalingSessionIds]) => {
const signalingStore = useSignalingStore()
signalingStore.updateParticipantsLeftFromStandaloneSignaling(signalingSessionIds)
}
const updateUsersChangedFromStandaloneSignaling = ([participants]) => {
const signalingStore = useSignalingStore()
signalingStore.updateParticipantsChangedFromStandaloneSignaling(token.value, participants)
}
const updateUsersCallDisconnectedFromStandaloneSignaling = () => {
const signalingStore = useSignalingStore()
signalingStore.updateParticipantsCallDisconnectedFromStandaloneSignaling(token.value)
}
/**
* Stop the get participants listeners
*
*/
function stopGetParticipants() {
EventBus.off('joined-conversation', onJoinedConversation)
EventBus.off('signaling-participant-list-changed', debounceUpdateParticipants)
EventBus.off('signaling-users-in-room', updateUsersFromInternalSignaling)
EventBus.off('signaling-users-joined', updateUsersJoinedFromStandaloneSignaling)
EventBus.off('signaling-users-left', updateUsersLeftFromStandaloneSignaling)
EventBus.off('signaling-users-changed', updateUsersChangedFromStandaloneSignaling)
EventBus.off('signaling-all-users-changed-in-call-to-disconnected', updateUsersCallDisconnectedFromStandaloneSignaling)
EventBus.off('signaling-participant-list-changed', debouncePostponedUpdateParticipants)
unsubscribe('guest-promoted', onJoinedConversation)
}

const onJoinedConversation = () => {
if (isOneToOneConversation.value) {
if (!participantsInitialised.value) {
cancelableGetParticipants()
} else {
nextTick(() => debounceUpdateParticipants())
debounceUpdateParticipants()
}
}

const debounceUpdateParticipants = () => {
const debouncePostponedUpdateParticipants = () => {
debounceUpdateParticipants(true)
}

const debounceUpdateParticipants = (postpone) => {
if (!isActive.value && !isInCall.value) {
// Update is ignored but there is a flag to force the participants update
pendingChanges = true
return
}

if (store.getters.windowIsVisible() && (isInCall.value || !conversation.value?.hasCall)) {
if (postpone) {
console.count('perf: debounceLongUpdateParticipants')
debounceLongUpdateParticipants()
} else if (store.getters.windowIsVisible() && (isInCall.value || !conversation.value?.hasCall)) {
console.count('perf: debounceFastUpdateParticipants')
debounceFastUpdateParticipants()
} else {
console.count('perf: debounceSlowUpdateParticipants')
debounceSlowUpdateParticipants()
}
pendingChanges = false
}

const cancelableGetParticipants = async () => {
console.count('perf: cancelableGetParticipants')
const isInLobby = store.getters.isInLobby
const isModeratorOrUser = store.getters.isModeratorOrUser
if (fetchingParticipants || token.value === '' || isInLobby || !isModeratorOrUser) {
Expand All @@ -85,6 +129,7 @@ export function useGetParticipants(isActive = ref(true), isTopBar = true) {
fetchingParticipants = true
debounceFastUpdateParticipants.clear()
debounceSlowUpdateParticipants.clear()
debounceLongUpdateParticipants.clear()

await store.dispatch('fetchParticipants', { token: token.value })
fetchingParticipants = false
Expand All @@ -94,6 +139,8 @@ export function useGetParticipants(isActive = ref(true), isTopBar = true) {
cancelableGetParticipants, 3000)
const debounceSlowUpdateParticipants = debounce(
cancelableGetParticipants, 15000)
const debounceLongUpdateParticipants = debounce(
cancelableGetParticipants, 30000)

onMounted(() => {
if (isTopBar) {
Expand Down
10 changes: 10 additions & 0 deletions src/store/participantsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
import SessionStorage from '../services/SessionStorage.js'
import { talkBroadcastChannel } from '../services/talkBroadcastChannel.js'
import { useGuestNameStore } from '../stores/guestName.js'
import { useSignalingStore } from '../stores/signaling.ts'
import CancelableRequest from '../utils/cancelableRequest.js'

/**
Expand Down Expand Up @@ -687,6 +688,10 @@ const actions = {
}
}

const signalingStore = useSignalingStore()
const unknownSignalingSessions = Object.values(signalingStore.sessions)
.filter(session => !session.attendeeId)

newParticipants.forEach(participant => {
if (context.state.attendees[token]?.[participant.attendeeId]) {
context.dispatch('updateParticipantIfHasChanged', { token, participant, hasUserStatuses })
Expand All @@ -697,6 +702,11 @@ const actions = {
}
}

const session = unknownSignalingSessions.find(session => participant.sessionIds.includes(session.sessionId))
if (session) {
signalingStore.addSignalingSession({ ...session, attendeeId: participant.attendeeId })
}

if (participant.participantType === PARTICIPANT.TYPE.GUEST
|| participant.participantType === PARTICIPANT.TYPE.GUEST_MODERATOR) {
guestNameStore.addGuestName({
Expand Down
Loading