From c1e464c5cc150e1075c02de062f1c18faa6b5069 Mon Sep 17 00:00:00 2001 From: Pat O'Neill Date: Thu, 30 Jul 2015 15:30:45 -0400 Subject: [PATCH 1/3] Updates for VideoJS 5.0 One test is failing until PR #2418 is merged in VideoJS. --- dist/videojs-errors.js | 8 ++++---- dist/videojs-errors.min.js | 4 ++-- package.json | 2 +- src/videojs.errors.js | 6 +++--- test/index.html | 2 +- test/videojs-errors.test.js | 16 ++++++++++------ 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/dist/videojs-errors.js b/dist/videojs-errors.js index 2ecf29c..5bc073c 100644 --- a/dist/videojs-errors.js +++ b/dist/videojs-errors.js @@ -1,4 +1,4 @@ -/*! videojs-errors - v0.1.8 - 2015-05-05 +/*! videojs-errors - v0.1.8 - 2015-07-30 * Copyright (c) 2015 Brightcove; Licensed Apache-2.0 */ (function(){ var @@ -49,7 +49,7 @@ */ monitorPlayback = function(player, options) { var - settings = videojs.util.mergeOptions(defaults, options), + settings = videojs.mergeOptions(defaults, options), monitor, // clears the previous monitor timeout and sets up a new one @@ -157,13 +157,13 @@ var player = this, // Merge the external and default settings - settings = videojs.util.mergeOptions(defaults, options); + settings = videojs.mergeOptions(defaults, options); // Add to the error dialog when an error occurs this.on('error', function() { var code, error, display, details = ''; - error = videojs.util.mergeOptions(this.error(), settings.errors[this.error().code || 0]); + error = videojs.mergeOptions(this.error(), settings.errors[this.error().code || 0]); if (error.message) { details = '
' + this.localize('Technical details') + diff --git a/dist/videojs-errors.min.js b/dist/videojs-errors.min.js index f9ec363..47a6af9 100644 --- a/dist/videojs-errors.min.js +++ b/dist/videojs-errors.min.js @@ -1,3 +1,3 @@ -/*! videojs-errors - v0.1.8 - 2015-05-05 +/*! videojs-errors - v0.1.8 - 2015-07-30 * Copyright (c) 2015 Brightcove; Licensed Apache-2.0 */ -!function(){var a={header:"",code:"",message:"",timeout:45e3,errors:{1:{type:"MEDIA_ERR_ABORTED",headline:"The video download was cancelled"},2:{type:"MEDIA_ERR_NETWORK",headline:"The video connection was lost, please confirm you are connected to the internet"},3:{type:"MEDIA_ERR_DECODE",headline:"The video is bad or in a format that cannot be played on your browser"},4:{type:"MEDIA_ERR_SRC_NOT_SUPPORTED",headline:"This video is either unavailable or not supported in this browser"},5:{type:"MEDIA_ERR_ENCRYPTED",headline:"The video you are trying to watch is encrypted and we do not know how to decrypt it"},unknown:{type:"MEDIA_ERR_UNKNOWN",headline:"An unanticipated problem was encountered, check back soon and try again"},"-1":{type:"PLAYER_ERR_NO_SRC",headline:"No video has been loaded"},"-2":{type:"PLAYER_ERR_TIMEOUT",headline:"Could not download the video"}}},b=function(b,c){var d,e=videojs.util.mergeOptions(a,c),f=function(){window.clearTimeout(d),d=window.setTimeout(function(){b.error()||b.paused()||b.ended()||b.error({code:-2,type:"PLAYER_ERR_TIMEOUT"})},e.timeout),b.error()&&-2===b.error().code&&b.error(null)},g=[],h=function(a,c){var d=function(){return b.paused()?i():b.ended()?i():void c.call(this)};b.on(a,d),g.push([a,d])},i=function(){for(var a;g.length;)a=g.shift(),b.off(a[0],a[1]);window.clearTimeout(d)};b.on("play",function(){var a=0;i(),f(),h("timeupdate",function(){var c=b.currentTime();c!==a&&(a=c,f())}),h("progress",f)}),b.on("dispose",function(){i()})},c=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},d=function(a,c){b(a,c),a.on("play",function(){(null===a.currentSrc()||void 0===a.currentSrc()||""===a.currentSrc())&&a.error({code:-1,type:"PLAYER_ERR_NO_SRC"})})};videojs.plugin("errors",function(b){var e=this,f=videojs.util.mergeOptions(a,b);this.on("error",function(){var a,b,d="";a=videojs.util.mergeOptions(this.error(),f.errors[this.error().code||0]),a.message&&(d='
'+this.localize("Technical details")+':
'+this.localize(a.message)+"
"),b=this.errorDisplay,b.el().innerHTML='

