diff options
author | Samuel Newman <mozzius@protonmail.com> | 2025-05-30 00:24:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-30 00:24:01 +0300 |
commit | 7b3916c8cc8fc21127b80b9732e047b5549333a9 (patch) | |
tree | ec4a967d3d4307e8229062ad67e42ca1668ee701 /src | |
parent | bc42d26bc519a26bb94bddc21fa1001b74afea25 (diff) | |
download | voidsky-7b3916c8cc8fc21127b80b9732e047b5549333a9.tar.zst |
Share bandwidth estimate between video instances (#8377)
Diffstat (limited to 'src')
-rw-r--r-- | src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx | 12 | ||||
-rw-r--r-- | src/view/com/util/post-embeds/VideoEmbedInner/bandwidth-estimate.ts | 11 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx b/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx index e6882a2f6..77f6cd0a6 100644 --- a/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx +++ b/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx @@ -1,6 +1,6 @@ import React, {useEffect, useId, useRef, useState} from 'react' import {View} from 'react-native' -import {AppBskyEmbedVideo} from '@atproto/api' +import {type AppBskyEmbedVideo} from '@atproto/api' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import type * as HlsTypes from 'hls.js' @@ -8,6 +8,7 @@ import type * as HlsTypes from 'hls.js' import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' import {atoms as a} from '#/alf' import {MediaInsetBorder} from '#/components/MediaInsetBorder' +import * as BandwidthEstimate from './bandwidth-estimate' import {Controls} from './web-controls/VideoControls' export function VideoEmbedInnerWeb({ @@ -231,6 +232,11 @@ function useHLS({ }) hlsRef.current = hls + const latestEstimate = BandwidthEstimate.get() + if (latestEstimate !== undefined) { + hls.bandwidthEstimate = latestEstimate + } + hls.attachMedia(videoRef.current) hls.loadSource(playlist) @@ -248,6 +254,10 @@ function useHLS({ {signal}, ) + hls.on(Hls.Events.FRAG_LOADED, () => { + BandwidthEstimate.set(hls.bandwidthEstimate) + }) + hls.on(Hls.Events.SUBTITLE_TRACKS_UPDATED, (_event, data) => { if (data.subtitleTracks.length > 0) { setHasSubtitleTrack(true) diff --git a/src/view/com/util/post-embeds/VideoEmbedInner/bandwidth-estimate.ts b/src/view/com/util/post-embeds/VideoEmbedInner/bandwidth-estimate.ts new file mode 100644 index 000000000..122e10aef --- /dev/null +++ b/src/view/com/util/post-embeds/VideoEmbedInner/bandwidth-estimate.ts @@ -0,0 +1,11 @@ +let latestBandwidthEstimate: number | undefined + +export function get() { + return latestBandwidthEstimate +} + +export function set(estimate: number) { + if (!isNaN(estimate)) { + latestBandwidthEstimate = estimate + } +} |