File tree 1 file changed +20
-7
lines changed
src/engines/BandwidthEngine
1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,12 @@ class BandwidthMeasurementEngine {
64
64
this . #throttleMs = throttleMs ;
65
65
this . #estimatedServerTime = Math . max ( 0 , estimatedServerTime ) ;
66
66
67
- document . addEventListener ( 'visibilitychange' , this . #handleVisibilityChange) ;
67
+ if ( typeof document !== 'undefined' ) {
68
+ document . addEventListener (
69
+ 'visibilitychange' ,
70
+ this . #handleVisibilityChange
71
+ ) ;
72
+ }
68
73
}
69
74
70
75
// Public attributes
@@ -90,9 +95,15 @@ class BandwidthMeasurementEngine {
90
95
}
91
96
92
97
#handleVisibilityChange = ( ) => {
93
- if ( document . visibilityState === 'hidden' ) {
98
+ if (
99
+ typeof document !== 'undefined' &&
100
+ document . visibilityState === 'hidden'
101
+ ) {
94
102
this . pause ( ) ;
95
- } else if ( document . visibilityState === 'visible' ) {
103
+ } else if (
104
+ typeof document !== 'undefined' &&
105
+ document . visibilityState === 'visible'
106
+ ) {
96
107
this . play ( ) ;
97
108
}
98
109
} ;
@@ -383,10 +394,12 @@ class BandwidthMeasurementEngine {
383
394
}
384
395
385
396
deleteEventListener ( ) {
386
- document . removeEventListener (
387
- 'visibilitychange' ,
388
- this . #handleVisibilityChange
389
- ) ;
397
+ if ( typeof document !== 'undefined' ) {
398
+ document . removeEventListener (
399
+ 'visibilitychange' ,
400
+ this . #handleVisibilityChange
401
+ ) ;
402
+ }
390
403
}
391
404
}
392
405
You can’t perform that action at this time.
0 commit comments