'+this.localize(a.headline)+"

"+this.localize("Error Code")+": "+(a.type||a.code)+"
"+this.localize(d)+'
",(e.width()<=600||e.height()<=250)&&b.addClass("vjs-xs"),c(b.el().querySelector(".vjs-errors-close-button"),"click",function(){b.hide()}),c(b.el().querySelector(".vjs-errors-ok-button"),"click",function(){b.hide()})}),d(this,f)})}(); \ No newline at end of file +!function(){var a={header:"",code:"",message:"",timeout:45e3,errors:{1:{type:"MEDIA_ERR_ABORTED",headline:"The video download was cancelled"},2:{type:"MEDIA_ERR_NETWORK",headline:"The video connection was lost, please confirm you are connected to the internet"},3:{type:"MEDIA_ERR_DECODE",headline:"The video is bad or in a format that cannot be played on your browser"},4:{type:"MEDIA_ERR_SRC_NOT_SUPPORTED",headline:"This video is either unavailable or not supported in this browser"},5:{type:"MEDIA_ERR_ENCRYPTED",headline:"The video you are trying to watch is encrypted and we do not know how to decrypt it"},unknown:{type:"MEDIA_ERR_UNKNOWN",headline:"An unanticipated problem was encountered, check back soon and try again"},"-1":{type:"PLAYER_ERR_NO_SRC",headline:"No video has been loaded"},"-2":{type:"PLAYER_ERR_TIMEOUT",headline:"Could not download the video"}}},b=function(b,c){var d,e=videojs.mergeOptions(a,c),f=function(){window.clearTimeout(d),d=window.setTimeout(function(){b.error()||b.paused()||b.ended()||b.error({code:-2,type:"PLAYER_ERR_TIMEOUT"})},e.timeout),b.error()&&-2===b.error().code&&b.error(null)},g=[],h=function(a,c){var d=function(){return b.paused()?i():b.ended()?i():void c.call(this)};b.on(a,d),g.push([a,d])},i=function(){for(var a;g.length;)a=g.shift(),b.off(a[0],a[1]);window.clearTimeout(d)};b.on("play",function(){var a=0;i(),f(),h("timeupdate",function(){var c=b.currentTime();c!==a&&(a=c,f())}),h("progress",f)}),b.on("dispose",function(){i()})},c=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},d=function(a,c){b(a,c),a.on("play",function(){(null===a.currentSrc()||void 0===a.currentSrc()||""===a.currentSrc())&&a.error({code:-1,type:"PLAYER_ERR_NO_SRC"})})};videojs.plugin("errors",function(b){var e=this,f=videojs.mergeOptions(a,b);this.on("error",function(){var a,b,d="";a=videojs.mergeOptions(this.error(),f.errors[this.error().code||0]),a.message&&(d='
'+this.localize("Technical details")+':
'+this.localize(a.message)+"
"),b=this.errorDisplay,b.el().innerHTML='

'+this.localize(a.headline)+"

