personal web client for Bluesky
typescript solidjs bluesky atcute

feat: store video bandwidth estimate

mary.my.id 543e25fb 095847d4

verified
Changed files
+19 -1
src
components
embeds
lib
preferences
states
+16 -1
src/components/embeds/players/video-player.tsx
··· 21 21 22 22 const [playing, setPlaying] = createSignal(false); 23 23 24 + const bwEstimate = currentAccount?.preferences.ui.videoBwEstimate; 24 25 const hls = new Hls({ 25 26 capLevelToPlayerSize: true, 26 - startLevel: 1, 27 + 28 + // the '-1' value makes a test request to estimate bandwidth and quality level 29 + // before showing the first fragment 30 + startLevel: bwEstimate === undefined ? -1 : Hls.DefaultConfig.startLevel, 31 + 27 32 xhrSetup(xhr, urlString) { 28 33 // We want to replace the URL here so it points directly to the CDN, 29 34 // and not the middleware service. ··· 46 51 }, 47 52 }); 48 53 54 + if (bwEstimate !== undefined) { 55 + hls.bandwidthEstimate = bwEstimate; 56 + } 57 + 49 58 onCleanup(() => hls.destroy()); 50 59 51 60 hls.loadSource(embed.playlist); ··· 60 69 if (!isMobile && currentAccount) { 61 70 node.volume = currentAccount.preferences.ui.mediaVolume; 62 71 } 72 + 73 + hls.on(Hls.Events.FRAG_LOADED, () => { 74 + if (currentAccount) { 75 + currentAccount.preferences.ui.videoBwEstimate = hls.bandwidthEstimate; 76 + } 77 + }); 63 78 64 79 hls.on(Hls.Events.LEVEL_LOADED, (_event, data) => { 65 80 const hasAudio = data.levelInfo.audioCodec !== undefined;
+2
src/lib/preferences/account.ts
··· 14 14 } 15 15 16 16 export interface UIPreferences { 17 + /** Media bandwidth estimate */ 18 + videoBwEstimate: number | undefined; 17 19 /** Media player volume */ 18 20 mediaVolume: number; 19 21 }
+1
src/lib/states/session.tsx
··· 288 288 }, 289 289 ], 290 290 ui: { 291 + videoBwEstimate: undefined, 291 292 mediaVolume: 0.25, 292 293 }, 293 294 composer: {