-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
200 lines (171 loc) · 5.31 KB
/
index.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
var loadCallbacks = [];
window.wikiaJWPlayer = function (elementId, options, callback) {
/**
* gets the android player if user is on an android device browser
*/
function getDefaultPlayerUrl(){
return !!navigator.userAgent.match(/android/i) ? 'https://cdn.jwplayer.com/libraries/MFqndUHM.js' : 'https://content.jwplatform.com/libraries/VXc5h4Tf.js';
}
/**
* adds script tag
* @param elementId
* @param playerURL
*/
function createScriptTag(elementId, playerURL) {
var script = document.createElement('script'),
playerElement = document.getElementById(elementId);
script.onload = function () {
wikiaJWPlayerSettingsPlugin.register();
if (options.sharing) {
wikiaJWPlayerSharingPlugin.register();
}
if (options.showSmallPlayerControls) {
wikiaJWPlayerSmallPlayerControls.register();
}
if (options.useWirewax !== false) {
FandomWirewaxPlugin.register();
}
loadCallbacks.forEach(function (callback) {
callback();
});
};
script.async = true;
script.src = playerURL || getDefaultPlayerUrl();
// insert script node just after player element
playerElement.parentNode.insertBefore(script, playerElement.nextSibling);
}
/**
* loads jwplayer library
* @param elementId
* @param playerURL
* @param callback
*/
function loadJWPlayerScript(elementId, playerURL, callback) {
if (typeof jwplayer !== 'undefined') {
callback();
} else {
loadCallbacks.push(callback);
// we don't want to load multiple jwplayer libraries
if (loadCallbacks.length === 1) {
createScriptTag(elementId, playerURL);
}
}
}
/**
* setups player
* @param elementId
* @param options
* @param logger
* @param lang
* @param i18n
* @return {*}
*/
function setupPlayer(elementId, options, logger, lang, i18n) {
var playerInstance = jwplayer(elementId),
videoId = options.videoDetails.playlist[0].mediaid,
willAutoplay = options.autoplay,
// IMA supports two-letter ISO 639-1 code
langForAds = lang.substr(0, 2),
playerSetup = {
advertising: {
admessage: i18n.admessage,
autoplayadsmuted: willAutoplay,
client: 'googima',
cuetext: i18n.cuetext,
loadVideoTimeout: 16000,
maxRedirects: 8,
requestTimeout: 11500,
setLocale: langForAds,
skipmessage: i18n.skipmessage,
skiptext: i18n.skiptext,
truncateMacros: false,
vastLoadTimeout: 11000,
vpaidcontrols: true,
},
autostart: willAutoplay && !document.hidden,
description: options.videoDetails.description,
image: '//content.jwplatform.com/thumbs/' + videoId + '-640.jpg',
mute: options.mute,
playlist: options.videoDetails.playlist,
title: options.videoDetails.title,
localization: i18n,
repeat: options.repeat,
setTimeEvents: options.setTimeEvents === undefined ? true : options.setTimeEvents,
};
playerSetup.plugins = {};
if (options.settings) {
playerSetup.plugins['wikiaSettings'] = {
showAutoplayToggle: options.settings.showAutoplayToggle,
showQuality: options.settings.showQuality,
showCaptions: options.settings.showCaptions,
autoplay: options.autoplay,
selectedCaptionsLanguage: options.selectedCaptionsLanguage,
i18n: i18n
};
}
if (options.sharing) {
playerSetup.plugins['wikiaSharing'] = {
i18n: i18n
};
}
if (options.related) {
playerSetup.related = {
autoplaytimer: options.related.time || 3,
file: '//cdn.jwplayer.com/v2/playlists/' + options.related.playlistId + '?related_media_id=' + videoId,
oncomplete: options.related.autoplay ? 'autoplay' : 'show',
autoplaymessage: i18n.nextUpInSeconds
};
}
if (options.watermark !== false) {
playerSetup.plugins['wikiaWatermark'] = {};
}
if (options.showSmallPlayerControls) {
playerSetup.plugins['smallPlayerControls'] = {};
}
if(options.useWirewax !== false) {
playerSetup.plugins['fandomWirewax'] = {};
}
logger.info('setupPlayer');
playerInstance.setup(playerSetup).on('ready', function (event) {
if(options.useWirewax !== false) {
window.wirewax_plugin = new FandomWirewaxPlugin(elementId, {
player: jwplayer(elementId),
ready: event,
});
}
});
logger.info('after setup');
logger.subscribeToPlayerErrors(playerInstance);
return playerInstance;
}
loadJWPlayerScript(elementId, options.playerURL, function () {
var logger = wikiaJWPlayerLogger(options),
lang = options.lang || 'en',
i18n = wikiaJWPlayeri18n[lang] || wikiaJWPlayeri18n['en'],
playerInstance = setupPlayer(elementId, options, logger, lang, i18n);
wikiaJWPlayerIdleScreen(playerInstance, i18n);
wikiaJWPlayerReplaceIcons(playerInstance);
wikiaJWPlayerEvents(playerInstance, options.autoplay, logger);
if (options.related) {
wikiaJWPlayerRelatedVideoSound(playerInstance);
}
if (options.tracking) {
options.tracking.pixel = options.videoDetails.playlist[0].pixel;
wikiaJWPlayerTracking(playerInstance, options.autoplay, options.tracking);
}
wikiaJWPlayerHandleTabNotActive(playerInstance, options.autoplay);
wikiaJWPlayerAllowControllOnTouchDevices(playerInstance);
wikiaJWPlayerUserIntendedPlayControl(
options.shouldForceUserIntendedPlay,
playerInstance,
options.tracking,
options.autoplay
);
if(options.watermark !== false) {
WikiaJWPlayerWatermarkPlugin.register();
}
if (callback) {
callback(playerInstance);
}
});
};