diff options
-rw-r--r-- | web/script/backbutton.ts | 1 | ||||
-rw-r--r-- | web/script/main.ts | 1 | ||||
-rw-r--r-- | web/script/player/download.ts | 1 | ||||
-rw-r--r-- | web/script/player/mediacaps.ts | 1 | ||||
-rw-r--r-- | web/script/player/mod.ts | 1 | ||||
-rw-r--r-- | web/script/player/player.ts | 3 | ||||
-rw-r--r-- | web/script/player/popup.ts | 1 | ||||
-rw-r--r-- | web/script/player/profiles.ts | 1 | ||||
-rw-r--r-- | web/script/player/track.ts | 25 |
9 files changed, 25 insertions, 10 deletions
diff --git a/web/script/backbutton.ts b/web/script/backbutton.ts index 4bd73c0..27a7ac2 100644 --- a/web/script/backbutton.ts +++ b/web/script/backbutton.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 { e } from "./jshelper/mod.ts"; globalThis.addEventListener("DOMContentLoaded", () => { diff --git a/web/script/main.ts b/web/script/main.ts index dd168d5..0b4bdbd 100644 --- a/web/script/main.ts +++ b/web/script/main.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 "./player/mod.ts" import "./transition.ts" import "./backbutton.ts" diff --git a/web/script/player/download.ts b/web/script/player/download.ts index 2c3b104..2549600 100644 --- a/web/script/player/download.ts +++ b/web/script/player/download.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 { OVar } from "../jshelper/mod.ts"; interface Measurement { time: number, duration: number, size: number } diff --git a/web/script/player/mediacaps.ts b/web/script/player/mediacaps.ts index 357c813..2c58c48 100644 --- a/web/script/player/mediacaps.ts +++ b/web/script/player/mediacaps.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 { EncodingProfile, SourceTrack, SourceTrackKind } from "./jhls.d.ts"; const cache = new Map<string, boolean>() diff --git a/web/script/player/mod.ts b/web/script/player/mod.ts index 5db257d..bfc9eba 100644 --- a/web/script/player/mod.ts +++ b/web/script/player/mod.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 { OVar, show } from "../jshelper/mod.ts"; import { e } from "../jshelper/mod.ts"; import { Logger } from "../jshelper/src/log.ts"; diff --git a/web/script/player/player.ts b/web/script/player/player.ts index 7ffdb97..d988374 100644 --- a/web/script/player/player.ts +++ b/web/script/player/player.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 { OVar, e } from "../jshelper/mod.ts"; import { NodePublic, SourceTrack, TimeRange } from "./jhls.d.ts"; import { SegmentDownloader } from "./download.ts"; @@ -91,7 +92,7 @@ export class Player { this.duration.value = metadata.media!.duration this.video.src = URL.createObjectURL(this.media_source) this.media_source.addEventListener("sourceopen", async () => { - this.set_pers("Initializing Media Extensions...") + this.set_pers("Downloading track indecies...") this.active_tracks.value.push((await PlayerTrack.new(this, this.node_id, 0, this.tracks![0]))!) // TODO unsafe and missing ui anyway this.active_tracks.value.push((await PlayerTrack.new(this, this.node_id, 1, this.tracks![1]))!) this.active_tracks.change() diff --git a/web/script/player/popup.ts b/web/script/player/popup.ts index 394f572..441f8d1 100644 --- a/web/script/player/popup.ts +++ b/web/script/player/popup.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" /> export class Popup { trigger_hov = false diff --git a/web/script/player/profiles.ts b/web/script/player/profiles.ts index ec82a6d..f7fd121 100644 --- a/web/script/player/profiles.ts +++ b/web/script/player/profiles.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 { OVar } from "../jshelper/mod.ts"; import { EncodingProfile } from "./jhls.d.ts"; import { profile_to_partial_track, test_media_capability } from "./mediacaps.ts"; 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, |