Use joinAbortController as isJoining
This commit is contained in:
@@ -25,27 +25,24 @@
|
|||||||
|
|
||||||
const participants = deriveVoiceParticipants(url, h)
|
const participants = deriveVoiceParticipants(url, h)
|
||||||
const isActive = $derived($currentVoiceSession?.url === url && $currentVoiceSession?.h === h)
|
const isActive = $derived($currentVoiceSession?.url === url && $currentVoiceSession?.h === h)
|
||||||
let isJoining = $state(false)
|
let joinAbortController = $state<AbortController | undefined>(undefined)
|
||||||
let joinAbortController: AbortController | undefined
|
|
||||||
|
|
||||||
const handleClick = async () => {
|
const handleClick = async () => {
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
await leaveVoiceRoom()
|
await leaveVoiceRoom()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (isJoining) {
|
if (joinAbortController) {
|
||||||
joinAbortController?.abort()
|
joinAbortController.abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
joinAbortController = new AbortController()
|
joinAbortController = new AbortController()
|
||||||
isJoining = true
|
|
||||||
try {
|
try {
|
||||||
await joinVoiceRoom(url, h, joinAbortController.signal)
|
await joinVoiceRoom(url, h, joinAbortController.signal)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to join voice room", e)
|
console.error("Failed to join voice room", e)
|
||||||
pushToast({theme: "error", message: "Failed to join voice room"})
|
pushToast({theme: "error", message: "Failed to join voice room"})
|
||||||
} finally {
|
} finally {
|
||||||
isJoining = false
|
|
||||||
joinAbortController = undefined
|
joinAbortController = undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +59,7 @@
|
|||||||
class={cx("!items-start", isActive && "!bg-base-100 !text-base-content")}>
|
class={cx("!items-start", isActive && "!bg-base-100 !text-base-content")}>
|
||||||
<div class="flex w-full min-w-0 flex-col gap-2">
|
<div class="flex w-full min-w-0 flex-col gap-2">
|
||||||
<div class="flex gap-2 items-center">
|
<div class="flex gap-2 items-center">
|
||||||
{#if isJoining}
|
{#if joinAbortController}
|
||||||
<span class="loading loading-spinner loading-sm"></span>
|
<span class="loading loading-spinner loading-sm"></span>
|
||||||
{:else}
|
{:else}
|
||||||
<Icon icon={isActive ? VolumeLoud : Volume} size={4} class="opacity-70" />
|
<Icon icon={isActive ? VolumeLoud : Volume} size={4} class="opacity-70" />
|
||||||
|
|||||||
Reference in New Issue
Block a user