"+this.localize("Error Code")+": "+(a.type||a.code)+"
"+this.localize(d)+'
",(e.width()<=600||e.height()<=250)&&b.addClass("vjs-xs"),c(b.el().querySelector(".vjs-errors-close-button"),"click",function(){b.hide()}),c(b.el().querySelector(".vjs-errors-ok-button"),"click",function(){b.hide()})}),d(this,f)})}(); \ No newline at end of file diff --git a/package.json b/package.json index d5e864e..738da3d 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,6 @@ "load-grunt-tasks": "0.6.0", "qunitjs": "^1.12", "sinon": "^1.14.1", - "video.js": "^4.12.5" + "video.js": "5.0.0-rc.34" } } diff --git a/src/videojs.errors.js b/src/videojs.errors.js index 6a1248b..eed570a 100644 --- a/src/videojs.errors.js +++ b/src/videojs.errors.js @@ -47,7 +47,7 @@ */ monitorPlayback = function(player, options) { var - settings = videojs.util.mergeOptions(defaults, options), + settings = videojs.mergeOptions(defaults, options), monitor, // clears the previous monitor timeout and sets up a new one @@ -155,13 +155,13 @@ var player = this, // Merge the external and default settings - settings = videojs.util.mergeOptions(defaults, options); + settings = videojs.mergeOptions(defaults, options); // Add to the error dialog when an error occurs this.on('error', function() { var code, error, display, details = ''; - error = videojs.util.mergeOptions(this.error(), settings.errors[this.error().code || 0]); + error = videojs.mergeOptions(this.error(), settings.errors[this.error().code || 0]); if (error.message) { details = '
' + this.localize('Technical details') + diff --git a/test/index.html b/test/index.html index f4ef8fb..78977c7 100644 --- a/test/index.html +++ b/test/index.html @@ -16,7 +16,7 @@ ok(true, 'everything is swell'); }); - + diff --git a/test/videojs-errors.test.js b/test/videojs-errors.test.js index 4409b6b..78caa9b 100644 --- a/test/videojs-errors.test.js +++ b/test/videojs-errors.test.js @@ -31,14 +31,16 @@ module('videojs-errors', { setup: function() { + var Html5 = videojs.getComponent('Html5'); + // force HTML support so the tests run in a reasonable // environment under phantomjs - realIsHtmlSupported = videojs.Html5.isSupported; - videojs.Html5.isSupported = function() { + realIsHtmlSupported = Html5.isSupported; + Html5.isSupported = function() { return true; }; - realCanPlaySource = videojs.Html5.canPlaySource; - videojs.Html5.canPlaySource = function() { + realCanPlaySource = Html5.canPlaySource; + Html5.canPlaySource = function() { return true; }; @@ -62,8 +64,10 @@ player.errors(); }, teardown: function() { - videojs.Html5.isSupported = realIsHtmlSupported; - videojs.Html5.canPlaySource = realCanPlaySource; + var Html5 = videojs.getComponent('Html5'); + + Html5.isSupported = realIsHtmlSupported; + Html5.canPlaySource = realCanPlaySource; clock.restore(); } }); From 29bf5be1068c51227da816625230aab71f2507ad Mon Sep 17 00:00:00 2001 From: Pat O'Neill Date: Wed, 5 Aug 2015 13:18:58 -0400 Subject: [PATCH 2/3] Bring in changes from #29 --- dist/videojs-errors.js | 12 ++++++++++-- dist/videojs-errors.min.js | 4 ++-- src/videojs.errors.js | 10 +++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/dist/videojs-errors.js b/dist/videojs-errors.js index 5bc073c..e34e1e9 100644 --- a/dist/videojs-errors.js +++ b/dist/videojs-errors.js @@ -1,4 +1,4 @@ -/*! videojs-errors - v0.1.8 - 2015-07-30 +/*! videojs-errors - v0.1.8 - 2015-08-05 * Copyright (c) 2015 Brightcove; Licensed Apache-2.0 */ (function(){ var @@ -163,7 +163,15 @@ this.on('error', function() { var code, error, display, details = ''; - error = videojs.mergeOptions(this.error(), settings.errors[this.error().code || 0]); + error = this.error(); + + // In the rare case when `error()` does not return an error object, + // defensively escape the handler function. + if (!error) { + return; + } + + error = videojs.mergeOptions(error, settings.errors[error.code || 0]); if (error.message) { details = '
' + this.localize('Technical details') + diff --git a/dist/videojs-errors.min.js b/dist/videojs-errors.min.js index 47a6af9..a4eb28b 100644 --- a/dist/videojs-errors.min.js +++ b/dist/videojs-errors.min.js @@ -1,3 +1,3 @@ -/*! videojs-errors - v0.1.8 - 2015-07-30 +/*! videojs-errors - v0.1.8 - 2015-08-05 * Copyright (c) 2015 Brightcove; Licensed Apache-2.0 */ -!function(){var a={header:"",code:"",message:"",timeout:45e3,errors:{1:{type:"MEDIA_ERR_ABORTED",headline:"The video download was cancelled"},2:{type:"MEDIA_ERR_NETWORK",headline:"The video connection was lost, please confirm you are connected to the internet"},3:{type:"MEDIA_ERR_DECODE",headline:"The video is bad or in a format that cannot be played on your browser"},4:{type:"MEDIA_ERR_SRC_NOT_SUPPORTED",headline:"This video is either unavailable or not supported in this browser"},5:{type:"MEDIA_ERR_ENCRYPTED",headline:"The video you are trying to watch is encrypted and we do not know how to decrypt it"},unknown:{type:"MEDIA_ERR_UNKNOWN",headline:"An unanticipated problem was encountered, check back soon and try again"},"-1":{type:"PLAYER_ERR_NO_SRC",headline:"No video has been loaded"},"-2":{type:"PLAYER_ERR_TIMEOUT",headline:"Could not download the video"}}},b=function(b,c){var d,e=videojs.mergeOptions(a,c),f=function(){window.clearTimeout(d),d=window.setTimeout(function(){b.error()||b.paused()||b.ended()||b.error({code:-2,type:"PLAYER_ERR_TIMEOUT"})},e.timeout),b.error()&&-2===b.error().code&&b.error(null)},g=[],h=function(a,c){var d=function(){return b.paused()?i():b.ended()?i():void c.call(this)};b.on(a,d),g.push([a,d])},i=function(){for(var a;g.length;)a=g.shift(),b.off(a[0],a[1]);window.clearTimeout(d)};b.on("play",function(){var a=0;i(),f(),h("timeupdate",function(){var c=b.currentTime();c!==a&&(a=c,f())}),h("progress",f)}),b.on("dispose",function(){i()})},c=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},d=function(a,c){b(a,c),a.on("play",function(){(null===a.currentSrc()||void 0===a.currentSrc()||""===a.currentSrc())&&a.error({code:-1,type:"PLAYER_ERR_NO_SRC"})})};videojs.plugin("errors",function(b){var e=this,f=videojs.mergeOptions(a,b);this.on("error",function(){var a,b,d="";a=videojs.mergeOptions(this.error(),f.errors[this.error().code||0]),a.message&&(d='
'+this.localize("Technical details")+':
'+this.localize(a.message)+"
"),b=this.errorDisplay,b.el().innerHTML='

