forked from videojs/videojs-contrib-ads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
95 lines (84 loc) · 2.64 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
(function() {
'use strict';
var pad = function(n, x, c) {
return (new Array(n).join(c || '0') + x).slice(-n);
};
var padRight = function(n, x, c) {
return (x + (new Array(n).join(c || '0'))).slice(0, n);
};
var player = videojs('examplePlayer', {}, function(){
// initalize example ads integration for this player
var player = this;
player.exampleAds({
debug: true
});
var log = document.querySelector('.log');
var Html5 = videojs.getTech('Html5');
Html5.Events.concat(Html5.Events.map(function(evt) {
return 'ad' + evt;
})).concat(Html5.Events.map(function(evt) {
return 'content' + evt;
})).concat([
// events emitted by ad plugin
'adtimeout',
'contentupdate',
'contentplayback',
// events emitted by third party ad implementors
'adsready',
'adscanceled',
'adplaying',
'adstart', // startLinearAdMode()
'adend' // endLinearAdMode()
]).filter(function(evt) {
var events = {
progress: 1,
timeupdate: 1,
suspend: 1,
emptied: 1,
contentprogress: 1,
contenttimeupdate: 1,
contentsuspend: 1,
contentemptied: 1,
adprogress: 1,
adtimeupdate: 1,
adsuspend: 1,
ademptied: 1
}
return !(evt in events);
}).map(function(evt) {
player.on(evt, function(event) {
var d , str, li;
li = document.createElement('li');
d = new Date();
d = '' +
pad(2, d.getHours()) + ':' +
pad(2, d.getMinutes()) + ':' +
pad(2, d.getSeconds()) + '.' +
pad(3, d.getMilliseconds());
if (event.type.indexOf('ad') === 0) {
li.className = 'ad-event';
} else if (event.type.indexOf('content') === 0) {
li.className = 'content-event';
}
str = '[' + (d) + '] ' + padRight(19, '[' + (event.state ? event.state : player.ads.state + '*') + ']', ' ') + ' ' + evt;
if (evt === 'contentupdate') {
str += "\toldValue: " + event.oldValue + "\n" +
"\tnewValue: " + event.newValue + "\n";
li.className = 'content-adplugin-event';
}
if (evt === 'contentplayback') {
li.className = 'content-adplugin-event';
}
if (evt === 'adplay') {
player.trigger('ads-ad-started');
}
li.innerHTML = str;
log.insertBefore(li, log.firstChild);
});
});
});
document.querySelector('form').addEventListener('submit', function(event) {
event.preventDefault();
player.src(document.querySelector('input[type="url"]').value);
});
})();