@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,693 +0,0 @@
|
|
|
1
|
-
import { $, Browser, Events, HTML5Video, Log, UICorePlugin, Utils, } from '@clappr/core';
|
|
2
|
-
import { reportError } from '@gcorevideo/utils';
|
|
3
|
-
import assert from 'assert';
|
|
4
|
-
import { CLAPPR_VERSION } from '../../build.js';
|
|
5
|
-
import RollManager from './rollmanager.js';
|
|
6
|
-
import SCTEManager from './sctemanager.js';
|
|
7
|
-
import { VolumeFadeEvents } from '../volume-fade/VolumeFade.js';
|
|
8
|
-
import '../../../assets/vast-ads/style.scss';
|
|
9
|
-
import volumeIcon from '../../../assets/icons/new/volume-max.svg';
|
|
10
|
-
import volumeMuteIcon from '../../../assets/icons/new/volume-off.svg';
|
|
11
|
-
const VERSION = '0.0.1';
|
|
12
|
-
export class VastAds extends UICorePlugin {
|
|
13
|
-
_clickToPausePlugin = null;
|
|
14
|
-
_cloneContainerEvents = null;
|
|
15
|
-
_clonePlaybackEvents = null;
|
|
16
|
-
countMiddleRoll = 0;
|
|
17
|
-
countRepeatableRoll = 0;
|
|
18
|
-
_container = null;
|
|
19
|
-
container = null;
|
|
20
|
-
_contentElement = null;
|
|
21
|
-
_currentPosition = 0;
|
|
22
|
-
currentState = '';
|
|
23
|
-
_imaIsloaded = false;
|
|
24
|
-
_imaLoadResult = false;
|
|
25
|
-
intervalTimer = null;
|
|
26
|
-
_playback = null;
|
|
27
|
-
_pluginIsReady = false;
|
|
28
|
-
_posterBigPlayStyle = null;
|
|
29
|
-
_posterPlugin = null;
|
|
30
|
-
_prevVolumeValue = 0;
|
|
31
|
-
vast = null;
|
|
32
|
-
_volume = 80;
|
|
33
|
-
startTimeRepeatableRoll = 0;
|
|
34
|
-
startTimeRepeatableRollGap = 0;
|
|
35
|
-
_scteManager = new SCTEManager();
|
|
36
|
-
$skipAd = null;
|
|
37
|
-
$muteIcon = null;
|
|
38
|
-
$areaClick = null;
|
|
39
|
-
_$adContainer = null;
|
|
40
|
-
_adContainer = null;
|
|
41
|
-
get name() {
|
|
42
|
-
return 'clappr-vast-ad-plugin';
|
|
43
|
-
}
|
|
44
|
-
get supportedVersion() {
|
|
45
|
-
return { min: CLAPPR_VERSION };
|
|
46
|
-
}
|
|
47
|
-
static get version() {
|
|
48
|
-
return VERSION;
|
|
49
|
-
}
|
|
50
|
-
get mediaControl() {
|
|
51
|
-
return this.core.mediaControl;
|
|
52
|
-
}
|
|
53
|
-
get attributes() {
|
|
54
|
-
return {
|
|
55
|
-
class: this.name,
|
|
56
|
-
'data-vast-ads': '',
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
constructor(core) {
|
|
60
|
-
super(core);
|
|
61
|
-
const cfg = this.options.vastAds;
|
|
62
|
-
try {
|
|
63
|
-
const no_lib = 'google' in window && window.google.ima;
|
|
64
|
-
if (!no_lib || !cfg) {
|
|
65
|
-
this.disable();
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
// LogManager.exception(error);
|
|
71
|
-
reportError(error);
|
|
72
|
-
this.disable();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// TODO: Add an option which is an array of plugin name to disable
|
|
76
|
-
try {
|
|
77
|
-
if (!cfg.preroll) {
|
|
78
|
-
this._pluginError('tag option is required');
|
|
79
|
-
this.disable();
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
this._pluginError('tag option is required');
|
|
85
|
-
this.disable();
|
|
86
|
-
// LogManager.message('Advertisement: tag option is required', SentryLogLevel.ERROR);
|
|
87
|
-
reportError(error);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (cfg.middleroll?.data?.length > 0) {
|
|
91
|
-
cfg.middleroll.data = cfg.middleroll.data
|
|
92
|
-
.filter(({ startTimePercent }) => startTimePercent >= 10 && startTimePercent <= 90)
|
|
93
|
-
.sort((a, b) => a.startTimePercent - b.startTimePercent);
|
|
94
|
-
}
|
|
95
|
-
if (cfg.repeatableroll?.data?.length > 0) {
|
|
96
|
-
cfg.repeatableroll.data = cfg.repeatableroll.data
|
|
97
|
-
.filter(({ startTime }) => startTime >= 2)
|
|
98
|
-
.sort((a, b) => a.startTime - b.startTime);
|
|
99
|
-
}
|
|
100
|
-
let lang = (this.core.options.language || Utils.getBrowserLanguage())
|
|
101
|
-
.toLowerCase()
|
|
102
|
-
.replace(/_/g, '-');
|
|
103
|
-
if (lang.indexOf('_') < 0) {
|
|
104
|
-
lang += '_' + lang;
|
|
105
|
-
}
|
|
106
|
-
if ('google' in window && window.google.ima) {
|
|
107
|
-
;
|
|
108
|
-
window.google.ima.settings.setLocale(lang);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
bindEvents() {
|
|
112
|
-
const no_lib = 'google' in window && window.google.ima;
|
|
113
|
-
if (!no_lib) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (this._scteManager) {
|
|
117
|
-
// @ts-ignore
|
|
118
|
-
this._scteManager.on('startSCTERoll', () => {
|
|
119
|
-
this.initializeRollManager({
|
|
120
|
-
type: 'scteroll',
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
// @ts-ignore
|
|
124
|
-
this._scteManager.on('stopSCTERoll', () => {
|
|
125
|
-
this._playVideoContent('scteroll');
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
this.listenToOnce(this.core, Events.CORE_READY, this._onCoreReady);
|
|
129
|
-
this.listenTo(this.core, Events.CORE_RESIZE, this.playerResize);
|
|
130
|
-
if (this.container) {
|
|
131
|
-
this.listenTo(this.container, Events.CONTAINER_VOLUME, this._onContainerVolume);
|
|
132
|
-
}
|
|
133
|
-
this.listenTo(this.core, VolumeFadeEvents.FADE, this._onVolumeChanged);
|
|
134
|
-
if (this.playback) {
|
|
135
|
-
this.listenTo(this.container, Events.CONTAINER_SEEK, (e) => {
|
|
136
|
-
if (this.container.advertisement.type === 'middleroll') {
|
|
137
|
-
this.countMiddleRoll = this.findCloserAdvertisement(this.options.vastAds.middleroll, 'startTimePercent', this.countMiddleRoll, e);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
this.countRepeatableRoll = this.findCloserAdvertisement(this.options.vastAds.repeatableroll, 'startTime', this.countRepeatableRoll, e);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
this.listenTo(this.playback, Events.PLAYBACK_LEVEL_SWITCH_START, () => {
|
|
144
|
-
if (this.currentState === 'pause') {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
this.currentState = 'switch';
|
|
148
|
-
});
|
|
149
|
-
this.listenTo(this.playback, Events.PLAYBACK_TIMEUPDATE, this.onPlaybackTimeUpdate);
|
|
150
|
-
this.listenTo(this.playback, Events.PLAYBACK_ENDED, this.onPlaybackEnded);
|
|
151
|
-
this._pauserollListeners();
|
|
152
|
-
this.listenToOnce(this.playback, Events.PLAYBACK_PLAY, () => {
|
|
153
|
-
if (this._posterBigPlayStyle) {
|
|
154
|
-
this._posterBigPlayStyle.remove();
|
|
155
|
-
this._posterBigPlayStyle = null;
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
this.listenTo(this.playback, Events.PLAYBACK_PLAY, this.onPlaybackPlay.bind(this));
|
|
159
|
-
this.listenToOnce(this.playback, 'playback:preroll:request', this.onPlaybackPrerollRequest);
|
|
160
|
-
}
|
|
161
|
-
if (this.mediaControl) {
|
|
162
|
-
this.listenToOnce(this.mediaControl, Events.MEDIACONTROL_CONTAINERCHANGED, this.containerChanged);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
onPlaybackEnded() {
|
|
166
|
-
if (this.playback?.getPlaybackType() !== 'live') {
|
|
167
|
-
this.countMiddleRoll = 0;
|
|
168
|
-
this.countRepeatableRoll = 0;
|
|
169
|
-
this.initializeRollManager({
|
|
170
|
-
type: 'postroll',
|
|
171
|
-
});
|
|
172
|
-
this._pauserollListeners();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
onPlaybackPlay() {
|
|
176
|
-
setTimeout(() => {
|
|
177
|
-
const posterPlugin = this.container?.getPlugin('poster');
|
|
178
|
-
posterPlugin?.enable();
|
|
179
|
-
posterPlugin?.$el.hide();
|
|
180
|
-
this._posterPlugin?.$playWrapper.show();
|
|
181
|
-
// TODO trigger event or call a method instead
|
|
182
|
-
}, 0);
|
|
183
|
-
}
|
|
184
|
-
onPlaybackPrerollRequest() {
|
|
185
|
-
try {
|
|
186
|
-
this.initializeRollManager({
|
|
187
|
-
type: 'preroll',
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
catch (error) {
|
|
191
|
-
// LogManager.exception(error);
|
|
192
|
-
reportError(error);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
onPlaybackTimeUpdate(e) {
|
|
196
|
-
if (this.container?.advertisement.type !== 'idle') {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
const middleroll = this._options.VastAds.middleroll;
|
|
200
|
-
assert(this.playback, 'playback is not defined');
|
|
201
|
-
if (middleroll && this.playback.getPlaybackType() === 'vod') {
|
|
202
|
-
const currentPercent = Math.floor((e.current / e.total) * 100);
|
|
203
|
-
const middlerollData = middleroll.data[this.countMiddleRoll];
|
|
204
|
-
if (middlerollData && middlerollData.startTimePercent <= currentPercent) {
|
|
205
|
-
// TODO fixit
|
|
206
|
-
// @ts-ignore
|
|
207
|
-
this._currentPosition = this.playback.getCurrentTime();
|
|
208
|
-
this.initializeRollManager({
|
|
209
|
-
type: 'middleroll',
|
|
210
|
-
count: this.countMiddleRoll,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (this._options.VastAds.repeatableroll &&
|
|
215
|
-
this.playback.getPlaybackType() === 'live') {
|
|
216
|
-
try {
|
|
217
|
-
if (!this.playback.el.played ||
|
|
218
|
-
!this.playback.el.played.length) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
let startTime = this.playback.el.played.start(0) ||
|
|
222
|
-
this.startTimeRepeatableRoll;
|
|
223
|
-
if (!this.startTimeRepeatableRoll) {
|
|
224
|
-
if (!startTime) {
|
|
225
|
-
this.startTimeRepeatableRoll = startTime = this.playback.el.currentTime;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
const currentTime = this.playback.el.currentTime -
|
|
229
|
-
startTime +
|
|
230
|
-
this.startTimeRepeatableRollGap;
|
|
231
|
-
const repeatablerollData = this._options.VastAds.repeatableroll.data[this.countRepeatableRoll];
|
|
232
|
-
if (repeatablerollData && repeatablerollData.startTime <= currentTime) {
|
|
233
|
-
this.startTimeRepeatableRollGap = currentTime;
|
|
234
|
-
this.initializeRollManager({
|
|
235
|
-
type: 'repeatableroll',
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
catch (error) {
|
|
240
|
-
// LogManager.exception(error);
|
|
241
|
-
reportError(error);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
rebindNextAd() {
|
|
246
|
-
if (Object.keys(this._scteManager).length > 0) {
|
|
247
|
-
this.containerChanged();
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
initializeRollManager({ type, count, }) {
|
|
251
|
-
this.destroyRoll();
|
|
252
|
-
assert(this._adContainer, '_adContainer is not defined');
|
|
253
|
-
const vast = new RollManager(this.core, this.options, this.$skipAd, this.$muteIcon, this.$areaClick, this._adContainer, type, count || 0, this._volume, this._prevVolumeValue);
|
|
254
|
-
// @ts-ignore
|
|
255
|
-
vast.on('advertisement_finish', (data) => {
|
|
256
|
-
this._playVideoContent(data.type, !!Browser.isiOS);
|
|
257
|
-
});
|
|
258
|
-
// @ts-ignore
|
|
259
|
-
vast.on('advertisement_dont_play', (data) => {
|
|
260
|
-
this._playVideoContent(data.type, true);
|
|
261
|
-
});
|
|
262
|
-
// @ts-ignore
|
|
263
|
-
vast.on('disable_plugin', (data) => {
|
|
264
|
-
this._playVideoContent(data.type);
|
|
265
|
-
this.disable();
|
|
266
|
-
});
|
|
267
|
-
// @ts-ignore
|
|
268
|
-
vast.on('advertisement_started', () => {
|
|
269
|
-
this.adsPlaying();
|
|
270
|
-
});
|
|
271
|
-
// @ts-ignore
|
|
272
|
-
vast.on('volume', (obj) => {
|
|
273
|
-
this.changeVolume(obj);
|
|
274
|
-
});
|
|
275
|
-
// @ts-ignore
|
|
276
|
-
vast.on('change_counter', (data) => {
|
|
277
|
-
if (data.type === 'middleroll') {
|
|
278
|
-
this.countMiddleRoll = data.value;
|
|
279
|
-
}
|
|
280
|
-
if (data.type === 'repeatableroll') {
|
|
281
|
-
this.countRepeatableRoll = data.value;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
this.vast = vast;
|
|
285
|
-
vast.setupRoll();
|
|
286
|
-
}
|
|
287
|
-
changeVolume(obj) {
|
|
288
|
-
this._volume = obj.volume;
|
|
289
|
-
this.core.options.mute = this.options.mute = obj.mute;
|
|
290
|
-
Utils.Config.persist('volume', this._volume);
|
|
291
|
-
}
|
|
292
|
-
findCloserAdvertisement(roll, key, counter, time) {
|
|
293
|
-
if (!roll) {
|
|
294
|
-
return -1;
|
|
295
|
-
}
|
|
296
|
-
if (roll.data.length <= counter) {
|
|
297
|
-
return -1;
|
|
298
|
-
}
|
|
299
|
-
let val = 0;
|
|
300
|
-
assert(this.playback, 'playback is not defined');
|
|
301
|
-
if (~key.indexOf('Percent')) {
|
|
302
|
-
val = (time / this.playback.getDuration()) * 100;
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
val = time;
|
|
306
|
-
}
|
|
307
|
-
const getNumber = (arr, searchNum) => arr.find((it) => Math.abs(it[key] - searchNum) ===
|
|
308
|
-
Math.min(...arr.map((it) => Math.abs(it[key] - searchNum))));
|
|
309
|
-
const searchEl = getNumber(roll.data, val);
|
|
310
|
-
if (!searchEl) {
|
|
311
|
-
return -1;
|
|
312
|
-
}
|
|
313
|
-
return roll.data.findIndex((el) => el.startTimePercent === searchEl.startTimePercent);
|
|
314
|
-
}
|
|
315
|
-
_validateData(roll) {
|
|
316
|
-
try {
|
|
317
|
-
if (roll.data.length) {
|
|
318
|
-
if (!Object.prototype.hasOwnProperty.call(roll, 'oneByOne')) {
|
|
319
|
-
roll.oneByOne = false;
|
|
320
|
-
}
|
|
321
|
-
return true;
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
return false;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
catch (error) {
|
|
328
|
-
// LogManager.exception(error);
|
|
329
|
-
reportError(error);
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
playerResize(size) {
|
|
334
|
-
this.$el.removeClass('w370');
|
|
335
|
-
if (size.width <= 370 || this.options.hideVolumeBar) {
|
|
336
|
-
this.$el.addClass('w370');
|
|
337
|
-
}
|
|
338
|
-
if (this.vast) {
|
|
339
|
-
this.vast.playerResize(size);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
_stopPauserollListeners() {
|
|
343
|
-
// @ts-ignore
|
|
344
|
-
this.stopListening(this.playback, Events.PLAYBACK_PLAY);
|
|
345
|
-
// @ts-ignore
|
|
346
|
-
this.stopListening(this.playback, Events.PLAYBACK_PAUSE);
|
|
347
|
-
}
|
|
348
|
-
get pluginOptions() {
|
|
349
|
-
return this.options.vastAds;
|
|
350
|
-
}
|
|
351
|
-
_pauserollListeners() {
|
|
352
|
-
if (!this._validateData(this.pluginOptions.pauseroll)) {
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
this._stopPauserollListeners();
|
|
356
|
-
this.currentState = '';
|
|
357
|
-
this.listenTo(this.playback, Events.PLAYBACK_PLAY, () => {
|
|
358
|
-
if (this.currentState === 'pause') {
|
|
359
|
-
this.currentState = 'play';
|
|
360
|
-
setTimeout(() => {
|
|
361
|
-
assert(this.playback, 'playback is not defined');
|
|
362
|
-
this.playback.pause();
|
|
363
|
-
// @ts-ignore
|
|
364
|
-
this._currentPosition = this.playback.getCurrentTime();
|
|
365
|
-
this.initializeRollManager({
|
|
366
|
-
type: 'pauseroll',
|
|
367
|
-
});
|
|
368
|
-
}, 0);
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
// @ts-ignore
|
|
372
|
-
this.stopListening(this.playback, Events.PLAYBACK_PAUSE);
|
|
373
|
-
// @ts-ignore
|
|
374
|
-
this.stopListening(this.playback, Events.PLAYBACK_STOP);
|
|
375
|
-
const wsPlugin = this.core.getPlugin('ws_plugin');
|
|
376
|
-
if (this.playback?.getPlaybackType() === 'live' &&
|
|
377
|
-
wsPlugin?.state === 'live') {
|
|
378
|
-
this.listenToOnce(this.playback, Events.PLAYBACK_STOP, () => {
|
|
379
|
-
console.warn('stop stream', this.currentState);
|
|
380
|
-
this.currentState = 'pause';
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
this.listenToOnce(this.playback, Events.PLAYBACK_PAUSE, () => {
|
|
385
|
-
console.warn('pause stream', this.currentState);
|
|
386
|
-
if (this.currentState === 'switch') {
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
this.currentState = 'pause';
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
this.currentState = 'play';
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
unBindEvents() {
|
|
396
|
-
// @ts-ignore
|
|
397
|
-
this.stopListening(this.core, Events.CORE_READY);
|
|
398
|
-
// @ts-ignore
|
|
399
|
-
this.stopListening(this.mediaControl, Events.MEDIACONTROL_CONTAINERCHANGED);
|
|
400
|
-
// @ts-ignore
|
|
401
|
-
this.stopListening(this.container, Events.CONTAINER_LOADEDMETADATA);
|
|
402
|
-
}
|
|
403
|
-
containerChanged() {
|
|
404
|
-
this.container = this.core.activeContainer;
|
|
405
|
-
this.container.advertisement = { type: 'idle' };
|
|
406
|
-
this._container = this.container;
|
|
407
|
-
this.playback = this.container?.playback;
|
|
408
|
-
assert(this.playback, 'playback is not defined');
|
|
409
|
-
this._contentElement = this.playback.el;
|
|
410
|
-
this._volume =
|
|
411
|
-
this.core &&
|
|
412
|
-
this.core.mediaControl &&
|
|
413
|
-
this.core.mediaControl.volume !== null &&
|
|
414
|
-
this.core.mediaControl.volume !== undefined &&
|
|
415
|
-
!isNaN(this.core.mediaControl.volume)
|
|
416
|
-
? this.core.mediaControl.volume
|
|
417
|
-
: 80;
|
|
418
|
-
this._prevVolumeValue = this._volume ? this._volume : 80;
|
|
419
|
-
this.core.mediaControl.container.$el.append(this.el);
|
|
420
|
-
this.$el.hide();
|
|
421
|
-
// @ts-ignore
|
|
422
|
-
this.stopListening();
|
|
423
|
-
// @ts-ignore
|
|
424
|
-
this._scteManager.off();
|
|
425
|
-
this.bindEvents();
|
|
426
|
-
}
|
|
427
|
-
_pluginError(msg) {
|
|
428
|
-
console.error(this.name + ': ' + msg);
|
|
429
|
-
}
|
|
430
|
-
_onCoreReady() {
|
|
431
|
-
this._container = this.core.activeContainer;
|
|
432
|
-
if (!this._container) {
|
|
433
|
-
this._pluginError('failed to get Clappr current container');
|
|
434
|
-
}
|
|
435
|
-
// Get current playback. (To get playback element)
|
|
436
|
-
this.playback = this.core.activePlayback;
|
|
437
|
-
if (!this.playback) {
|
|
438
|
-
this._pluginError('failed to get Clappr playback');
|
|
439
|
-
}
|
|
440
|
-
// Attempt to get poster plugin. (May interfere with media control)
|
|
441
|
-
this._posterPlugin = this._container?.getPlugin('poster');
|
|
442
|
-
// Attempt to get click-to-pause plugin. (May interfere with advert click handling)
|
|
443
|
-
this._clickToPausePlugin = this._container?.getPlugin('click_to_pause');
|
|
444
|
-
assert(this.playback, 'playback is not defined');
|
|
445
|
-
this._contentElement = this.playback.el;
|
|
446
|
-
if (this._pluginIsReady) {
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
this._initPlugin();
|
|
450
|
-
}
|
|
451
|
-
set playback(value) {
|
|
452
|
-
this._scteManager.playback = value;
|
|
453
|
-
this._playback = value;
|
|
454
|
-
}
|
|
455
|
-
get playback() {
|
|
456
|
-
return this._playback;
|
|
457
|
-
}
|
|
458
|
-
_onContainerVolume(value) {
|
|
459
|
-
if (value === 0) {
|
|
460
|
-
this.options.mute = true;
|
|
461
|
-
}
|
|
462
|
-
else {
|
|
463
|
-
this._prevVolumeValue = value;
|
|
464
|
-
this.options.mute = false;
|
|
465
|
-
}
|
|
466
|
-
this._volume = value;
|
|
467
|
-
}
|
|
468
|
-
_onVolumeChanged(e) {
|
|
469
|
-
if (this._volume === e || e === 0) {
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
this.options.mute = e === 0;
|
|
473
|
-
this._volume = e;
|
|
474
|
-
}
|
|
475
|
-
_stopListening() {
|
|
476
|
-
try {
|
|
477
|
-
assert(this._container, 'container is not defined');
|
|
478
|
-
if (!this._clonePlaybackEvents) {
|
|
479
|
-
for (const id in this._container._listeningTo) {
|
|
480
|
-
this._clonePlaybackEvents = Object.assign({}, this._container._listeningTo[id]._events);
|
|
481
|
-
this._container._listeningTo[id]._events = {};
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
if (!this._cloneContainerEvents) {
|
|
485
|
-
this._cloneContainerEvents = Object.assign({}, this._container._events);
|
|
486
|
-
this._container._events = {};
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
catch (error) {
|
|
490
|
-
// LogManager.exception(error);
|
|
491
|
-
reportError(error);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
_startListening() {
|
|
495
|
-
try {
|
|
496
|
-
assert(this._container, 'container is not defined');
|
|
497
|
-
for (const id in this._container._listeningTo) {
|
|
498
|
-
;
|
|
499
|
-
this._container._listeningTo[id]._events = Object.assign({}, this._clonePlaybackEvents);
|
|
500
|
-
}
|
|
501
|
-
this._container._events = Object.assign({}, this._cloneContainerEvents);
|
|
502
|
-
this._cloneContainerEvents = null;
|
|
503
|
-
this._clonePlaybackEvents = null;
|
|
504
|
-
}
|
|
505
|
-
catch (error) {
|
|
506
|
-
// LogManager.exception(error);
|
|
507
|
-
reportError(error);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
_initPlugin() {
|
|
511
|
-
assert(this.playback, 'playback is not defined');
|
|
512
|
-
// Ensure browser can play video content. (Avoid to display an ad with nothing after)
|
|
513
|
-
if (this.playback.name === 'no_op') {
|
|
514
|
-
return;
|
|
515
|
-
}
|
|
516
|
-
// Ensure playback is using HTML5 video element if mobile device
|
|
517
|
-
if (this.playback.tagName !== 'video' && Browser.isMobile) {
|
|
518
|
-
this.destroy();
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
this._pluginIsReady = true;
|
|
522
|
-
}
|
|
523
|
-
adsPlaying() {
|
|
524
|
-
assert(this.container, 'container is not defined');
|
|
525
|
-
const poster = this.container.getPlugin('poster');
|
|
526
|
-
poster && poster.disable();
|
|
527
|
-
try {
|
|
528
|
-
const logo = this.container.getPlugin('logo');
|
|
529
|
-
logo && logo.disable();
|
|
530
|
-
}
|
|
531
|
-
catch (error) {
|
|
532
|
-
// LogManager.exception(error);
|
|
533
|
-
reportError(error);
|
|
534
|
-
}
|
|
535
|
-
this.core.mediaControl.disable();
|
|
536
|
-
this.$el.show();
|
|
537
|
-
if (this.container.advertisement.type !== 'scteroll') {
|
|
538
|
-
if (!Browser.isiOS) {
|
|
539
|
-
setTimeout(() => {
|
|
540
|
-
this.playback?.pause();
|
|
541
|
-
}, 0);
|
|
542
|
-
}
|
|
543
|
-
this._stopListening();
|
|
544
|
-
}
|
|
545
|
-
else {
|
|
546
|
-
assert(this.playback instanceof HTML5Video, 'playback is not an instance of HTML5Video');
|
|
547
|
-
if (!this.playback.isMuted()) {
|
|
548
|
-
;
|
|
549
|
-
this.container.advertisement.isMuted = true;
|
|
550
|
-
this.playback.mute();
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
// TODO trigger event on the core object
|
|
554
|
-
// Player.player.trigger('advertisementIsPlaying', data);
|
|
555
|
-
try {
|
|
556
|
-
const spinnerPlugin = this.container?.getPlugin('spinner');
|
|
557
|
-
spinnerPlugin?.hide();
|
|
558
|
-
spinnerPlugin?.disable();
|
|
559
|
-
}
|
|
560
|
-
catch (error) {
|
|
561
|
-
// LogManager.exception(error);
|
|
562
|
-
reportError(error);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
destroyRoll() {
|
|
566
|
-
if (this.vast) {
|
|
567
|
-
// @ts-ignore
|
|
568
|
-
this.vast.off();
|
|
569
|
-
this.vast.destroyRoll();
|
|
570
|
-
this.vast = null;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
_playVideoContent(currentRoll, justPlay) {
|
|
574
|
-
// const currentRoll = type;
|
|
575
|
-
this.destroyRoll();
|
|
576
|
-
if (currentRoll === 'preroll') {
|
|
577
|
-
this.pluginOptions[currentRoll] = [];
|
|
578
|
-
}
|
|
579
|
-
this.currentState = '';
|
|
580
|
-
this.$el.hide();
|
|
581
|
-
if (!this.options.disableClickOnPause) {
|
|
582
|
-
// TODO sort out
|
|
583
|
-
this._clickToPausePlugin?.enable();
|
|
584
|
-
}
|
|
585
|
-
try {
|
|
586
|
-
const logoPlugin = this.container?.getPlugin('logo');
|
|
587
|
-
logoPlugin?.enable();
|
|
588
|
-
}
|
|
589
|
-
catch (error) {
|
|
590
|
-
// LogManager.exception(error);
|
|
591
|
-
reportError(error);
|
|
592
|
-
}
|
|
593
|
-
try {
|
|
594
|
-
const spinnerPlugin = this.container?.getPlugin('spinner');
|
|
595
|
-
spinnerPlugin?.enable();
|
|
596
|
-
spinnerPlugin?.hide();
|
|
597
|
-
}
|
|
598
|
-
catch (error) {
|
|
599
|
-
// LogManager.exception(error);
|
|
600
|
-
reportError(error);
|
|
601
|
-
}
|
|
602
|
-
if (this.intervalTimer !== null) {
|
|
603
|
-
clearInterval(this.intervalTimer);
|
|
604
|
-
this.intervalTimer = null;
|
|
605
|
-
}
|
|
606
|
-
// @ts-ignore
|
|
607
|
-
this.stopListening(this.playback, Events.PLAYBACK_PAUSE);
|
|
608
|
-
setTimeout(async () => {
|
|
609
|
-
if (currentRoll === 'scteroll') {
|
|
610
|
-
this.options.mute = this.core.options.mute;
|
|
611
|
-
this.setMuted(this.core.options.mute);
|
|
612
|
-
this.core.mediaControl.setInitialVolume();
|
|
613
|
-
}
|
|
614
|
-
// this.adTemplates = null;
|
|
615
|
-
this._posterBigPlayStyle = $('<style>div.play-wrapper { display:none; }</style>');
|
|
616
|
-
this._posterBigPlayStyle.appendTo(this.$el);
|
|
617
|
-
// TODO check that the core event is enough
|
|
618
|
-
// Player.player.trigger('advertisementWasFinished');
|
|
619
|
-
this.core.trigger('core:advertisement:finish');
|
|
620
|
-
assert(this.container, 'container is not defined');
|
|
621
|
-
this.container.trigger('container:advertisement:finish');
|
|
622
|
-
this.container.advertisement = { type: 'idle' };
|
|
623
|
-
this.container.enableMediaControl();
|
|
624
|
-
Log.debug('Advertisement', 'advertisement finished and start video');
|
|
625
|
-
const playbackOptions = this.core.options.playback || {};
|
|
626
|
-
playbackOptions.recycleVideo = Browser.isMobile;
|
|
627
|
-
if (this._clonePlaybackEvents || this._cloneContainerEvents) {
|
|
628
|
-
this._startListening();
|
|
629
|
-
}
|
|
630
|
-
if (currentRoll === 'preroll' || currentRoll === 'repeatableroll') {
|
|
631
|
-
if (currentRoll === 'repeatableroll') {
|
|
632
|
-
this.startTimeRepeatableRoll = 0;
|
|
633
|
-
}
|
|
634
|
-
if (!justPlay) {
|
|
635
|
-
if (this.core.containers) {
|
|
636
|
-
this.core.containers.forEach(function (container) {
|
|
637
|
-
container.destroy();
|
|
638
|
-
});
|
|
639
|
-
this.core.containers = [];
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
setTimeout(() => {
|
|
643
|
-
this.core.configure({
|
|
644
|
-
playback: playbackOptions,
|
|
645
|
-
sources: this.options.source,
|
|
646
|
-
autoPlay: true,
|
|
647
|
-
disableCanAutoPlay: true,
|
|
648
|
-
mute: this.core.options.mute,
|
|
649
|
-
});
|
|
650
|
-
this.core.activeContainer.mediaControlDisabled = false;
|
|
651
|
-
}, 0);
|
|
652
|
-
// TODO figure out where it should go
|
|
653
|
-
// if (currentRoll === 'postroll') {
|
|
654
|
-
// this.playback.stop();
|
|
655
|
-
// }
|
|
656
|
-
}
|
|
657
|
-
if (currentRoll === 'pauseroll' || currentRoll === 'middleroll') {
|
|
658
|
-
if (Browser.isiOS && this._currentPosition > 0) {
|
|
659
|
-
this.listenToOnce(this.playback, Events.PLAYBACK_PLAY, () => {
|
|
660
|
-
this.playback?.seek(this._currentPosition);
|
|
661
|
-
this._currentPosition = 0;
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
await this.playback?.play();
|
|
665
|
-
this.options.mute = this.core.options.mute;
|
|
666
|
-
this.setMuted(this.core.options.mute);
|
|
667
|
-
this.core.mediaControl.setInitialVolume();
|
|
668
|
-
}
|
|
669
|
-
}, 0);
|
|
670
|
-
}
|
|
671
|
-
render() {
|
|
672
|
-
this.$skipAd = $("<div class='skip-ad-button control-need-disable'></div>");
|
|
673
|
-
this.$muteIcon = $("<div class='mute-ad-icon control-need-disable'></div>");
|
|
674
|
-
this.$areaClick = $("<div class='area-ad-click enable'></div>");
|
|
675
|
-
this.$muteIcon.append(volumeIcon);
|
|
676
|
-
this.$muteIcon.append(volumeMuteIcon);
|
|
677
|
-
this.$el.append(this.$areaClick);
|
|
678
|
-
this.$el.append(this.$skipAd);
|
|
679
|
-
this.$el.append(this.$muteIcon);
|
|
680
|
-
this.$muteIcon.hide();
|
|
681
|
-
this.$skipAd.hide();
|
|
682
|
-
this.$areaClick.hide();
|
|
683
|
-
this._$adContainer = $('<div />')
|
|
684
|
-
.addClass('preroll-container')
|
|
685
|
-
.attr('data-preroll', '');
|
|
686
|
-
this.$el.append(this._$adContainer);
|
|
687
|
-
this._adContainer = this._$adContainer[0];
|
|
688
|
-
return this;
|
|
689
|
-
}
|
|
690
|
-
setMuted(muted) {
|
|
691
|
-
this.core.activeContainer.options.mute = muted;
|
|
692
|
-
}
|
|
693
|
-
}
|