aboutsummaryrefslogtreecommitdiff
path: root/web/script/player/track.ts
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-12-25 16:23:44 +0100
committermetamuffin <metamuffin@disroot.org>2023-12-25 16:23:44 +0100
commite2c62c34b4c2983b8ceef034347bc62b28a88122 (patch)
treec43eaf7dcf5a468c918bafb6b7e223ec73607e09 /web/script/player/track.ts
parentc5d484e16bae5d923f6a3c441827d3d470bfee6e (diff)
downloadjellything-e2c62c34b4c2983b8ceef034347bc62b28a88122.tar
jellything-e2c62c34b4c2983b8ceef034347bc62b28a88122.tar.bz2
jellything-e2c62c34b4c2983b8ceef034347bc62b28a88122.tar.zst
lib=dom everywhere and error handling
Diffstat (limited to 'web/script/player/track.ts')
-rw-r--r--web/script/player/track.ts25
1 files changed, 16 insertions, 9 deletions
diff --git a/web/script/player/track.ts b/web/script/player/track.ts
index c6f90b4..df7ab69 100644
--- a/web/script/player/track.ts
+++ b/web/script/player/track.ts
@@ -3,6 +3,7 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
+/// <reference lib="dom" />
import { JhlsTrackIndex, SourceTrack, TimeRange } from "./jhls.d.ts";
import { OVar } from "../jshelper/mod.ts";
import { profile_to_partial_track, track_to_content_type } from "./mediacaps.ts";
@@ -24,16 +25,22 @@ export class PlayerTrack {
public profile_selector: ProfileSelector
public static async new(player: Player, node_id: string, track_index: number, metadata: SourceTrack): Promise<PlayerTrack | undefined> {
- const res = await fetch(`/n/${encodeURIComponent(player.node_id)}/stream?format=jhlsi&tracks=${track_index}`, { headers: { "Accept": "application/json" } })
- if (!res.ok) return player.error.value = "Cannot download node.", undefined
- let index!: JhlsTrackIndex & { error: string }
- try { index = await res.json() }
- catch (_) { player.set_pers("Error: Failed to fetch node") }
- if (index.error) return player.set_pers("server error: " + index.error), undefined
+ try {
+ const res = await fetch(`/n/${encodeURIComponent(player.node_id)}/stream?format=jhlsi&tracks=${track_index}`, { headers: { "Accept": "application/json" } })
+ if (!res.ok) return player.error.value = "Cannot download index.", undefined
+ let index!: JhlsTrackIndex & { error: string }
+ try { index = await res.json() }
+ catch (_) { player.set_pers("Error: Failed to fetch node") }
+ if (index.error) return player.set_pers("server error: " + index.error), undefined
- const t = new PlayerTrack(player, node_id, track_index, metadata, index)
- await t.init()
- return t
+ const t = new PlayerTrack(player, node_id, track_index, metadata, index)
+ await t.init()
+ return t
+ } catch (e) {
+ if (e instanceof TypeError) {
+ player.set_pers("Cannot download index: Network Error")
+ } else throw e
+ }
}
constructor(
private player: Player,