'+this.localize(a.headline)+"

"+this.localize("Error Code")+": "+(a.type||a.code)+"
"+this.localize(d)+'
",(e.width()<=600||e.height()<=250)&&b.addClass("vjs-xs"),c(b.el().querySelector(".vjs-errors-close-button"),"click",function(){b.hide()}),c(b.el().querySelector(".vjs-errors-ok-button"),"click",function(){b.hide()})}),d(this,f)})}(); \ No newline at end of file +!function(){var a={header:"",code:"",message:"",timeout:45e3,errors:{1:{type:"MEDIA_ERR_ABORTED",headline:"The video download was cancelled"},2:{type:"MEDIA_ERR_NETWORK",headline:"The video connection was lost, please confirm you are connected to the internet"},3:{type:"MEDIA_ERR_DECODE",headline:"The video is bad or in a format that cannot be played on your browser"},4:{type:"MEDIA_ERR_SRC_NOT_SUPPORTED",headline:"This video is either unavailable or not supported in this browser"},5:{type:"MEDIA_ERR_ENCRYPTED",headline:"The video you are trying to watch is encrypted and we do not know how to decrypt it"},unknown:{type:"MEDIA_ERR_UNKNOWN",headline:"An unanticipated problem was encountered, check back soon and try again"},"-1":{type:"PLAYER_ERR_NO_SRC",headline:"No video has been loaded"},"-2":{type:"PLAYER_ERR_TIMEOUT",headline:"Could not download the video"}}},b=function(b,c){var d,e=videojs.mergeOptions(a,c),f=function(){window.clearTimeout(d),d=window.setTimeout(function(){b.error()||b.paused()||b.ended()||b.error({code:-2,type:"PLAYER_ERR_TIMEOUT"})},e.timeout),b.error()&&-2===b.error().code&&b.error(null)},g=[],h=function(a,c){var d=function(){return b.paused()?i():b.ended()?i():void c.call(this)};b.on(a,d),g.push([a,d])},i=function(){for(var a;g.length;)a=g.shift(),b.off(a[0],a[1]);window.clearTimeout(d)};b.on("play",function(){var a=0;i(),f(),h("timeupdate",function(){var c=b.currentTime();c!==a&&(a=c,f())}),h("progress",f)}),b.on("dispose",function(){i()})},c=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},d=function(a,c){b(a,c),a.on("play",function(){(null===a.currentSrc()||void 0===a.currentSrc()||""===a.currentSrc())&&a.error({code:-1,type:"PLAYER_ERR_NO_SRC"})})};videojs.plugin("errors",function(b){var e=this,f=videojs.mergeOptions(a,b);this.on("error",function(){var a,b,d="";a=this.error(),a&&(a=videojs.mergeOptions(a,f.errors[a.code||0]),a.message&&(d='
'+this.localize("Technical details")+':
'+this.localize(a.message)+"
"),b=this.errorDisplay,b.el().innerHTML='

