mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-03-11 09:35:42 +00:00
Merge pull request #608 from chrisk325/patch-16
fix edge case trailer unmount logic
This commit is contained in:
commit
237bf51b66
3 changed files with 15 additions and 18 deletions
|
|
@ -1144,6 +1144,7 @@ const HeroSection: React.FC<HeroSectionProps> = memo(({
|
|||
setTrailerError(false);
|
||||
setTrailerReady(false);
|
||||
setTrailerPreloaded(false);
|
||||
startedOnReadyRef.current = false;
|
||||
|
||||
// Small delay to avoid blocking the UI render
|
||||
timerId = setTimeout(async () => {
|
||||
|
|
|
|||
|
|
@ -159,28 +159,19 @@ const TrailerModal: React.FC<TrailerModalProps> = memo(({
|
|||
const handleVideoError = useCallback((error: any) => {
|
||||
logger.error('TrailerModal', 'Video error:', error);
|
||||
|
||||
const errorCode = error?.error?.code;
|
||||
const isRetryableError = errorCode === -1102 || errorCode === -1009 || errorCode === -1005;
|
||||
|
||||
if (isRetryableError && retryCount < 2) {
|
||||
logger.info('TrailerModal', `Retrying video load (attempt ${retryCount + 1}/2)`);
|
||||
if (retryCount < 2) {
|
||||
logger.info('TrailerModal', `Re-extracting trailer (attempt ${retryCount + 1}/2)`);
|
||||
setRetryCount(prev => prev + 1);
|
||||
|
||||
// Capture current URL before clearing it
|
||||
setTrailerUrl(current => {
|
||||
const urlToRestore = current;
|
||||
setTimeout(() => {
|
||||
setTrailerUrl(urlToRestore);
|
||||
}, 500);
|
||||
return null; // Clear first to force remount
|
||||
});
|
||||
// Invalidate cache so loadTrailer gets a fresh URL, not the same bad one
|
||||
if (trailer?.key) TrailerService.invalidateCache(trailer.key);
|
||||
loadTrailer();
|
||||
return;
|
||||
}
|
||||
|
||||
logger.error('TrailerModal', 'Video error after retries or non-retryable:', error);
|
||||
logger.error('TrailerModal', 'Video error after retries:', error);
|
||||
setError('Unable to play trailer. Please try again.');
|
||||
setLoading(false);
|
||||
}, [retryCount]);
|
||||
}, [retryCount, loadTrailer, trailer?.key]);
|
||||
|
||||
const handleTrailerEnd = useCallback(() => {
|
||||
setIsPlaying(false);
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ interface CacheEntry {
|
|||
}
|
||||
|
||||
export class TrailerService {
|
||||
// Cache for 3 minutes — just enough to avoid re-extracting on quick re-renders
|
||||
private static readonly CACHE_TTL_MS = 30 * 1000;
|
||||
// Cache for 5 seconds — just enough to avoid re-extracting on quick re-renders
|
||||
private static readonly CACHE_TTL_MS = 5 * 1000;
|
||||
private static urlCache = new Map<string, CacheEntry>();
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
@ -114,6 +114,11 @@ export class TrailerService {
|
|||
return { url, title, year };
|
||||
}
|
||||
|
||||
static invalidateCache(videoId: string): void {
|
||||
this.urlCache.delete(videoId);
|
||||
logger.info('TrailerService', `Cache invalidated for videoId=${videoId}`);
|
||||
}
|
||||
|
||||
static setUseLocalServer(_useLocal: boolean): void {}
|
||||
|
||||
static getServerStatus(): { usingLocal: boolean; localUrl: string } {
|
||||
|
|
|
|||
Loading…
Reference in a new issue