forked from coracle/flotilla
Voice Room Membership Error (#106)
Before this we were showing "Failed to join voice room" if the relay rejected our request for a livekit token because we aren't a member of the room. Now it shows the error "Failed to join voice room: you must be a member." Co-authored-by: mplorentz <mplorentz@noreply.gitea.coracle.social> Reviewed-on: coracle/flotilla#106 Co-authored-by: Matt Lorentz <mplorentz@noreply.coracle.social> Co-committed-by: Matt Lorentz <mplorentz@noreply.coracle.social>
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
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 {handleJoinError} from "@app/components/VoiceWidget.svelte"
|
||||||
import {makeRoomPath} from "@app/util/routes"
|
import {makeRoomPath} from "@app/util/routes"
|
||||||
import {
|
import {
|
||||||
deriveVoiceParticipants,
|
deriveVoiceParticipants,
|
||||||
@@ -42,12 +42,7 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
await joinVoiceRoom(url, h).catch(handleJoinError)
|
||||||
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(() => {
|
||||||
|
|||||||
@@ -1,3 +1,20 @@
|
|||||||
|
<script module lang="ts">
|
||||||
|
import {AbortError, TimeoutError} from "$lib/util"
|
||||||
|
import {VoiceJoinMembershipError} from "@app/voice"
|
||||||
|
import {pushToast} from "@app/util/toast"
|
||||||
|
|
||||||
|
export function 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})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {fly} from "svelte/transition"
|
import {fly} from "svelte/transition"
|
||||||
import {displayRelayUrl} from "@welshman/util"
|
import {displayRelayUrl} from "@welshman/util"
|
||||||
@@ -23,6 +40,10 @@
|
|||||||
$currentVoiceRoom ? displayRoom($currentVoiceRoom.url, $currentVoiceRoom.h) : "",
|
$currentVoiceRoom ? displayRoom($currentVoiceRoom.url, $currentVoiceRoom.h) : "",
|
||||||
)
|
)
|
||||||
const spaceName = $derived($currentVoiceRoom ? displayRelayUrl($currentVoiceRoom.url) : "")
|
const spaceName = $derived($currentVoiceRoom ? displayRelayUrl($currentVoiceRoom.url) : "")
|
||||||
|
|
||||||
|
const handleRejoin = () => {
|
||||||
|
void rejoinVoiceRoom().catch(handleJoinError)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $currentVoiceRoom}
|
{#if $currentVoiceRoom}
|
||||||
@@ -70,7 +91,7 @@
|
|||||||
<Button
|
<Button
|
||||||
data-tip="Join Voice"
|
data-tip="Join Voice"
|
||||||
class="center tooltip tooltip-top btn btn-sm btn-square btn-success"
|
class="center tooltip tooltip-top btn btn-sm btn-square btn-success"
|
||||||
onclick={rejoinVoiceRoom}>
|
onclick={handleRejoin}>
|
||||||
<Icon icon={PhoneCallingRounded} size={4} />
|
<Icon icon={PhoneCallingRounded} size={4} />
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
+11
-3
@@ -17,6 +17,13 @@ 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export type VoiceSession = {
|
export type VoiceSession = {
|
||||||
url: string
|
url: string
|
||||||
h: string
|
h: string
|
||||||
@@ -95,6 +102,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,7 +251,6 @@ 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
|
|
||||||
throw e
|
throw e
|
||||||
} finally {
|
} finally {
|
||||||
if (isActive()) joinAbortController = undefined
|
if (isActive()) joinAbortController = undefined
|
||||||
@@ -264,9 +271,10 @@ export const leaveVoiceRoom = async () => {
|
|||||||
participantPubkeyMap.set(new Map())
|
participantPubkeyMap.set(new Map())
|
||||||
}
|
}
|
||||||
|
|
||||||
export const rejoinVoiceRoom = () => {
|
export const rejoinVoiceRoom = async (): Promise<void> => {
|
||||||
const target = get(currentVoiceRoom)
|
const target = get(currentVoiceRoom)
|
||||||
if (target) joinVoiceRoom(target.url, target.h)
|
if (!target) return
|
||||||
|
return joinVoiceRoom(target.url, target.h)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toggleMute = async () => {
|
export const toggleMute = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user