diff options
author | metamuffin <metamuffin@disroot.org> | 2023-12-23 00:43:42 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-12-23 00:43:42 +0100 |
commit | 0b53d68b214b022a4ae6292785c165ad95e71696 (patch) | |
tree | 1532b6619fd2598af1c73018b7ec339145d81602 /web/script/player/player.ts | |
parent | 75949cebdd61dd8f0d06f2e47081c460e2a442f0 (diff) | |
download | jellything-0b53d68b214b022a4ae6292785c165ad95e71696.tar jellything-0b53d68b214b022a4ae6292785c165ad95e71696.tar.bz2 jellything-0b53d68b214b022a4ae6292785c165ad95e71696.tar.zst |
rework ~~import~~ system pt. 8.1: update the player to new format
Diffstat (limited to 'web/script/player/player.ts')
-rw-r--r-- | web/script/player/player.ts | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/web/script/player/player.ts b/web/script/player/player.ts index c07fa37..7ffdb97 100644 --- a/web/script/player/player.ts +++ b/web/script/player/player.ts @@ -4,20 +4,18 @@ Copyright (C) 2023 metamuffin <metamuffin.org> */ import { OVar, e } from "../jshelper/mod.ts"; -import { JhlsMetadata, JhlsTrack, TimeRange } from "./jhls.d.ts"; +import { NodePublic, SourceTrack, TimeRange } from "./jhls.d.ts"; import { SegmentDownloader } from "./download.ts"; import { PlayerTrack } from "./track.ts"; -import { ProfileSelector } from "./profiles.ts"; import { Logger } from "../jshelper/src/log.ts"; export interface BufferRange extends TimeRange { status: "buffered" | "loading" | "queued" } export class Player { public video = e("video") public media_source = new MediaSource(); - public tracks?: JhlsTrack[]; + public tracks?: SourceTrack[]; public active_tracks = new OVar<PlayerTrack[]>([]); public downloader: SegmentDownloader = new SegmentDownloader(); - public profile_selector!: ProfileSelector public position = new OVar(0) public duration = new OVar(1) @@ -31,7 +29,7 @@ export class Player { if (s) this.cancel_buffering_pers = this.logger?.log_persistent(s) } - constructor(private node_id: string, public logger?: Logger<string>) { + constructor(public node_id: string, public logger?: Logger<string>) { this.video.onloadedmetadata = () => { } this.video.ondurationchange = () => { } this.video.ontimeupdate = () => { @@ -80,26 +78,22 @@ export class Player { } async fetch_meta() { - this.set_pers("Loading media manifest...") - const res = await fetch(`/n/${encodeURIComponent(this.node_id)}/stream?format=jhls`, { headers: { "Accept": "application/json" } }) - if (!res.ok) return this.error.value = "Cannot download JHLS metadata" - let metadata!: JhlsMetadata & { error: string } + this.set_pers("Loading node...") + const res = await fetch(`/n/${encodeURIComponent(this.node_id)}`, { headers: { "Accept": "application/json" } }) + if (!res.ok) return this.error.value = "Cannot download node." + let metadata!: NodePublic & { error: string } try { metadata = await res.json() } - catch (_) { this.set_pers("Error: Failed to fetch stream info") } + catch (_) { this.set_pers("Error: Failed to fetch node") } if (metadata.error) return this.set_pers("server error: " + metadata.error) this.set_pers() - this.tracks = metadata.tracks + this.tracks = metadata.media!.tracks - this.profile_selector = new ProfileSelector(this, this.downloader.bandwidth, metadata) - this.set_pers("Checking codec support...") - await this.profile_selector.init() - - this.duration.value = metadata.duration + 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.active_tracks.value.push(await PlayerTrack.new(this, this.node_id, 0, metadata.tracks[0])) - this.active_tracks.value.push(await PlayerTrack.new(this, this.node_id, 1, metadata.tracks[1])) + 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() this.set_pers("Downloading initial segments...") this.update() |