refactor: share stream url
This commit is contained in:
@@ -3,17 +3,9 @@ import { showControls } from "./controls";
|
||||
import { updateSubtitleOptions } from "./subtitles";
|
||||
import { updateQualityOptions } from "./quality";
|
||||
import { safeLocalStorage } from "./storage";
|
||||
import { streamUrlForMode } from "./source";
|
||||
import { loadVideoSource } from "./video";
|
||||
|
||||
// builds stream URL with mode, token, and optional quality param
|
||||
const streamUrlForMode = (mode: string, quality?: string): string => {
|
||||
const src = state.modeSources[mode];
|
||||
if (!src?.token) return "";
|
||||
let url = `${state.streamURL}?mode=${encodeURIComponent(mode)}&token=${encodeURIComponent(src.token)}`;
|
||||
if (quality && quality !== "best") url += `&quality=${encodeURIComponent(quality)}`;
|
||||
return url;
|
||||
};
|
||||
|
||||
/**
|
||||
* Switches between sub/dub mode.
|
||||
* Saves preference to localStorage, reloads video src.
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
import { state } from "./state";
|
||||
import { streamUrlForMode } from "./source";
|
||||
import { safeLocalStorage } from "./storage";
|
||||
import { loadVideoSource } from "./video";
|
||||
|
||||
// same as mode.ts - could be extracted to shared util
|
||||
const streamUrlForMode = (mode: string, quality?: string): string => {
|
||||
const src = state.modeSources[mode];
|
||||
if (!src?.token) return "";
|
||||
let url = `${state.streamURL}?mode=${encodeURIComponent(mode)}&token=${encodeURIComponent(src.token)}`;
|
||||
if (quality && quality !== "best") url += `&quality=${encodeURIComponent(quality)}`;
|
||||
return url;
|
||||
};
|
||||
|
||||
/**
|
||||
* Switches video quality (resolution).
|
||||
* Persists preference to localStorage.
|
||||
|
||||
13
static/player/source.ts
Normal file
13
static/player/source.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { state } from "./state";
|
||||
|
||||
export const streamUrlForMode = (mode: string, quality?: string): string => {
|
||||
const src = state.modeSources[mode];
|
||||
if (!src?.token) return "";
|
||||
|
||||
let url = `${state.streamURL}?mode=${encodeURIComponent(mode)}&token=${encodeURIComponent(src.token)}`;
|
||||
if (quality && quality !== "best") {
|
||||
url += `&quality=${encodeURIComponent(quality)}`;
|
||||
}
|
||||
|
||||
return url;
|
||||
};
|
||||
Reference in New Issue
Block a user