@gcorevideo/player 2.28.25 → 2.28.27

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