@@ -7,7 +7,11 @@ import {
77 HlsUrlParameters ,
88 type Level ,
99} from '../types/level' ;
10- import { getRetryDelay , isTimeoutError } from '../utils/error-helper' ;
10+ import {
11+ getRetryDelay ,
12+ isTimeoutError ,
13+ offlineHttpStatus ,
14+ } from '../utils/error-helper' ;
1115import { computeReloadInterval , mergeDetails } from '../utils/level-helper' ;
1216import { Logger } from '../utils/logger' ;
1317import type Hls from '../hls' ;
@@ -426,20 +430,37 @@ export default class BasePlaylistController
426430 ) ;
427431 this . loadPlaylist ( ) ;
428432 } else {
429- const delay = getRetryDelay ( retryConfig , retryCount ) ;
433+ const offlineStatus = offlineHttpStatus ( errorEvent . response ?. code ) ;
430434 // Schedule level/track reload
431435 this . clearTimer ( ) ;
432- this . timer = self . setTimeout ( ( ) => this . loadPlaylist ( ) , delay ) ;
433- this . warn (
434- `Retrying playlist loading ${ retryCount + 1 } /${
435- retryConfig . maxNumRetry
436- } after "${ errorDetails } " in ${ delay } ms`,
437- ) ;
436+ if ( offlineStatus ) {
437+ this . log ( `Waiting for connection (offline)` ) ;
438+ errorEvent . reason = 'offline' ;
439+ this . timer = self . setTimeout ( ( ) => this . checkOfflineStatus ( ) , 1000 ) ;
440+ } else {
441+ const delay = getRetryDelay ( retryConfig , retryCount ) ;
442+ this . warn (
443+ `Retrying playlist loading ${ retryCount + 1 } /${
444+ retryConfig . maxNumRetry
445+ } after "${ errorDetails } " in ${ delay } ms`,
446+ ) ;
447+ this . timer = self . setTimeout ( ( ) => this . loadPlaylist ( ) , delay ) ;
448+ }
438449 }
439450 // `levelRetry = true` used to inform other controllers that a retry is happening
440451 errorEvent . levelRetry = true ;
441452 errorAction . resolved = true ;
442453 }
443454 return retry ;
444455 }
456+
457+ private checkOfflineStatus ( ) {
458+ this . clearTimer ( ) ;
459+ if ( offlineHttpStatus ( 0 ) ) {
460+ this . timer = self . setTimeout ( ( ) => this . checkOfflineStatus ( ) , 1000 ) ;
461+ } else {
462+ this . log ( `Connection restored (online)` ) ;
463+ this . loadPlaylist ( ) ;
464+ }
465+ }
445466}
0 commit comments