1/*! @name videojs-errors @version 4.1.2 @license Apache-2.0 */ 2(function (global, factory) { 3 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('video.js'), require('global/document')) : 4 typeof define === 'function' && define.amd ? define(['video.js', 'global/document'], factory) : 5 (global.videojsErrors = factory(global.videojs,global.document)); 6}(this, (function (videojs,document) { 'use strict'; 7 8 videojs = videojs && videojs.hasOwnProperty('default') ? videojs['default'] : videojs; 9 document = document && document.hasOwnProperty('default') ? document['default'] : document; 10 11 var version = "4.1.2"; 12 13 var FlashObj = videojs.getComponent('Flash'); 14 var defaultDismiss = !videojs.browser.IS_IPHONE; 15 16 // Video.js 5/6 cross-compatibility. 17 var registerPlugin = videojs.registerPlugin || videojs.plugin; 18 19 // Default options for the plugin. 20 var defaults = { 21 header: '', 22 code: '', 23 message: '', 24 timeout: 45 * 1000, 25 dismiss: defaultDismiss, 26 progressDisabled: false, 27 errors: { 28 '1': { 29 type: 'MEDIA_ERR_ABORTED', 30 headline: 'The video download was cancelled' 31 }, 32 '2': { 33 type: 'MEDIA_ERR_NETWORK', 34 headline: 'The video connection was lost, please confirm you are ' + 'connected to the internet' 35 }, 36 '3': { 37 type: 'MEDIA_ERR_DECODE', 38 headline: 'The video is bad or in a format that cannot be played on your browser' 39 }, 40 '4': { 41 type: 'MEDIA_ERR_SRC_NOT_SUPPORTED', 42 headline: 'This video is either unavailable or not supported in this browser' 43 }, 44 '5': { 45 type: 'MEDIA_ERR_ENCRYPTED', 46 headline: 'The video you are trying to watch is encrypted and we do not know how ' + 'to decrypt it' 47 }, 48 'unknown': { 49 type: 'MEDIA_ERR_UNKNOWN', 50 headline: 'An unanticipated problem was encountered, check back soon and try again' 51 }, 52 '-1': { 53 type: 'PLAYER_ERR_NO_SRC', 54 headline: 'No video has been loaded' 55 }, 56 '-2': { 57 type: 'PLAYER_ERR_TIMEOUT', 58 headline: 'Could not download the video' 59 }, 60 'PLAYER_ERR_DOMAIN_RESTRICTED': { 61 headline: 'This video is restricted from playing on your current domain' 62 }, 63 'PLAYER_ERR_IP_RESTRICTED': { 64 headline: 'This video is restricted at your current IP address' 65 }, 66 'PLAYER_ERR_GEO_RESTRICTED': { 67 headline: 'This video is restricted from playing in your current geographic region' 68 }, 69 'FLASHLS_ERR_CROSS_DOMAIN': { 70 headline: 'The video could not be loaded: crossdomain access denied.' 71 } 72 } 73 }; 74 75 var initPlugin = function initPlugin(player, options) { 76 var monitor = void 0; 77 var waiting = void 0; 78 var isStalling = void 0; 79 var listeners = []; 80 81 var updateErrors = function updateErrors(updates) { 82 options.errors = videojs.mergeOptions(options.errors, updates); 83 84 // Create `code`s from errors which don't have them (based on their keys). 85 Object.keys(options.errors).forEach(function (k) { 86 var err = options.errors[k]; 87 88 if (!err.type) { 89 err.type = k; 90 } 91 }); 92 }; 93 94 // Make sure we flesh out initially-provided errors. 95 updateErrors(); 96 97 // clears the previous monitor timeout and sets up a new one 98 var resetMonitor = function resetMonitor() { 99 // at this point the player has recovered 100 player.clearTimeout(waiting); 101 if (isStalling) { 102 isStalling = false; 103 player.removeClass('vjs-waiting'); 104 } 105 106 // start the loading spinner if player has stalled 107 waiting = player.setTimeout(function () { 108 // player already has an error 109 // or is not playing under normal conditions 110 if (player.error() || player.paused() || player.ended()) { 111 return; 112 } 113 114 isStalling = true; 115 player.addClass('vjs-waiting'); 116 }, 1000); 117 118 player.clearTimeout(monitor); 119 monitor = player.setTimeout(function () { 120 // player already has an error 121 // or is not playing under normal conditions 122 if (player.error() || player.paused() || player.ended()) { 123 return; 124 } 125 126 player.error({ 127 code: -2, 128 type: 'PLAYER_ERR_TIMEOUT' 129 }); 130 }, options.timeout); 131 132 // clear out any existing player timeout 133 // playback has recovered 134 if (player.error() && player.error().code === -2) { 135 player.error(null); 136 } 137 }; 138 139 // clear any previously registered listeners 140 var cleanup = function cleanup() { 141 var listener = void 0; 142 143 while (listeners.length) { 144 listener = listeners.shift(); 145 player.off(listener[0], listener[1]); 146 } 147 player.clearTimeout(monitor); 148 player.clearTimeout(waiting); 149 }; 150 151 // creates and tracks a player listener if the player looks alive
152 var healthcheck = function healthcheck(type, fn) { 153 var check = function check() { 154 // if there's an error do not reset the monitor and 155 // clear the error unless time is progressing 156 if (!player.error()) { 157 // error if using Flash and its API is unavailable 158 var tech = player.$('.vjs-tech'); 159 160 if (tech && tech.type === 'application/x-shockwave-flash' && !tech.vjs_getProperty) { 161 player.error({ 162 code: -2, 163 type: 'PLAYER_ERR_TIMEOUT' 164 }); 165 return; 166 } 167 168 // playback isn't expected if the player is paused 169 if (player.paused()) { 170 return resetMonitor(); 171 } 172 // playback isn't expected once the video has ended 173 if (player.ended()) { 174 return resetMonitor(); 175 } 176 } 177 178 fn.call(this); 179 }; 180 181 player.on(type, check); 182 listeners.push([type, check]); 183 }; 184 185 var onPlayStartMonitor = function onPlayStartMonitor() { 186 var lastTime = 0; 187 188 cleanup(); 189 190 // if no playback is detected for long enough, trigger a timeout error 191 resetMonitor(); 192 healthcheck(['timeupdate', 'adtimeupdate'], function () { 193 var currentTime = player.currentTime(); 194 195 // playback is operating normally or has recovered 196 if (currentTime !== lastTime) { 197 lastTime = currentTime; 198 resetMonitor(); 199 } 200 }); 201 202 if (!options.progressDisabled) { 203 healthcheck('progress', resetMonitor); 204 } 205 }; 206 207 var onPlayNoSource = function onPlayNoSource() { 208 if (!player.currentSrc()) { 209 player.error({ 210 code: -1, 211 type: 'PLAYER_ERR_NO_SRC' 212 }); 213 } 214 }; 215 216 var onErrorHandler = function onErrorHandler() { 217 var details = ''; 218 var error = player.error(); 219 var content = document.createElement('div'); 220 var dialogContent = ''; 221 222 // In the rare case when `error()` does not return an error object, 223 // defensively escape the handler function. 224 if (!error) { 225 return; 226 } 227 228 error = videojs.mergeOptions(error, options.errors[error.code || error.type || 0]); 229 230 if (error.message) { 231 details = '<div class="vjs-errors-details">' + player.localize('Technical details') + '\n : <div class="vjs-errors-message">' + player.localize(error.message) + '</div>\n </div>'; 232 } 233 234 if (error.code === 4 && FlashObj && !FlashObj.isSupported()) { 235 var flashMessage = player.localize('If you are using an older browser please try upgrading or installing Flash.'); 236 237 details += '<span class="vjs-errors-flashmessage">' + flashMessage + '</span>'; 238 } 239 240 var display = player.getChild('errorDisplay'); 241 242 content.className = 'vjs-errors-dialog'; 243 content.id = 'vjs-errors-dialog'; 244 dialogContent = '<div class="vjs-errors-content-container">\n <h2 class="vjs-errors-headline">' + this.localize(error.headline) + '</h2>\n <div><b>' + this.localize('Error Code') + '</b>: ' + (error.type || error.code) + '</div>\n ' + details + '\n </div>'; 245 246 var closeable = display.closeable(!('dismiss' in error) || error.dismiss); 247 248 // We should get a close button 249 if (closeable) { 250 dialogContent += '<div class="vjs-errors-ok-button-container">\n <button class="vjs-errors-ok-button">' + this.localize('OK') + '</button>\n </div>'; 251 content.innerHTML = dialogContent; 252 display.fillWith(content); 253 // Get the close button inside the error display 254 display.contentEl().firstChild.appendChild(display.getChild('closeButton').el()); 255 256 var okButton = display.el().querySelector('.vjs-errors-ok-button'); 257 258 player.on(okButton, 'click', function () { 259 display.close(); 260 }); 261 } else { 262 content.innerHTML = dialogContent; 263 display.fillWith(content); 264 } 265 266 if (player.currentWidth() <= 600 || player.currentHeight() <= 250) { 267 display.addClass('vjs-xs'); 268 } 269 270 display.one('modalclose', function () { 271 return player.error(null); 272 }); 273 }; 274 275 var onDisposeHandler = function onDisposeHandler() { 276 cleanup(); 277 278 player.removeClass('vjs-errors'); 279 player.off('play', onPlayStartMonitor); 280 player.off('play', onPlayNoSource); 281 player.off('dispose', onDisposeHandler); 282 player.off(['aderror', 'error'], onErrorHandler); 283 }; 284 285 var reInitPlugin = function reInitPlugin(newOptions) { 286 onDisposeHandler(); 287 initPlugin(player, videojs.mergeOptions(defaults, newOptions)); 288 }; 289 290 reInitPlugin.extend = function (errors) { 291 return updateErrors(errors); 292 }; 293 reInitPlugin.getAll = function () { 294 return videojs.mergeOptions(options.errors); 295 }; 296 297 // Get / set timeout value. Restart monitor if changed. 298 reInitPlugin.timeout = function (timeout) { 299 if (typeof timeout === 'undefined') { 300 return options.timeout; 301 } 302 if (timeout !== options.timeout) { 303 options.timeout = timeout; 304 if (!player.paused()) { 305 onPlayStartMonitor(); 306 } 307 } 308 }; 309 310 reInitPlugin.disableProgress = function (disabled) { 311 options.progressDisabled = disabled; 312 onPlayStartMonitor(); 313 }; 314 315 player.on('play', onPlayStartMonitor); 316 player.on('play', onPlayNoSource); 317 player.on('dispose', onDisposeHandler); 318 player.on(['aderror', 'error'], onErrorHandler); 319 320 player.ready(function () { 321 player.addClass('vjs-errors'); 322 });
323 324 // if the plugin is re-initialised during playback, start the timeout handler. 325 if (!player.paused()) { 326 onPlayStartMonitor(); 327 } 328 329 // Include the version number. 330 reInitPlugin.VERSION = version; 331 332 player.errors = reInitPlugin; 333 }; 334 335 var errors = function errors(options) { 336 initPlugin(this, videojs.mergeOptions(defaults, options)); 337 }; 338 339 ['extend', 'getAll', 'disableProgress'].forEach(function (k) { 340 errors[k] = function () { 341 videojs.log.warn('The errors.' + k + '() method is not available until the plugin has been initialized!'); 342 }; 343 }); 344 345 // Include the version number. 346 errors.VERSION = version; 347 348 // Register the plugin with video.js. 349 registerPlugin('errors', errors); 350 351 return errors; 352 353})));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.