Show better error when failing to join a voice room due to membership requirements.

This commit is contained in:
mplorentz
2026-03-25 15:57:10 -04:00
parent 610b8dd171
commit 56d386cb6b
2 changed files with 24 additions and 11 deletions
+1 -7
View File
@@ -5,7 +5,6 @@
import ProfileCircle from "@app/components/ProfileCircle.svelte" import ProfileCircle from "@app/components/ProfileCircle.svelte"
import RoomImage from "@app/components/RoomImage.svelte" import RoomImage from "@app/components/RoomImage.svelte"
import RoomName from "@app/components/RoomName.svelte" import RoomName from "@app/components/RoomName.svelte"
import {pushToast} from "@app/util/toast"
import {makeRoomPath} from "@app/util/routes" import {makeRoomPath} from "@app/util/routes"
import { import {
deriveVoiceParticipants, deriveVoiceParticipants,
@@ -42,12 +41,7 @@
return return
} }
try { await joinVoiceRoom(url, h)
await joinVoiceRoom(url, h)
} catch (e) {
console.error("Failed to join voice room", e)
pushToast({theme: "error", message: "Failed to join voice room"})
}
} }
$effect(() => { $effect(() => {
+23 -4
View File
@@ -9,7 +9,7 @@ import type {TrustedEvent} from "@welshman/util"
import {makeHttpAuth, makeHttpAuthHeader, getTags} from "@welshman/util" import {makeHttpAuth, makeHttpAuthHeader, getTags} from "@welshman/util"
import {signer} from "@welshman/app" import {signer} from "@welshman/app"
import {getLivekitEndpoint} from "$lib/livekit" import {getLivekitEndpoint} from "$lib/livekit"
import {AbortError, whenAborted, whenTimeout} from "$lib/util" import {AbortError, TimeoutError, whenAborted, whenTimeout} from "$lib/util"
import {deriveLatestEventForUrl} from "@app/core/state" import {deriveLatestEventForUrl} from "@app/core/state"
import {pushToast} from "@app/util/toast" import {pushToast} from "@app/util/toast"
@@ -17,6 +17,24 @@ export const LIVEKIT_PARTICIPANTS = 39004
export {checkRelayHasLivekit} from "$lib/livekit" export {checkRelayHasLivekit} from "$lib/livekit"
export class VoiceJoinMembershipError extends Error {
constructor() {
super("Failed to join voice room: you must be a member.")
this.name = "VoiceJoinMembershipError"
}
}
const handleJoinError = (e: unknown) => {
if (e instanceof AbortError) return
console.error("Failed to join voice room", e)
let message = "Failed to join voice room"
if (e instanceof VoiceJoinMembershipError) message = e.message
else if (e instanceof TimeoutError)
message = "Connection timed out. Please check your network and try again."
else if (e instanceof Error && e.message === "No signer available") message = e.message
pushToast({theme: "error", message})
}
export type VoiceSession = { export type VoiceSession = {
url: string url: string
h: string h: string
@@ -95,6 +113,7 @@ const fetchLivekitToken = async (
if (!response.ok) { if (!response.ok) {
const text = await response.text() const text = await response.text()
if (response.status === 403) throw new VoiceJoinMembershipError()
throw new Error(`Token request failed (${response.status}): ${text}`) throw new Error(`Token request failed (${response.status}): ${text}`)
} }
@@ -243,8 +262,7 @@ export const joinVoiceRoom = async (url: string, h: string): Promise<void> => {
playJoinSound() playJoinSound()
} catch (e) { } catch (e) {
if (isActive()) voiceState.set("disconnected") if (isActive()) voiceState.set("disconnected")
if (e instanceof AbortError) return handleJoinError(e)
throw e
} finally { } finally {
if (isActive()) joinAbortController = undefined if (isActive()) joinAbortController = undefined
} }
@@ -266,7 +284,8 @@ export const leaveVoiceRoom = async () => {
export const rejoinVoiceRoom = () => { export const rejoinVoiceRoom = () => {
const target = get(currentVoiceRoom) const target = get(currentVoiceRoom)
if (target) joinVoiceRoom(target.url, target.h) if (!target) return
void joinVoiceRoom(target.url, target.h)
} }
export const toggleMute = async () => { export const toggleMute = async () => {