'+this.localize(a.headline)+"

"+this.localize("Error Code")+": "+(a.type||a.code)+"
"+this.localize(d)+'
",(e.width()<=600||e.height()<=250)&&b.addClass("vjs-xs"),c(b.el().querySelector(".vjs-errors-close-button"),"click",function(){b.hide()}),c(b.el().querySelector(".vjs-errors-ok-button"),"click",function(){b.hide()}))}),d(this,f)})}(); \ No newline at end of file diff --git a/src/videojs.errors.js b/src/videojs.errors.js index eed570a..2131316 100644 --- a/src/videojs.errors.js +++ b/src/videojs.errors.js @@ -161,7 +161,15 @@ this.on('error', function() { var code, error, display, details = ''; - error = videojs.mergeOptions(this.error(), settings.errors[this.error().code || 0]); + error = this.error(); + + // In the rare case when `error()` does not return an error object, + // defensively escape the handler function. + if (!error) { + return; + } + + error = videojs.mergeOptions(error, settings.errors[error.code || 0]); if (error.message) { details = '
' + this.localize('Technical details') + From e102e4f10e1981dc045863720d7bc9acc5e0002e Mon Sep 17 00:00:00 2001 From: Pat O'Neill Date: Tue, 17 Nov 2015 15:32:57 -0500 Subject: [PATCH 3/3] Don't do anything until player is ready --- dist/videojs-errors.js | 87 +++++++++++++++++++------------------- dist/videojs-errors.min.js | 4 +- package.json | 22 +++++----- src/videojs.errors.js | 85 +++++++++++++++++++------------------ 4 files changed, 100 insertions(+), 98 deletions(-) diff --git a/dist/videojs-errors.js b/dist/videojs-errors.js index e34e1e9..2e1055f 100644 --- a/dist/videojs-errors.js +++ b/dist/videojs-errors.js @@ -1,4 +1,4 @@ -/*! videojs-errors - v0.1.8 - 2015-08-05 +/*! videojs-errors - v0.1.8 - 2015-11-17 * Copyright (c) 2015 Brightcove; Licensed Apache-2.0 */ (function(){ var @@ -134,7 +134,6 @@ // Setup Custom Error Conditions var initCustomErrorConditions = function(player, options) { - var stalledTimeout, playbackMonitor; // PLAYER_ERR_TIMEOUT monitorPlayback(player, options); @@ -153,60 +152,62 @@ }; videojs.plugin('errors', function(options){ - var player = this, // Merge the external and default settings settings = videojs.mergeOptions(defaults, options); - // Add to the error dialog when an error occurs - this.on('error', function() { - var code, error, display, details = ''; + player.ready(function() { - error = this.error(); + // Add to the error dialog when an error occurs + this.on('error', function() { + var code, error, display, details = ''; - // In the rare case when `error()` does not return an error object, - // defensively escape the handler function. - if (!error) { - return; - } + error = this.error(); + + // In the rare case when `error()` does not return an error object, + // defensively escape the handler function. + if (!error) { + return; + } - error = videojs.mergeOptions(error, settings.errors[error.code || 0]); + error = videojs.mergeOptions(error, settings.errors[error.code || 0]); - if (error.message) { - details = '
' + this.localize('Technical details') + - ':
' + this.localize(error.message) + '
' + + if (error.message) { + details = '
' + this.localize('Technical details') + + ':
' + this.localize(error.message) + '
' + + '
'; + } + + display = this.errorDisplay; + + display.el().innerHTML = + '
' + + '' + + '
' + + '

