1
1
import './ima.css'
2
- import type { Constructable , pluginParameter } from 'shared/assets/types/types.js'
2
+ import type Player from 'core/player.js'
3
+ import type { Constructable } from 'shared/assets/types/types.js'
4
+
5
+ type pluginParameter = {
6
+ player : Player
7
+ options : {
8
+ adTagUrl ?: string
9
+ adsRenderingSettings ?: {
10
+ restoreCustomPlaybackStateOnAdBreakComplete : boolean
11
+ enablePreloading : boolean
12
+ }
13
+ updateImaSettings ?: ( settings : any ) => void
14
+ adTimeout ?: number
15
+ debug ?: boolean
16
+ }
17
+ }
3
18
4
19
declare global {
5
20
interface Window {
@@ -66,7 +81,6 @@ type ImaEvent = {
66
81
*/
67
82
export default class ImaPlugin {
68
83
player : any
69
- options : any
70
84
playerIsReady : boolean
71
85
sdkIsReady : boolean
72
86
currentAd ! : any
@@ -83,6 +97,14 @@ export default class ImaPlugin {
83
97
playIsWaiting : boolean
84
98
isLinearAd : boolean
85
99
playerIsEnded : boolean
100
+ adTagUrl : string
101
+ adsRenderingSettings : {
102
+ restoreCustomPlaybackStateOnAdBreakComplete : boolean
103
+ enablePreloading : boolean
104
+ }
105
+ updateImaSettings : ( settings : any ) => void
106
+ adTimeout : number
107
+ debug : boolean
86
108
87
109
providers = [ 'html5' ]
88
110
types = [ 'video' ]
@@ -96,18 +118,14 @@ export default class ImaPlugin {
96
118
constructor ( { player, options = { } } : pluginParameter ) {
97
119
this . player = player
98
120
99
- const defaultOptions = {
100
- adTagUrl : '' ,
101
- adsRenderingSettings : {
102
- restoreCustomPlaybackStateOnAdBreakComplete : true ,
103
- enablePreloading : true
104
- } ,
105
- // eslint-disable-next-line @typescript-eslint/no-empty-function
106
- updateImaSettings : ( ) => { } ,
107
- adTimeout : 5000 ,
108
- debug : false
121
+ this . adTagUrl = options . adTagUrl ?? ''
122
+ this . adsRenderingSettings = options . adsRenderingSettings ?? {
123
+ restoreCustomPlaybackStateOnAdBreakComplete : true ,
124
+ enablePreloading : true
109
125
}
110
- this . options = { ...defaultOptions , ...options }
126
+ this . updateImaSettings = options . updateImaSettings ?? ( ( _settings : any ) => { } )
127
+ this . adTimeout = options . adTimeout ?? 5000
128
+ this . debug = options . debug ?? false
111
129
112
130
this . playerIsReady = false
113
131
this . sdkIsReady = false
@@ -154,7 +172,7 @@ export default class ImaPlugin {
154
172
const script = document . createElement ( 'script' )
155
173
script . defer = true
156
174
script . type = 'text/javascript'
157
- script . src = `//imasdk.googleapis.com/js/sdkloader/ima3${ this . options . debug ? '_debug' : '' } .js`
175
+ script . src = `//imasdk.googleapis.com/js/sdkloader/ima3${ this . debug ? '_debug' : '' } .js`
158
176
script . onload = ( ) => {
159
177
this . sdkIsReady = true
160
178
this . onPlayerAndSdkReady ( )
@@ -236,8 +254,8 @@ export default class ImaPlugin {
236
254
initAdObjects ( ) {
237
255
this . adsLoaded = false
238
256
window . google . ima . settings . setDisableCustomPlaybackForIOS10Plus ( this . player . options . playsinline )
239
- if ( this . options . updateImaSettings instanceof Function ) {
240
- this . options . updateImaSettings ( window . google . ima . settings )
257
+ if ( this . updateImaSettings instanceof Function ) {
258
+ this . updateImaSettings ( window . google . ima . settings )
241
259
}
242
260
243
261
this . adDisplayContainer = new window . google . ima . AdDisplayContainer (
@@ -266,7 +284,7 @@ export default class ImaPlugin {
266
284
*/
267
285
requestAds ( ) {
268
286
const adsRequest = new window . google . ima . AdsRequest ( )
269
- adsRequest . adTagUrl = this . options . adTagUrl
287
+ adsRequest . adTagUrl = this . adTagUrl
270
288
adsRequest . linearAdSlotWidth = this . player . media . clientWidth
271
289
adsRequest . linearAdSlotHeight = this . player . media . clientHeight
272
290
adsRequest . nonLinearAdSlotWidth = this . player . media . clientWidth
@@ -289,7 +307,7 @@ export default class ImaPlugin {
289
307
window . google . ima . UiElements . AD_ATTRIBUTION ,
290
308
window . google . ima . UiElements . COUNTDOWN
291
309
] ,
292
- ...this . options . adsRenderingSettings
310
+ ...this . adsRenderingSettings
293
311
}
294
312
this . adsManager = adsManagerLoadedEvent . getAdsManager ( this . player . media , adsRenderingSettings )
295
313
@@ -505,7 +523,7 @@ export default class ImaPlugin {
505
523
506
524
this . timerAdTimeout = window . setTimeout ( ( ) => {
507
525
this . onAdTimeoutReached ( )
508
- } , this . options . adTimeout )
526
+ } , this . adTimeout )
509
527
}
510
528
511
529
/**
0 commit comments