Skip to content

Commit

Permalink
Merge branch 'fix-video-not-appearing' into add-feedback-when-there-i…
Browse files Browse the repository at this point in the history
…s-no-answer-from-other-user
  • Loading branch information
lgmarchi committed Oct 11, 2024
2 parents 45ba859 + 7fdba74 commit 05423d0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
23 changes: 14 additions & 9 deletions src/lib/components/calling/CallScreen.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import type { Chat } from "$lib/types"
import VolumeMixer from "./VolumeMixer.svelte"
import { onDestroy, onMount } from "svelte"
import { callTimeout, VoiceRTCInstance, type VoiceRTCUser } from "$lib/media/Voice"
import { callTimeout, VoiceRTCInstance } from "$lib/media/Voice"
import { log } from "$lib/utils/Logger"
export let expanded: boolean = false
Expand Down Expand Up @@ -113,7 +113,9 @@
}
let showAnimation = true
let message = "Connecting..."
let message = $_("settings.calling.connecting")
let timeout: NodeJS.Timeout | undefined
onMount(async () => {
document.addEventListener("mousedown", handleClickOutside)
Expand All @@ -122,9 +124,9 @@
if (VoiceRTCInstance.localVideoCurrentSrc && VoiceRTCInstance.remoteVideoCreator) {
if (VoiceRTCInstance.toCall && VoiceRTCInstance.toCall.find(did => did !== "") !== undefined) {
await VoiceRTCInstance.makeCall()
setTimeout(() => {
timeout = setTimeout(() => {
showAnimation = false
message = "No response"
message = $_("settings.calling.noResponse")
}, 15000)
}
}
Expand All @@ -140,6 +142,9 @@
subscribeTwo()
subscribeThree()
subscribeFour()
if (timeout) {
clearTimeout(timeout)
}
})
</script>

Expand Down Expand Up @@ -362,11 +367,11 @@
justify-content: center;
flex-direction: column;
text-align: center;
animation: shake 0.5s ease-in-out infinite;
animation: shake 0.4s ease-in-out infinite;
}
.shaking-participant {
animation: shake 0.5s ease-in-out infinite;
animation: shake 0.4s ease-in-out infinite;
}
@keyframes shake {
Expand All @@ -375,13 +380,13 @@
transform: translateX(0);
}
25% {
transform: translateX(-2px);
transform: translateX(-0.75px);
}
50% {
transform: translateX(2px);
transform: translateX(0.75px);
}
75% {
transform: translateX(-2px);
transform: translateX(-0.75px);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@
"startCallMessage": "📞 A call started at {value}.",
"endCallMessage": "📴 The call ended at {formattedEndTime}. Duration: {duration}.",
"callMissed": "📞 Missed call",
"noAnswer": "No answer, leaving the call..."
"noAnswer": "No answer, leaving the call...",
"connecting": "Connecting...",
"noResponse": "No response"
},
"notifications": {
"name": "Notifications",
Expand Down
18 changes: 12 additions & 6 deletions src/lib/media/Voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { joinRoom } from "trystero/ipfs"

const CALL_ACK = "CALL_ACCEPT"

let timeOuts: NodeJS.Timeout[] = []

export enum VoiceRTCMessageType {
UpdateUser = "UPDATE_USER",
None = "NONE",
Expand Down Expand Up @@ -428,15 +430,18 @@ export class VoiceRTC {
if (call) {
this.inviteToCall(this.toCall)
}
setTimeout(() => {
const timeoutWhenCallIsNull = setTimeout(() => {
if (this.call === null || this.call.empty) {
log.debug("No one joined the call, leaving")
callTimeout.set(true)
setTimeout(() => {
this.leaveCall(true)
}, 3500)
timeOuts.push(
setTimeout(() => {
this.leaveCall(true)
}, 3500)
)
}
}, 20000)
timeOuts.push(timeoutWhenCallIsNull)
Store.setActiveCall(Store.getCallingChat(this.channel!)!, CallDirection.Outbound)
} catch (error) {
log.error(`Error making call: ${error}`)
Expand Down Expand Up @@ -505,10 +510,10 @@ export class VoiceRTC {
}
})
}
await new Promise(resolve => setTimeout(resolve, 5000))
await new Promise(resolve => timeOuts.push(setTimeout(resolve, 5000)))
if (connected) {
// If connection has been made let it ring for 30 sec.
await new Promise(resolve => setTimeout(resolve, 30000))
await new Promise(resolve => timeOuts.push(setTimeout(resolve, 30000)))
conn.close()
break
}
Expand Down Expand Up @@ -567,6 +572,7 @@ export class VoiceRTC {
}

async leaveCall(sendEndCallMessage = false) {
timeOuts.forEach(t => clearTimeout(t))
sendEndCallMessage = sendEndCallMessage && this.channel !== undefined && this.call != null
if (sendEndCallMessage && this.call?.start) {
const now = new Date()
Expand Down

0 comments on commit 05423d0

Please sign in to comment.