' + this.localize(error.headline) + '

' + + '
' + this.localize('Error Code') + ': ' + (error.type || error.code) + '
' + + this.localize(details) + + '
' + + '
' + + '' + + '
' + '
'; - } - display = this.errorDisplay; - - display.el().innerHTML = - '
' + - '' + - '
' + - '

' + this.localize(error.headline) + '

' + - '
' + this.localize('Error Code') + ': ' + (error.type || error.code) + '
' + - this.localize(details) + - '
' + - '
' + - '' + - '
' + - '
'; - - if (player.width() <= 600 || player.height() <= 250) { - display.addClass('vjs-xs'); - } + if (player.width() <= 600 || player.height() <= 250) { + display.addClass('vjs-xs'); + } - on(display.el().querySelector('.vjs-errors-close-button'), 'click', function() { - display.hide(); - }); - on(display.el().querySelector('.vjs-errors-ok-button'), 'click', function() { - display.hide(); + on(display.el().querySelector('.vjs-errors-close-button'), 'click', function() { + display.hide(); + }); + on(display.el().querySelector('.vjs-errors-ok-button'), 'click', function() { + display.hide(); + }); }); - }); - // Initialize custom error conditions - initCustomErrorConditions(this, settings); + // Initialize custom error conditions + initCustomErrorConditions(this, settings); + }); }); })(); diff --git a/dist/videojs-errors.min.js b/dist/videojs-errors.min.js index a4eb28b..669bb2d 100644 --- a/dist/videojs-errors.min.js +++ b/dist/videojs-errors.min.js @@ -1,3 +1,3 @@ -/*! videojs-errors - v0.1.8 - 2015-08-05 +/*! videojs-errors - v0.1.8 - 2015-11-17 * Copyright (c) 2015 Brightcove; Licensed Apache-2.0 */ -!function(){var a={header:"",code:"",message:"",timeout:45e3,errors:{1:{type:"MEDIA_ERR_ABORTED",headline:"The video download was cancelled"},2:{type:"MEDIA_ERR_NETWORK",headline:"The video connection was lost, please confirm you are connected to the internet"},3:{type:"MEDIA_ERR_DECODE",headline:"The video is bad or in a format that cannot be played on your browser"},4:{type:"MEDIA_ERR_SRC_NOT_SUPPORTED",headline:"This video is either unavailable or not supported in this browser"},5:{type:"MEDIA_ERR_ENCRYPTED",headline:"The video you are trying to watch is encrypted and we do not know how to decrypt it"},unknown:{type:"MEDIA_ERR_UNKNOWN",headline:"An unanticipated problem was encountered, check back soon and try again"},"-1":{type:"PLAYER_ERR_NO_SRC",headline:"No video has been loaded"},"-2":{type:"PLAYER_ERR_TIMEOUT",headline:"Could not download the video"}}},b=function(b,c){var d,e=videojs.mergeOptions(a,c),f=function(){window.clearTimeout(d),d=window.setTimeout(function(){b.error()||b.paused()||b.ended()||b.error({code:-2,type:"PLAYER_ERR_TIMEOUT"})},e.timeout),b.error()&&-2===b.error().code&&b.error(null)},g=[],h=function(a,c){var d=function(){return b.paused()?i():b.ended()?i():void c.call(this)};b.on(a,d),g.push([a,d])},i=function(){for(var a;g.length;)a=g.shift(),b.off(a[0],a[1]);window.clearTimeout(d)};b.on("play",function(){var a=0;i(),f(),h("timeupdate",function(){var c=b.currentTime();c!==a&&(a=c,f())}),h("progress",f)}),b.on("dispose",function(){i()})},c=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},d=function(a,c){b(a,c),a.on("play",function(){(null===a.currentSrc()||void 0===a.currentSrc()||""===a.currentSrc())&&a.error({code:-1,type:"PLAYER_ERR_NO_SRC"})})};videojs.plugin("errors",function(b){var e=this,f=videojs.mergeOptions(a,b);this.on("error",function(){var a,b,d="";a=this.error(),a&&(a=videojs.mergeOptions(a,f.errors[a.code||0]),a.message&&(d='
'+this.localize("Technical details")+':
'+this.localize(a.message)+"
"),b=this.errorDisplay,b.el().innerHTML='

