@gcorevideo/player 2.30.1 → 2.30.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/audio-tracks/template.ejs +1 -1
- package/dist/core.js +1 -1
- package/dist/index.css +335 -335
- package/dist/index.embed.js +43 -13
- package/dist/index.js +69 -32
- package/lib/plugins/audio-selector/AudioTracks.d.ts +4 -0
- package/lib/plugins/audio-selector/AudioTracks.d.ts.map +1 -1
- package/lib/plugins/audio-selector/AudioTracks.js +42 -12
- package/lib/plugins/media-control/MediaControl.d.ts +1 -0
- package/lib/plugins/media-control/MediaControl.d.ts.map +1 -1
- package/lib/plugins/media-control/MediaControl.js +9 -1
- package/package.json +1 -1
- package/src/plugins/audio-selector/AudioTracks.ts +51 -16
- package/src/plugins/audio-selector/__tests__/__snapshots__/AudioTracks.test.ts.snap +9 -9
- package/src/plugins/media-control/MediaControl.ts +10 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/assets/vast-ads/style.scss +0 -112
- package/lib/plugins/vast-ads/VastAds.d.ts +0 -74
- package/lib/plugins/vast-ads/VastAds.d.ts.map +0 -1
- package/lib/plugins/vast-ads/VastAds.js +0 -693
- package/lib/plugins/vast-ads/loaderxml.d.ts +0 -32
- package/lib/plugins/vast-ads/loaderxml.d.ts.map +0 -1
- package/lib/plugins/vast-ads/loaderxml.js +0 -229
- package/lib/plugins/vast-ads/roll.d.ts +0 -60
- package/lib/plugins/vast-ads/roll.d.ts.map +0 -1
- package/lib/plugins/vast-ads/roll.js +0 -421
- package/lib/plugins/vast-ads/rollmanager.d.ts +0 -62
- package/lib/plugins/vast-ads/rollmanager.d.ts.map +0 -1
- package/lib/plugins/vast-ads/rollmanager.js +0 -357
- package/lib/plugins/vast-ads/sctemanager.d.ts +0 -18
- package/lib/plugins/vast-ads/sctemanager.d.ts.map +0 -1
- package/lib/plugins/vast-ads/sctemanager.js +0 -117
- package/lib/plugins/vast-ads/types.d.ts +0 -12
- package/lib/plugins/vast-ads/types.d.ts.map +0 -1
- package/lib/plugins/vast-ads/types.js +0 -1
- package/lib/plugins/vast-ads/urlhandler.d.ts +0 -4
- package/lib/plugins/vast-ads/urlhandler.d.ts.map +0 -1
- package/lib/plugins/vast-ads/urlhandler.js +0 -30
- package/lib/plugins/vast-ads/xmlhttprequest.d.ts +0 -6
- package/lib/plugins/vast-ads/xmlhttprequest.d.ts.map +0 -1
- package/lib/plugins/vast-ads/xmlhttprequest.js +0 -40
- package/lib/plugins/vast-ads/xmlmerge.d.ts +0 -12
- package/lib/plugins/vast-ads/xmlmerge.d.ts.map +0 -1
- package/lib/plugins/vast-ads/xmlmerge.js +0 -83
- package/src/plugins/vast-ads/VastAds.ts +0 -919
- package/src/plugins/vast-ads/loaderxml.ts +0 -301
- package/src/plugins/vast-ads/roll.ts +0 -590
- package/src/plugins/vast-ads/rollmanager.ts +0 -447
- package/src/plugins/vast-ads/sctemanager.ts +0 -152
- package/src/plugins/vast-ads/types.ts +0 -20
- package/src/plugins/vast-ads/urlhandler.ts +0 -42
- package/src/plugins/vast-ads/xmlhttprequest.ts +0 -49
- package/src/plugins/vast-ads/xmlmerge.ts +0 -106
|
@@ -1,590 +0,0 @@
|
|
|
1
|
-
// import LogManager from '../../utils/LogManager';
|
|
2
|
-
import { $, Container, Core, Events, Log, Playback } from '@clappr/core'
|
|
3
|
-
import { reportError } from '@gcorevideo/utils'
|
|
4
|
-
import assert from 'assert'
|
|
5
|
-
|
|
6
|
-
import type { ZeptoResult } from '../../types.js'
|
|
7
|
-
import type { TimerId } from '../../utils/types.js'
|
|
8
|
-
|
|
9
|
-
type RollConstructorOptions = {
|
|
10
|
-
core: Core
|
|
11
|
-
$skipAd: ZeptoResult
|
|
12
|
-
$muteIcon: ZeptoResult
|
|
13
|
-
$areaClick: ZeptoResult
|
|
14
|
-
mute: boolean
|
|
15
|
-
volume: number
|
|
16
|
-
prevVolume: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default class Roll extends Events {
|
|
20
|
-
private mute: boolean
|
|
21
|
-
private core: Core
|
|
22
|
-
private container: Container
|
|
23
|
-
private $skipAd: ZeptoResult
|
|
24
|
-
private $muteIcon: ZeptoResult
|
|
25
|
-
private $areaClick: ZeptoResult
|
|
26
|
-
private _playback: Playback
|
|
27
|
-
private _volume: number
|
|
28
|
-
private _prevValueVolume: number
|
|
29
|
-
|
|
30
|
-
private _useDummyMp4Video = false
|
|
31
|
-
|
|
32
|
-
private firstRemaininTime = 0
|
|
33
|
-
|
|
34
|
-
private intervalTimer: TimerId | null = null
|
|
35
|
-
|
|
36
|
-
private _isAdStartedTriggered: boolean
|
|
37
|
-
|
|
38
|
-
private extension: any
|
|
39
|
-
|
|
40
|
-
private _adsManager: any
|
|
41
|
-
|
|
42
|
-
private url: string = ''
|
|
43
|
-
|
|
44
|
-
// _events: Record<string, Function>;
|
|
45
|
-
|
|
46
|
-
constructor({
|
|
47
|
-
core,
|
|
48
|
-
$skipAd,
|
|
49
|
-
$muteIcon,
|
|
50
|
-
$areaClick,
|
|
51
|
-
mute,
|
|
52
|
-
volume,
|
|
53
|
-
prevVolume,
|
|
54
|
-
}: RollConstructorOptions) {
|
|
55
|
-
super()
|
|
56
|
-
this.mute = mute
|
|
57
|
-
this.core = core
|
|
58
|
-
this.container = this.core.activeContainer
|
|
59
|
-
this.$skipAd = $skipAd
|
|
60
|
-
this.$muteIcon = $muteIcon
|
|
61
|
-
this.$areaClick = $areaClick
|
|
62
|
-
this._playback = this.core.activePlayback
|
|
63
|
-
this._volume = volume
|
|
64
|
-
this._prevValueVolume = prevVolume
|
|
65
|
-
this._isAdStartedTriggered = false
|
|
66
|
-
// this._events = {};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
static _adContainer: any
|
|
70
|
-
|
|
71
|
-
private static _adDisplayContainer: any
|
|
72
|
-
|
|
73
|
-
private static _imaContainer: any
|
|
74
|
-
|
|
75
|
-
static _contentElement: HTMLMediaElement | null = null
|
|
76
|
-
|
|
77
|
-
static createAdDisplayContainer() {
|
|
78
|
-
Roll.createImaContainer()
|
|
79
|
-
assert('google' in window, 'Google IMA SDK not found')
|
|
80
|
-
Roll._adDisplayContainer = new (
|
|
81
|
-
window.google as any
|
|
82
|
-
).ima.AdDisplayContainer(Roll._imaContainer, Roll._contentElement)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
static createImaContainer() {
|
|
86
|
-
Roll.destroyImaContainer()
|
|
87
|
-
// IMA does not clean ad container when finished
|
|
88
|
-
// For the sake of simplicity, wrap into a <div> element
|
|
89
|
-
if (Roll._adContainer) {
|
|
90
|
-
Roll._imaContainer = document.createElement('div')
|
|
91
|
-
Roll._adContainer.appendChild(Roll._imaContainer)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
static destroyImaContainer() {
|
|
96
|
-
if (Roll._imaContainer && Roll._adContainer) {
|
|
97
|
-
Roll._adContainer.removeChild(Roll._imaContainer)
|
|
98
|
-
delete Roll._imaContainer
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private _onAdError(adErrorEvent: any) {
|
|
103
|
-
try {
|
|
104
|
-
const googleError = adErrorEvent.getError()
|
|
105
|
-
const error = new Error(
|
|
106
|
-
googleError.getMessage() + ' ' + googleError.getErrorCode(),
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
error.name = googleError.getType()
|
|
110
|
-
// LogManager.exception(error);
|
|
111
|
-
reportError(error)
|
|
112
|
-
} catch (error) {
|
|
113
|
-
// LogManager.exception(error);
|
|
114
|
-
reportError(error)
|
|
115
|
-
}
|
|
116
|
-
Log.debug('Advertisement', 'advertisement error')
|
|
117
|
-
this._cleverContinueAd(true)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async _playAds() {
|
|
121
|
-
await Roll._adDisplayContainer.initialize()
|
|
122
|
-
try {
|
|
123
|
-
assert('google' in window, 'Google IMA SDK not found')
|
|
124
|
-
assert(Roll._contentElement, 'content element not found')
|
|
125
|
-
this._adsManager.init(
|
|
126
|
-
Roll._contentElement.offsetWidth,
|
|
127
|
-
Roll._contentElement.offsetHeight,
|
|
128
|
-
(window.google as any).ima.ViewMode.NORMAL,
|
|
129
|
-
)
|
|
130
|
-
this._adsManager.start()
|
|
131
|
-
} catch (error) {
|
|
132
|
-
// LogManager.exception(error);
|
|
133
|
-
reportError(error)
|
|
134
|
-
this._imaEvent('error', error)
|
|
135
|
-
this._playVideoContent()
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
private _setVolume(volume: number) {
|
|
140
|
-
try {
|
|
141
|
-
if (this._adsManager) {
|
|
142
|
-
this._adsManager.setVolume(volume / 100)
|
|
143
|
-
}
|
|
144
|
-
if (typeof this.core.mediaControl.setVolume === 'function') {
|
|
145
|
-
this.core.options.mute = !volume
|
|
146
|
-
|
|
147
|
-
this.trigger('volume', {
|
|
148
|
-
volume,
|
|
149
|
-
mute: this.core.options.mute,
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
if ((this.container as any).advertisement.type !== 'scteroll') {
|
|
153
|
-
this.core.mediaControl.setVolume(volume, true)
|
|
154
|
-
} else {
|
|
155
|
-
if (volume) {
|
|
156
|
-
;(this.container as any).advertisement.isMuted = true
|
|
157
|
-
} else {
|
|
158
|
-
this.core.mediaControl.setVolume(volume, true)
|
|
159
|
-
;(this.container as any).advertisement.isMuted = false
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
this._volume = volume
|
|
164
|
-
} catch (error) {
|
|
165
|
-
// LogManager.exception(error);
|
|
166
|
-
reportError(error)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
_playVideoContent() {
|
|
171
|
-
this.destroy()
|
|
172
|
-
this.trigger('advertisement_finish')
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
_hideControls() {
|
|
176
|
-
if (this.extension && this.extension.controls === '0') {
|
|
177
|
-
this.$skipAd.css({ opacity: 0, visibility: 'hidden' })
|
|
178
|
-
this.$muteIcon.css({ opacity: 0, visibility: 'hidden' })
|
|
179
|
-
} else {
|
|
180
|
-
this.$skipAd.css({ opacity: 1, visibility: 'visible' })
|
|
181
|
-
this.$muteIcon.css({ opacity: 1, visibility: 'visible' })
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
_requestAd({
|
|
186
|
-
xml,
|
|
187
|
-
url,
|
|
188
|
-
extension,
|
|
189
|
-
}: {
|
|
190
|
-
xml: any
|
|
191
|
-
url: string
|
|
192
|
-
extension: any
|
|
193
|
-
}) {
|
|
194
|
-
this.extension = extension
|
|
195
|
-
assert('google' in window, 'Google IMA SDK not found')
|
|
196
|
-
const adsLoader = new (window.google as any).ima.AdsLoader(
|
|
197
|
-
Roll._adDisplayContainer,
|
|
198
|
-
)
|
|
199
|
-
|
|
200
|
-
adsLoader.addEventListener(
|
|
201
|
-
(window.google as any).ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
|
|
202
|
-
(e: any) => {
|
|
203
|
-
this._onAdsManagerLoaded(e)
|
|
204
|
-
},
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
adsLoader.addEventListener(
|
|
208
|
-
(window.google as any).ima.AdErrorEvent.Type.AD_ERROR,
|
|
209
|
-
(e: any) => {
|
|
210
|
-
this._onAdError(e)
|
|
211
|
-
},
|
|
212
|
-
)
|
|
213
|
-
const adsRequest = new (window.google as any).ima.AdsRequest()
|
|
214
|
-
|
|
215
|
-
if (xml) {
|
|
216
|
-
adsRequest.adTagUrl = ''
|
|
217
|
-
adsRequest.adsResponse = xml
|
|
218
|
-
} else {
|
|
219
|
-
if (url) {
|
|
220
|
-
adsRequest.adTagUrl = url
|
|
221
|
-
} else {
|
|
222
|
-
throw 'no ad url'
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
this.url = url
|
|
226
|
-
|
|
227
|
-
assert(Roll._contentElement, 'content element not found')
|
|
228
|
-
adsRequest.linearAdSlotWidth = Roll._contentElement.offsetWidth
|
|
229
|
-
adsRequest.linearAdSlotHeight = Roll._contentElement.offsetHeight
|
|
230
|
-
adsRequest.nonLinearAdSlotWidth = Roll._contentElement.offsetWidth
|
|
231
|
-
adsRequest.nonLinearAdSlotHeight = Roll._contentElement.offsetHeight
|
|
232
|
-
adsLoader.requestAds(adsRequest)
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
playerResize() {
|
|
236
|
-
assert(Roll._contentElement, 'content element not found')
|
|
237
|
-
assert('google' in window, 'Google IMA SDK not found')
|
|
238
|
-
this._adsManager &&
|
|
239
|
-
this._adsManager.resize(
|
|
240
|
-
Roll._contentElement.offsetWidth,
|
|
241
|
-
Roll._contentElement.offsetHeight,
|
|
242
|
-
(window.google as any).ima.ViewMode.NORMAL,
|
|
243
|
-
)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
_onAdsManagerLoaded(adsManagerLoadedEvent: any) {
|
|
247
|
-
assert('google' in window, 'Google IMA SDK not found')
|
|
248
|
-
const adsRenderingSettings = new (
|
|
249
|
-
window.google as any
|
|
250
|
-
).ima.AdsRenderingSettings()
|
|
251
|
-
|
|
252
|
-
adsRenderingSettings.loadVideoTimeout = process.env.MINIMIZE ? 4000 : 8000
|
|
253
|
-
adsRenderingSettings.bitrate = 100000
|
|
254
|
-
// Plugin will handle playback state when ad has completed
|
|
255
|
-
|
|
256
|
-
this._adsManager = adsManagerLoadedEvent.getAdsManager(
|
|
257
|
-
Roll._contentElement,
|
|
258
|
-
adsRenderingSettings,
|
|
259
|
-
)
|
|
260
|
-
this._adsManager.addEventListener(
|
|
261
|
-
(window.google as any).ima.AdEvent.Type.LOADED,
|
|
262
|
-
() => {
|
|
263
|
-
if (this.mute) {
|
|
264
|
-
this._setVolume(0)
|
|
265
|
-
} else {
|
|
266
|
-
this._setVolume(this._volume)
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
this.changeIconVolume()
|
|
270
|
-
},
|
|
271
|
-
)
|
|
272
|
-
this._adsManager.addEventListener(
|
|
273
|
-
(window.google as any).ima.AdErrorEvent.Type.AD_ERROR,
|
|
274
|
-
(e: any) => {
|
|
275
|
-
const adType = (this.container as any).advertisement.type
|
|
276
|
-
|
|
277
|
-
if (
|
|
278
|
-
!(
|
|
279
|
-
(adType === 'middleroll' || adType === 'repeatableroll') &&
|
|
280
|
-
!this._playback.isPlaying()
|
|
281
|
-
)
|
|
282
|
-
) {
|
|
283
|
-
this._onAdError(e)
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
)
|
|
287
|
-
this._adsManager.addEventListener(
|
|
288
|
-
(window.google as any).ima.AdEvent.Type.CONTENT_RESUME_REQUESTED,
|
|
289
|
-
() => {
|
|
290
|
-
this._imaEvent('content_resume_requested')
|
|
291
|
-
},
|
|
292
|
-
)
|
|
293
|
-
this._adsManager.addEventListener(
|
|
294
|
-
(window.google as any).ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED,
|
|
295
|
-
() => {
|
|
296
|
-
this._imaEvent('content_pause_requested')
|
|
297
|
-
this._triggerStartAd(this.url)
|
|
298
|
-
},
|
|
299
|
-
)
|
|
300
|
-
this._adsManager.addEventListener(
|
|
301
|
-
(window.google as any).ima.AdEvent.Type.CLICK,
|
|
302
|
-
() => {
|
|
303
|
-
this._imaEvent('click')
|
|
304
|
-
},
|
|
305
|
-
)
|
|
306
|
-
this._adsManager.addEventListener(
|
|
307
|
-
(window.google as any).ima.AdEvent.Type.IMPRESSION,
|
|
308
|
-
() => {
|
|
309
|
-
this._imaEvent('impression')
|
|
310
|
-
},
|
|
311
|
-
)
|
|
312
|
-
this._adsManager.addEventListener(
|
|
313
|
-
(window.google as any).ima.AdEvent.Type.STARTED,
|
|
314
|
-
(adEvent: any) => {
|
|
315
|
-
this._triggerStartAd(this.url)
|
|
316
|
-
this.trigger('advertisement_played')
|
|
317
|
-
const ad = adEvent.getAd()
|
|
318
|
-
|
|
319
|
-
try {
|
|
320
|
-
assert(Roll._contentElement, 'content element not found')
|
|
321
|
-
assert('google' in window, 'Google IMA SDK not found')
|
|
322
|
-
this._adsManager &&
|
|
323
|
-
this._adsManager.resize(
|
|
324
|
-
Roll._contentElement.offsetWidth,
|
|
325
|
-
Roll._contentElement.offsetHeight,
|
|
326
|
-
(window.google as any).ima.ViewMode.NORMAL,
|
|
327
|
-
)
|
|
328
|
-
} catch (error) {
|
|
329
|
-
// LogManager.exception(error);
|
|
330
|
-
reportError(error)
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (this.mute) {
|
|
334
|
-
this._setVolume(0)
|
|
335
|
-
} else {
|
|
336
|
-
this._setVolume(this._volume)
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (ad.isLinear()) {
|
|
340
|
-
// For a linear ad, a timer can be started to poll for
|
|
341
|
-
// the remaining time.
|
|
342
|
-
|
|
343
|
-
this.intervalTimer = setInterval(() => {
|
|
344
|
-
this._remainingTime(ad)
|
|
345
|
-
}, 300) // every 300ms
|
|
346
|
-
}
|
|
347
|
-
},
|
|
348
|
-
)
|
|
349
|
-
this._adsManager.addEventListener(
|
|
350
|
-
(window.google as any).ima.AdEvent.Type.FIRST_QUARTILE,
|
|
351
|
-
() => {
|
|
352
|
-
this._imaEvent('first_quartile')
|
|
353
|
-
},
|
|
354
|
-
)
|
|
355
|
-
this._adsManager.addEventListener(
|
|
356
|
-
(window.google as any).ima.AdEvent.Type.MIDPOINT,
|
|
357
|
-
() => {
|
|
358
|
-
this._imaEvent('midpoint')
|
|
359
|
-
},
|
|
360
|
-
)
|
|
361
|
-
this._adsManager.addEventListener(
|
|
362
|
-
(window.google as any).ima.AdEvent.Type.THIRD_QUARTILE,
|
|
363
|
-
() => {
|
|
364
|
-
this._imaEvent('third_quartile')
|
|
365
|
-
},
|
|
366
|
-
)
|
|
367
|
-
this._adsManager.addEventListener(
|
|
368
|
-
(window.google as any).ima.AdEvent.Type.COMPLETE,
|
|
369
|
-
() => {
|
|
370
|
-
this._imaEvent('complete')
|
|
371
|
-
this._useDummyMp4Video = false
|
|
372
|
-
},
|
|
373
|
-
)
|
|
374
|
-
this._adsManager.addEventListener(
|
|
375
|
-
(window.google as any).ima.AdEvent.Type.ALL_ADS_COMPLETED,
|
|
376
|
-
() => {
|
|
377
|
-
this._imaEvent('all_ads_completed')
|
|
378
|
-
this._cleverContinueAd()
|
|
379
|
-
this._useDummyMp4Video = false
|
|
380
|
-
},
|
|
381
|
-
)
|
|
382
|
-
|
|
383
|
-
this._adsManager.addEventListener(
|
|
384
|
-
(window.google as any).ima.AdEvent.Type.PAUSED,
|
|
385
|
-
() => {
|
|
386
|
-
this._imaEvent('paused')
|
|
387
|
-
},
|
|
388
|
-
)
|
|
389
|
-
|
|
390
|
-
this._adsManager.addEventListener(
|
|
391
|
-
(window.google as any).ima.AdEvent.Type.RESUMED,
|
|
392
|
-
() => {
|
|
393
|
-
this._imaEvent('resumed')
|
|
394
|
-
},
|
|
395
|
-
)
|
|
396
|
-
|
|
397
|
-
this._adsManager.addEventListener(
|
|
398
|
-
(window.google as any).ima.AdEvent.Type.SKIPPED,
|
|
399
|
-
() => {
|
|
400
|
-
this._imaEvent('skipped')
|
|
401
|
-
if (this.extension && this.extension.skipAd) {
|
|
402
|
-
this._trackUrl(this.extension.skipAd)
|
|
403
|
-
}
|
|
404
|
-
},
|
|
405
|
-
)
|
|
406
|
-
|
|
407
|
-
this._adsManager.addEventListener(
|
|
408
|
-
(window.google as any).ima.AdEvent.Type.VOLUME_CHANGED,
|
|
409
|
-
() => {
|
|
410
|
-
this._imaEvent('volume_change')
|
|
411
|
-
this.changeIconVolume()
|
|
412
|
-
},
|
|
413
|
-
)
|
|
414
|
-
|
|
415
|
-
this._adsManager.addEventListener(
|
|
416
|
-
(window.google as any).ima.AdEvent.Type.VOLUME_MUTED,
|
|
417
|
-
() => {
|
|
418
|
-
this._imaEvent('volume_muted')
|
|
419
|
-
this.changeIconVolume()
|
|
420
|
-
},
|
|
421
|
-
)
|
|
422
|
-
|
|
423
|
-
this._adsManager.addEventListener(
|
|
424
|
-
(window.google as any).ima.AdEvent.Type.USER_CLOSE,
|
|
425
|
-
() => {
|
|
426
|
-
this._imaEvent('user_close')
|
|
427
|
-
},
|
|
428
|
-
)
|
|
429
|
-
|
|
430
|
-
if (this.mute) {
|
|
431
|
-
this._setVolume(0)
|
|
432
|
-
} else {
|
|
433
|
-
this._setVolume(this._volume)
|
|
434
|
-
}
|
|
435
|
-
this._setupOverlay()
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
_triggerStartAd(url: string) {
|
|
439
|
-
if (!this._isAdStartedTriggered) {
|
|
440
|
-
this._isAdStartedTriggered = true
|
|
441
|
-
this.trigger('advertisement_started', {
|
|
442
|
-
url,
|
|
443
|
-
})
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
_remainingTime(ad: any) {
|
|
448
|
-
if (!ad || !this._adsManager) {
|
|
449
|
-
return
|
|
450
|
-
}
|
|
451
|
-
const remainingTime = Math.abs(this._adsManager.getRemainingTime())
|
|
452
|
-
const duration = ad.getDuration() || ad.getMinSuggestedDuration()
|
|
453
|
-
|
|
454
|
-
if (!this.firstRemaininTime) {
|
|
455
|
-
this.firstRemaininTime = this._adsManager.getRemainingTime()
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
const shouldShowSkip =
|
|
459
|
-
remainingTime < this.firstRemaininTime &&
|
|
460
|
-
this.extension.timeOffset > -1 &&
|
|
461
|
-
this.firstRemaininTime > this.extension.timeOffset &&
|
|
462
|
-
!(duration > 0 && Math.abs(duration) < this.extension.timeOffset)
|
|
463
|
-
|
|
464
|
-
if (!shouldShowSkip) {
|
|
465
|
-
return
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
this.$skipAd.show()
|
|
469
|
-
const offset = Math.round(
|
|
470
|
-
this.extension.timeOffset -
|
|
471
|
-
Math.abs(this.firstRemaininTime - remainingTime),
|
|
472
|
-
)
|
|
473
|
-
|
|
474
|
-
if (offset > 0) {
|
|
475
|
-
this.$skipAd.addClass('skip-ad-time')
|
|
476
|
-
this.$skipAd.text(this.core.i18n.t('you_can_skip_ad') + ' ' + offset)
|
|
477
|
-
} else {
|
|
478
|
-
this.$skipAd.removeClass('skip-ad-time')
|
|
479
|
-
this.$skipAd.text(this.core.i18n.t('skip_ad'))
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
private _cleverContinueAd(error?: any) {
|
|
484
|
-
try {
|
|
485
|
-
this.destroy()
|
|
486
|
-
} catch (error) {
|
|
487
|
-
// LogManager.exception(error);
|
|
488
|
-
reportError(error)
|
|
489
|
-
}
|
|
490
|
-
this.trigger('continue_ad', { error })
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
private _imaEvent(eventName: string, e?: any) {
|
|
494
|
-
$.isFunction((this._events as any)[eventName]) &&
|
|
495
|
-
(this._events as any)[eventName](e)
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
changeIconVolume() {
|
|
499
|
-
if (!this._adsManager) {
|
|
500
|
-
return
|
|
501
|
-
}
|
|
502
|
-
this.$muteIcon.show()
|
|
503
|
-
if (this._adsManager.getVolume() === 0) {
|
|
504
|
-
if (!this._volume && this._adsManager.getVolume()) {
|
|
505
|
-
this._volume = this._adsManager.getVolume() * 100
|
|
506
|
-
}
|
|
507
|
-
this.$muteIcon.find('.mute-off-ad-icon').show()
|
|
508
|
-
this.$muteIcon.find('.mute-on-ad-icon').hide()
|
|
509
|
-
} else {
|
|
510
|
-
this._volume = this._adsManager.getVolume() * 100
|
|
511
|
-
this.$muteIcon.find('.mute-on-ad-icon').show()
|
|
512
|
-
this.$muteIcon.find('.mute-off-ad-icon').hide()
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
_setupOverlay() {
|
|
517
|
-
this.$muteIcon.off('click')
|
|
518
|
-
this.$skipAd.off('click')
|
|
519
|
-
this.$areaClick.off('click')
|
|
520
|
-
this.$muteIcon.off()
|
|
521
|
-
this.$skipAd.off()
|
|
522
|
-
this.$areaClick.off()
|
|
523
|
-
this.$muteIcon.on('click', () => {
|
|
524
|
-
if (this._adsManager) {
|
|
525
|
-
if (this._adsManager.getVolume() === 0) {
|
|
526
|
-
this._setVolume(
|
|
527
|
-
this._prevValueVolume ? this._prevValueVolume : this._volume,
|
|
528
|
-
)
|
|
529
|
-
} else {
|
|
530
|
-
this._setVolume(0)
|
|
531
|
-
}
|
|
532
|
-
this.changeIconVolume()
|
|
533
|
-
}
|
|
534
|
-
})
|
|
535
|
-
this.$skipAd.on('click', () => {
|
|
536
|
-
if (this.extension.skipEvents) {
|
|
537
|
-
this._trackUrls(this.extension.skipEvents)
|
|
538
|
-
}
|
|
539
|
-
if (this.extension.progressEvents) {
|
|
540
|
-
this._trackUrls(this.extension.progressEvents)
|
|
541
|
-
}
|
|
542
|
-
if (this.extension && this.extension.skipAd) {
|
|
543
|
-
this._trackUrl(this.extension.skipAd)
|
|
544
|
-
}
|
|
545
|
-
this._adsManager.stop()
|
|
546
|
-
console.warn('skip ad')
|
|
547
|
-
})
|
|
548
|
-
|
|
549
|
-
if (this.extension.clickThrough) {
|
|
550
|
-
this.$areaClick.show()
|
|
551
|
-
this.$areaClick.on('click', () => {
|
|
552
|
-
window.open(this.extension.clickThrough, '_blank')
|
|
553
|
-
console.warn(this.extension.clickTrackings)
|
|
554
|
-
if (this.extension.clickTrackings.length) {
|
|
555
|
-
this._trackUrls(this.extension.clickTrackings)
|
|
556
|
-
}
|
|
557
|
-
})
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
this._hideControls()
|
|
561
|
-
|
|
562
|
-
this._playAds()
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
_trackUrls(urls: string[]) {
|
|
566
|
-
for (let i = 0; i < urls.length; i++) {
|
|
567
|
-
this._trackUrl(urls[i])
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
_trackUrl(url: string) {
|
|
572
|
-
if (url) {
|
|
573
|
-
const i = new Image()
|
|
574
|
-
|
|
575
|
-
i.src = url
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
destroy() {
|
|
580
|
-
if (this.intervalTimer) {
|
|
581
|
-
clearInterval(this.intervalTimer)
|
|
582
|
-
this.intervalTimer = null
|
|
583
|
-
}
|
|
584
|
-
if (Roll._adDisplayContainer) {
|
|
585
|
-
if (this._adsManager) {
|
|
586
|
-
this._adsManager.destroy()
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
}
|