@@ -282,6 +282,7 @@ export class SabrStream extends PassThrough {
282282 this . startTime = config . startTime || 0 ;
283283 this . positionCallback = config . positionCallback ;
284284 this . userAgent = config . userAgent || USER_AGENT ;
285+ this . recoveryPending = false ;
285286
286287
287288
@@ -354,6 +355,10 @@ export class SabrStream extends PassThrough {
354355 try {
355356 if ( this . lastVirtualAdvanceAt === 0 ) this . lastVirtualAdvanceAt = Date . now ( ) ;
356357 while ( ! this . _aborted && ! this . destroyed && ! this . streamFinished ) {
358+ if ( this . recoveryPending ) {
359+ await wait ( 500 , signal ) ;
360+ continue ;
361+ }
357362 if ( this . requestNumber === 0 ) {
358363 try {
359364 const tokenData = await poTokenManager . generate ( this . videoId , this . visitorData ) ;
@@ -485,6 +490,18 @@ export class SabrStream extends PassThrough {
485490 logger ( 'error' , 'SABR' , `Failed to decode PO token (session update): ${ e . message } ` ) ;
486491 }
487492 }
493+ if ( config . visitorData ) {
494+ this . visitorData = config . visitorData ;
495+ }
496+ if ( config . clientInfo ) {
497+ this . clientInfo = config . clientInfo ;
498+ }
499+ if ( config . formats ) {
500+ this . formatIds = config . formats ;
501+ }
502+ if ( config . userAgent ) {
503+ this . userAgent = config . userAgent ;
504+ }
488505 if ( config . playbackCookie ) {
489506 if ( ! this . nextRequestPolicy ) this . nextRequestPolicy = { } ;
490507 this . nextRequestPolicy . playbackCookie = config . playbackCookie ;
@@ -494,6 +511,7 @@ export class SabrStream extends PassThrough {
494511 this . requestNumber = 0 ;
495512 this . noMediaStreak = 0 ;
496513 this . pendingRangesHeaders . clear ( ) ;
514+ this . recoveryPending = false ;
497515
498516 logger ( 'info' , 'SABR' , `Session updated. Continuing with RN=${ this . requestNumber } , URL=${ this . serverAbrStreamingUrl . slice ( 0 , 50 ) } ...` ) ;
499517 }
@@ -616,6 +634,7 @@ export class SabrStream extends PassThrough {
616634 if ( status . status === 2 ) {
617635 logger ( 'warn' , 'SABR' , `Stream Protection Status: ${ status . status } (Limited Playback). Triggering token refresh...` ) ;
618636 poTokenManager . reset ( ) ;
637+ this . recoveryPending = true ;
619638 this . emit ( 'stall' ) ;
620639 return ;
621640 }
0 commit comments