'+this.localize(a.headline)+"

"+this.localize("Error Code")+": "+(a.type||a.code)+"
"+this.localize(d)+'
",(e.width()<=600||e.height()<=250)&&b.addClass("vjs-xs"),c(b.el().querySelector(".vjs-errors-close-button"),"click",function(){b.hide()}),c(b.el().querySelector(".vjs-errors-ok-button"),"click",function(){b.hide()}))}),d(this,f)})}(); \ No newline at end of file +!function(){var a={header:"",code:"",message:"",timeout:45e3,errors:{1:{type:"MEDIA_ERR_ABORTED",headline:"The video download was cancelled"},2:{type:"MEDIA_ERR_NETWORK",headline:"The video connection was lost, please confirm you are connected to the internet"},3:{type:"MEDIA_ERR_DECODE",headline:"The video is bad or in a format that cannot be played on your browser"},4:{type:"MEDIA_ERR_SRC_NOT_SUPPORTED",headline:"This video is either unavailable or not supported in this browser"},5:{type:"MEDIA_ERR_ENCRYPTED",headline:"The video you are trying to watch is encrypted and we do not know how to decrypt it"},unknown:{type:"MEDIA_ERR_UNKNOWN",headline:"An unanticipated problem was encountered, check back soon and try again"},"-1":{type:"PLAYER_ERR_NO_SRC",headline:"No video has been loaded"},"-2":{type:"PLAYER_ERR_TIMEOUT",headline:"Could not download the video"}}},b=function(b,c){var d,e=videojs.mergeOptions(a,c),f=function(){window.clearTimeout(d),d=window.setTimeout(function(){b.error()||b.paused()||b.ended()||b.error({code:-2,type:"PLAYER_ERR_TIMEOUT"})},e.timeout),b.error()&&-2===b.error().code&&b.error(null)},g=[],h=function(a,c){var d=function(){return b.paused()?i():b.ended()?i():void c.call(this)};b.on(a,d),g.push([a,d])},i=function(){for(var a;g.length;)a=g.shift(),b.off(a[0],a[1]);window.clearTimeout(d)};b.on("play",function(){var a=0;i(),f(),h("timeupdate",function(){var c=b.currentTime();c!==a&&(a=c,f())}),h("progress",f)}),b.on("dispose",function(){i()})},c=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)},d=function(a,c){b(a,c),a.on("play",function(){(null===a.currentSrc()||void 0===a.currentSrc()||""===a.currentSrc())&&a.error({code:-1,type:"PLAYER_ERR_NO_SRC"})})};videojs.plugin("errors",function(b){var e=this,f=videojs.mergeOptions(a,b);e.ready(function(){this.on("error",function(){var a,b,d="";a=this.error(),a&&(a=videojs.mergeOptions(a,f.errors[a.code||0]),a.message&&(d='
'+this.localize("Technical details")+':
'+this.localize(a.message)+"
"),b=this.errorDisplay,b.el().innerHTML='

'+this.localize(a.headline)+"

