diff --git a/src/lib/components/calling/CallScreen.svelte b/src/lib/components/calling/CallScreen.svelte index 068198fcd..b130eb5c4 100644 --- a/src/lib/components/calling/CallScreen.svelte +++ b/src/lib/components/calling/CallScreen.svelte @@ -16,23 +16,47 @@ import { callInProgress, callTimeout, TIME_TO_SHOW_CONNECTING, TIME_TO_SHOW_END_CALL_FEEDBACK, timeCallStarted, usersAcceptedTheCall, usersDeniedTheCall, VoiceRTCInstance } from "$lib/media/Voice" import { log } from "$lib/utils/Logger" import { playSound, SoundHandler, Sounds } from "../utils/SoundHandler" + import { MultipassStoreInstance } from "$lib/wasm/MultipassStore" export let expanded: boolean = false - function toggleExanded() { - expanded = !expanded - } + export let deafened: boolean = get(Store.state.devices.deafened) + export let chat: Chat let showVolumeMixer = false let showCallSettings = false - let muted: boolean = !VoiceRTCInstance.callOptions.audio.enabled let cameraEnabled: boolean = get(Store.state.devices.cameraEnabled) + let isFullScreen = false + let localVideoCurrentSrc: HTMLVideoElement - export let deafened: boolean = get(Store.state.devices.deafened) - export let chat: Chat + let showAnimation = true + let message = $_("settings.calling.connecting") + let timeout: NodeJS.Timeout | undefined + let callSound: SoundHandler | undefined = undefined + + $: if ($usersAcceptedTheCall.length > 0) { + callSound?.stop() + callSound = undefined + } + $: userCache = Store.getUsersLookup(chat.users) + $: userCallOptions = VoiceRTCInstance.callOptions + $: remoteStreams = Store.state.activeCallMeta + $: ownUserName = get(Store.state.user).name + + $: if ($usersDeniedTheCall.length === chat.users.length - 1) { + setTimeout(() => { + Store.endCall() + VoiceRTCInstance.leaveCall() + dispatch("endCall") + }, TIME_TO_SHOW_END_CALL_FEEDBACK) + } let dispatch = createEventDispatcher() + function toggleExanded() { + expanded = !expanded + } + function toggleFullscreen() { const elem = document.getElementById("call-screen") @@ -50,13 +74,6 @@ userCallOptions = userCallOptions } - let isFullScreen = false - - $: userCache = Store.getUsersLookup(chat.users) - $: userCallOptions = VoiceRTCInstance.callOptions - $: remoteStreams = Store.state.activeCallMeta - $: ownUserName = get(Store.state.user).name - let subscribeOne = Store.state.devices.muted.subscribe(state => { muted = state userCallOptions = VoiceRTCInstance.callOptions @@ -78,8 +95,6 @@ userCallOptions = VoiceRTCInstance.callOptions }) - let localVideoCurrentSrc: HTMLVideoElement - function handleClickOutside(event: MouseEvent) { const callSettingsElement = document.getElementById("call-settings") const showVolumeElement = document.getElementById("volume-mixer") @@ -118,20 +133,8 @@ } } - $: if ($usersDeniedTheCall.length === chat.users.length - 1) { - setTimeout(() => { - Store.endCall() - VoiceRTCInstance.leaveCall() - dispatch("endCall") - }, TIME_TO_SHOW_END_CALL_FEEDBACK) - } - - let showAnimation = true let noResponseVisible = false - let message = $_("settings.calling.connecting") - let timeout: NodeJS.Timeout | undefined let hideNoResponseUsersTimeout: NodeJS.Timeout | undefined - let callSound: SoundHandler | undefined = undefined function hideNoResponseUsersAfterAPeriodOfTime() { hideNoResponseUsersTimeout = setTimeout(() => { @@ -139,12 +142,9 @@ }, 10000) } - $: if ($usersAcceptedTheCall.length > 0) { - callSound?.stop() - callSound = undefined - } - onMount(async () => { + await MultipassStoreInstance.listUsersForACall(chat.users) + userCache = Store.getUsersLookup(chat.users) usersDeniedTheCall.set([]) callTimeout.set(false) usersAcceptedTheCall.set([]) diff --git a/src/lib/components/messaging/Conversation.svelte b/src/lib/components/messaging/Conversation.svelte index a8f7b993d..ac8b32130 100644 --- a/src/lib/components/messaging/Conversation.svelte +++ b/src/lib/components/messaging/Conversation.svelte @@ -96,7 +96,9 @@ } onDestroy(() => { - if (scrollContainer.scrollHeight <= scrollContainer.clientHeight) markAsRead($chat.id) + if (scrollContainer && scrollContainer.scrollHeight) { + if (scrollContainer?.scrollHeight <= scrollContainer?.clientHeight) markAsRead($chat.id) + } }) diff --git a/src/lib/wasm/MultipassStore.ts b/src/lib/wasm/MultipassStore.ts index f1d5ff927..2ac4d19c0 100644 --- a/src/lib/wasm/MultipassStore.ts +++ b/src/lib/wasm/MultipassStore.ts @@ -391,6 +391,31 @@ class MultipassStore { } } + /** + * Lists users for a call. + * Update users cache if they are not already in cache. + * It avoids problem if there is some user in call that is not current user's friend. + */ + async listUsersForACall(callUsers: Array) { + const multipass = get(this.multipassWritable) + + if (multipass) { + try { + let usersInCall: Array = [] + for (let i = 0; i < callUsers.length; i++) { + let userInCall = await this.identity_from_did(callUsers[i]) + if (userInCall) { + usersInCall.push(userInCall.key) + // Add users in cache + Store.updateUser(userInCall) + } + } + } catch (error) { + log.error("Error getting users in a call: " + error) + } + } + } + /** * Removes a friend. * @param did - The DID of the friend to be removed. @@ -611,7 +636,7 @@ class MultipassStore { overlay: "", }, status: status, - status_message: identity === undefined ? "" : (identity.status_message ?? ""), + status_message: identity === undefined ? "" : identity.status_message ?? "", }, integrations: identity === undefined ? new Map() : identity.metadata, media: {