8
8
ListenerManager ,
9
9
} from "../CommonMethods/index" ;
10
10
import { buildUUID } from "../IdGenerationMethod/index" ;
11
- import { createTimerWorker , inlineWorkerText } from "../Worker/index" ;
12
11
import { BufferMonitor , BufferProcessor } from "./VideoBufferMonitor" ;
13
12
import { ErrorManager } from "./ErrorManager" ;
14
13
import { PlaybackEventHandler } from "./PlayerEventHandler" ;
@@ -56,14 +55,15 @@ function nucleusState(
56
55
disableCookies : actionableData . disableCookies ?? false ,
57
56
respectDoNotTrack : actionableData . respectDoNotTrack ?? false ,
58
57
allowRebufferTracking : false ,
59
- disablePlayheadRebufferTracking : false ,
58
+ disablePlayheadRebufferTracking :
59
+ actionableData . disablePlayheadRebufferTracking ?? false ,
60
60
errorConverter : function ( errAttr : any ) {
61
61
return errAttr ;
62
62
} ,
63
63
} ;
64
64
actionableData = {
65
- actionableData,
66
65
...defaultConfig ,
66
+ actionableData,
67
67
} ;
68
68
fileInstance . userConfigData = actionableData ;
69
69
fileInstance . fetchPlayheadTime =
@@ -90,34 +90,7 @@ function nucleusState(
90
90
fileInstance . data . view_sequence_number = 1 ;
91
91
fileInstance . data . player_sequence_number = 1 ;
92
92
fileInstance . lastCheckedEventTime = void 0 ;
93
-
94
- // Initiating web workers
95
- fileInstance . worker = createTimerWorker ( inlineWorkerText ) ;
96
-
97
- // Message from web worker
98
- fileInstance . worker . onmessage = function ( message : any ) {
99
- let messageCommand : string = message . data . command ;
100
-
101
- switch ( messageCommand ) {
102
- case "pulseStart" :
103
- fileInstance . dispatch ( messageCommand ) ;
104
- fileInstance . handlePulse . pulseInterval = true ;
105
- break ;
106
-
107
- case "pulseEnd" :
108
- fileInstance . playheadProgressing = false ;
109
- fileInstance . dispatch ( messageCommand ) ;
110
- fileInstance . handlePulse . pulseInterval = false ;
111
- break ;
112
-
113
- case "emitPulse" :
114
- fileInstance . dispatch ( "pulse" ) ;
115
- break ;
116
-
117
- default :
118
- return ;
119
- }
120
- } ;
93
+ fileInstance . throbTimeoutId = undefined ;
121
94
122
95
fileInstance . dispatch = function (
123
96
name : string ,
@@ -176,7 +149,10 @@ function nucleusState(
176
149
fileInstance . demolishView ( ) ;
177
150
} ;
178
151
179
- if ( window && typeof window !== "undefined" ) {
152
+ if (
153
+ typeof window !== "undefined" &&
154
+ typeof window . addEventListener !== "undefined"
155
+ ) {
180
156
window . addEventListener (
181
157
"pagehide" ,
182
158
function ( event ) {
@@ -389,8 +365,6 @@ nucleusState.prototype.validateData = function () {
389
365
} ;
390
366
391
367
nucleusState . prototype . filterData = function ( str : string ) {
392
- const workerInstance = this ;
393
-
394
368
if ( this . data . view_id ) {
395
369
if (
396
370
this . data . player_source_duration > 0 ||
@@ -413,18 +387,29 @@ nucleusState.prototype.filterData = function (str: string) {
413
387
this . eventsDispatcher . sendData ( str , updatedata ) ;
414
388
this . data . view_sequence_number ++ ;
415
389
this . data . player_sequence_number ++ ;
416
- workerInstance . worker . postMessage ( {
417
- command : "checkPulse" ,
418
- pausestate : workerInstance . data . player_is_paused ,
419
- errortracker : workerInstance . warning . hasErrorOccurred ,
420
- } ) ;
390
+
391
+ this . handlePulseEvent ( this ) ;
421
392
422
393
if ( str === "viewCompleted" ) {
423
394
delete this . data . view_id ;
424
395
}
425
396
}
426
397
} ;
427
398
399
+ nucleusState . prototype . handlePulseEvent = ( instance : any ) => {
400
+ if ( instance . throbTimeoutId ) {
401
+ clearTimeout ( instance . throbTimeoutId ) ;
402
+ }
403
+
404
+ if ( ! instance . warning . hasErrorOccurred ) {
405
+ instance . throbTimeoutId = setTimeout ( ( ) => {
406
+ if ( ! instance . data . player_is_paused ) {
407
+ instance . dispatch ( "pulse" ) ;
408
+ }
409
+ } , 10000 ) ;
410
+ }
411
+ } ;
412
+
428
413
nucleusState . prototype . refreshViewData = function ( ) {
429
414
const view = this ;
430
415
Object . keys ( this . data ) . forEach ( function ( k ) {
0 commit comments