"+this.localize("Error Code")+": "+(a.type||a.code)+"
"+this.localize(d)+'
",(e.width()<=600||e.height()<=250)&&b.addClass("vjs-xs"),c(b.el().querySelector(".vjs-errors-close-button"),"click",function(){b.hide()}),c(b.el().querySelector(".vjs-errors-ok-button"),"click",function(){b.hide()}))}),d(this,f)})})}(); \ No newline at end of file diff --git a/package.json b/package.json index 738da3d..6a9056a 100644 --- a/package.json +++ b/package.json @@ -21,17 +21,17 @@ "dependencies": {}, "devDependencies": { "grunt": "^0.4.4", - "grunt-contrib-clean": "^0.4", - "grunt-contrib-concat": "^0.3", - "grunt-contrib-connect": "^0.7", - "grunt-contrib-jshint": "^0.6", - "grunt-contrib-qunit": "^0.2", - "grunt-contrib-uglify": "^0.2", - "grunt-contrib-watch": "^0.4", - "grunt-videojs-languages": "0.0.4", - "load-grunt-tasks": "0.6.0", - "qunitjs": "^1.12", + "grunt-contrib-clean": "^0.4.0", + "grunt-contrib-concat": "^0.3.0", + "grunt-contrib-connect": "^0.7.0", + "grunt-contrib-jshint": "^0.6.0", + "grunt-contrib-qunit": "^0.2.0", + "grunt-contrib-uglify": "^0.2.0", + "grunt-contrib-watch": "^0.4.0", + "grunt-videojs-languages": "^0.0.4", + "load-grunt-tasks": "^0.6.0", + "qunitjs": "^1.12.0", "sinon": "^1.14.1", - "video.js": "5.0.0-rc.34" + "video.js": "^5.2.1" } } diff --git a/src/videojs.errors.js b/src/videojs.errors.js index 2131316..4f14635 100644 --- a/src/videojs.errors.js +++ b/src/videojs.errors.js @@ -132,7 +132,6 @@ // Setup Custom Error Conditions var initCustomErrorConditions = function(player, options) { - var stalledTimeout, playbackMonitor; // PLAYER_ERR_TIMEOUT monitorPlayback(player, options); @@ -151,60 +150,62 @@ }; videojs.plugin('errors', function(options){ - var player = this, // Merge the external and default settings settings = videojs.mergeOptions(defaults, options); - // Add to the error dialog when an error occurs - this.on('error', function() { - var code, error, display, details = ''; + player.ready(function() { - error = this.error(); + // Add to the error dialog when an error occurs + this.on('error', function() { + var code, error, display, details = ''; - // In the rare case when `error()` does not return an error object, - // defensively escape the handler function. - if (!error) { - return; - } + error = this.error(); + + // In the rare case when `error()` does not return an error object, + // defensively escape the handler function. + if (!error) { + return; + } - error = videojs.mergeOptions(error, settings.errors[error.code || 0]); + error = videojs.mergeOptions(error, settings.errors[error.code || 0]); - if (error.message) { - details = '
' + this.localize('Technical details') + - ':
' + this.localize(error.message) + '
' + + if (error.message) { + details = '
' + this.localize('Technical details') + + ':
' + this.localize(error.message) + '
' + + '
'; + } + + display = this.errorDisplay; + + display.el().innerHTML = + '
' + + '' + + '
' + + '

' + this.localize(error.headline) + '

' + + '
' + this.localize('Error Code') + ': ' + (error.type || error.code) + '
' + + this.localize(details) + + '
' + + '
' + + '' + + '
' + '
'; - } - display = this.errorDisplay; - - display.el().innerHTML = - '
' + - '' + - '
' + - '

' + this.localize(error.headline) + '

' + - '
' + this.localize('Error Code') + ': ' + (error.type || error.code) + '
' + - this.localize(details) + - '
' + - '
' + - '' + - '
' + - '
'; - - if (player.width() <= 600 || player.height() <= 250) { - display.addClass('vjs-xs'); - } + if (player.width() <= 600 || player.height() <= 250) { + display.addClass('vjs-xs'); + } - on(display.el().querySelector('.vjs-errors-close-button'), 'click', function() { - display.hide(); - }); - on(display.el().querySelector('.vjs-errors-ok-button'), 'click', function() { - display.hide(); + on(display.el().querySelector('.vjs-errors-close-button'), 'click', function() { + display.hide(); + }); + on(display.el().querySelector('.vjs-errors-ok-button'), 'click', function() { + display.hide(); + }); }); - }); - // Initialize custom error conditions - initCustomErrorConditions(this, settings); + // Initialize custom error conditions + initCustomErrorConditions(this, settings); + }); }); })();