diff --git a/src/ui/hls/hls.html b/src/ui/player/player.html similarity index 70% rename from src/ui/hls/hls.html rename to src/ui/player/player.html index 6ff202f..8bcf77d 100644 --- a/src/ui/hls/hls.html +++ b/src/ui/player/player.html @@ -3,8 +3,8 @@ HLS - - + + diff --git a/src/ui/hls/hls.sass b/src/ui/player/player.sass similarity index 100% rename from src/ui/hls/hls.sass rename to src/ui/player/player.sass diff --git a/src/ui/hls/hls.ts b/src/ui/player/player.ts similarity index 88% rename from src/ui/hls/hls.ts rename to src/ui/player/player.ts index 0ee2591..0f3cd18 100644 --- a/src/ui/hls/hls.ts +++ b/src/ui/player/player.ts @@ -1,4 +1,4 @@ -import {matches, Reliability} from "../../match/match"; +import {Match, matches, Reliability} from "../../match/match"; // @ts-ignore import Hls from "hls.js"; @@ -8,18 +8,13 @@ function show_message(message: string) { document.getElementById('video').hidden = true } -async function main() { - const urlQuery = new URLSearchParams(window.location.search) - const id = urlQuery.get('id') - const url = urlQuery.get('url') - - const match = matches.find((m) => m.id === id) - if (match === undefined) { - show_message(`Invalid id: ${id}. Please report this here`) - return - } - document.title = match.name +async function play_native(url: string, match: Match) { + const video = document.getElementById('video') as HTMLVideoElement + video.controls = true + video.src = url +} +async function play_hls(url: string, match: Match) { const video = document.getElementById('video') as HTMLVideoElement video.controls = true @@ -66,4 +61,19 @@ async function main() { } } +async function main() { + const urlQuery = new URLSearchParams(window.location.search) + const id = urlQuery.get('id') + const url = urlQuery.get('url') + + const match = matches.find((m) => m.id === id) + if (match === undefined) { + show_message(`Invalid id: ${id}. Please report this here`) + return + } + document.title = match.name + + url.endsWith('.m3u8') ? await play_hls(url, match) : await play_native(url, match) +} + main() diff --git a/tasks/build.ts b/tasks/build.ts index c08c5a2..e674299 100644 --- a/tasks/build.ts +++ b/tasks/build.ts @@ -80,7 +80,7 @@ async function buildMisc() { async function buildHtml() { const files = { 'src/ui/popup/popup.html': 'build/ui/popup/popup.html', - 'src/ui/hls/hls.html': 'build/ui/hls/hls.html' + 'src/ui/player/player.html': 'build/ui/player/player.html' } for (const [src, dst] of Object.entries(files)) { @@ -92,7 +92,7 @@ async function buildHtml() { async function buildCss() { const files = { 'src/ui/popup/popup.sass': 'build/ui/popup/popup.css', - 'src/ui/hls/hls.sass': 'build/ui/hls/hls.css' + 'src/ui/player/player.sass': 'build/ui/player/player.css' } for (const [src, dst] of Object.entries(files)) { @@ -108,7 +108,7 @@ async function buildCss() { async function buildJs() { const files = { 'src/ui/popup/popup.ts': 'build/ui/popup/popup.js', - 'src/ui/hls/hls.ts': 'build/ui/hls/hls.js', + 'src/ui/player/player.ts': 'build/ui/player/player.js', 'src/index.ts': 'build/index.js' }