Skip to content

Commit

Permalink
Merge branch 'dev' into luis/data-cy-replies
Browse files Browse the repository at this point in the history
  • Loading branch information
luisecm authored Oct 25, 2024
2 parents 855b824 + 6cba6c9 commit d366728
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 33 deletions.
67 changes: 36 additions & 31 deletions src/lib/components/calling/CallScreen.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -50,12 +74,10 @@
userCallOptions = userCallOptions
}
let isFullScreen = false
$: 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 && chat.users.length > 1) {
callSound?.stop()
callSound = undefined
}
let subscribeOne = Store.state.devices.muted.subscribe(state => {
muted = state
Expand All @@ -78,8 +100,6 @@
userCallOptions = VoiceRTCInstance.callOptions
})
let localVideoCurrentSrc: HTMLVideoElement
function handleClickOutside(event: MouseEvent) {
const callSettingsElement = document.getElementById("call-settings")
const showVolumeElement = document.getElementById("volume-mixer")
Expand Down Expand Up @@ -118,33 +138,18 @@
}
}
$: 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(() => {
noResponseVisible = false
}, 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([])
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/messaging/Conversation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
</script>

Expand Down
3 changes: 3 additions & 0 deletions src/lib/media/Voice.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { playSound, Sounds } from "$lib/components/utils/SoundHandler"
import { CallDirection } from "$lib/enums"
import { Store } from "$lib/state/Store"
import { create_cancellable_handler, type Cancellable } from "$lib/utils/CancellablePromise"
Expand Down Expand Up @@ -194,6 +195,7 @@ export class CallRoom {
let stream = await VoiceRTCInstance.getLocalStream()
log.debug(`Sending local stream ${stream} to ${peer}`)
room.addStream(stream, peer)
playSound(Sounds.Joined)
if (!this.start) {
this.start = new Date()
}
Expand All @@ -205,6 +207,7 @@ export class CallRoom {
VoiceRTCInstance.remoteVideoCreator.delete(participant[0])
delete this.participants[participant[0]]
}
playSound(Sounds.Disconnect)
if (this.empty) {
VoiceRTCInstance.leaveCall(true)
}
Expand Down
27 changes: 26 additions & 1 deletion src/lib/wasm/MultipassStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>) {
const multipass = get(this.multipassWritable)

if (multipass) {
try {
let usersInCall: Array<string> = []
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.
Expand Down Expand Up @@ -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<string, string>() : identity.metadata,
media: {
Expand Down

0 comments on commit d366728

Please sign in to comment.