Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoJS 5 Compatibility #28

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 48 additions & 39 deletions dist/videojs-errors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! videojs-errors - v0.1.8 - 2015-05-05
/*! videojs-errors - v0.1.8 - 2015-11-17
* Copyright (c) 2015 Brightcove; Licensed Apache-2.0 */
(function(){
var
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -134,7 +134,6 @@

// Setup Custom Error Conditions
var initCustomErrorConditions = function(player, options) {
var stalledTimeout, playbackMonitor;

// PLAYER_ERR_TIMEOUT
monitorPlayback(player, options);
Expand All @@ -153,52 +152,62 @@
};

videojs.plugin('errors', function(options){

var
player = this,
// Merge the external and default settings
settings = videojs.util.mergeOptions(defaults, options);
settings = videojs.mergeOptions(defaults, options);

player.ready(function() {

// Add to the error dialog when an error occurs
this.on('error', function() {
var code, error, display, details = '';

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 = videojs.mergeOptions(error, settings.errors[error.code || 0]);

error = videojs.util.mergeOptions(this.error(), settings.errors[this.error().code || 0]);
if (error.message) {
details = '<div class="vjs-errors-details">' + this.localize('Technical details') +
': <div class="vjs-errors-message">' + this.localize(error.message) + '</div>' +
'</div>';
}

if (error.message) {
details = '<div class="vjs-errors-details">' + this.localize('Technical details') +
': <div class="vjs-errors-message">' + this.localize(error.message) + '</div>' +
display = this.errorDisplay;

display.el().innerHTML =
'<div class="vjs-errors-dialog">' +
'<button class="vjs-errors-close-button"></button>' +
'<div class="vjs-errors-content-container">' +
'<h2 class="vjs-errors-headline">' + this.localize(error.headline) + '</h2>' +
'<div><b>' + this.localize('Error Code') + '</b>: ' + (error.type || error.code) + '</div>' +
this.localize(details) +
'</div>' +
'<div class="vjs-errors-ok-button-container">' +
'<button class="vjs-errors-ok-button">' + this.localize('OK') + '</button>' +
'</div>' +
'</div>';
}

display = this.errorDisplay;

display.el().innerHTML =
'<div class="vjs-errors-dialog">' +
'<button class="vjs-errors-close-button"></button>' +
'<div class="vjs-errors-content-container">' +
'<h2 class="vjs-errors-headline">' + this.localize(error.headline) + '</h2>' +
'<div><b>' + this.localize('Error Code') + '</b>: ' + (error.type || error.code) + '</div>' +
this.localize(details) +
'</div>' +
'<div class="vjs-errors-ok-button-container">' +
'<button class="vjs-errors-ok-button">' + this.localize('OK') + '</button>' +
'</div>' +
'</div>';

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);
});
});
})();
4 changes: 2 additions & 2 deletions dist/videojs-errors.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "^4.12.5"
"video.js": "^5.2.1"
}
}
85 changes: 47 additions & 38 deletions src/videojs.errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -132,7 +132,6 @@

// Setup Custom Error Conditions
var initCustomErrorConditions = function(player, options) {
var stalledTimeout, playbackMonitor;

// PLAYER_ERR_TIMEOUT
monitorPlayback(player, options);
Expand All @@ -151,52 +150,62 @@
};

videojs.plugin('errors', function(options){

var
player = this,
// Merge the external and default settings
settings = videojs.util.mergeOptions(defaults, options);
settings = videojs.mergeOptions(defaults, options);

player.ready(function() {

// Add to the error dialog when an error occurs
this.on('error', function() {
var code, error, display, details = '';

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 = videojs.mergeOptions(error, settings.errors[error.code || 0]);

error = videojs.util.mergeOptions(this.error(), settings.errors[this.error().code || 0]);
if (error.message) {
details = '<div class="vjs-errors-details">' + this.localize('Technical details') +
': <div class="vjs-errors-message">' + this.localize(error.message) + '</div>' +
'</div>';
}

if (error.message) {
details = '<div class="vjs-errors-details">' + this.localize('Technical details') +
': <div class="vjs-errors-message">' + this.localize(error.message) + '</div>' +
display = this.errorDisplay;

display.el().innerHTML =
'<div class="vjs-errors-dialog">' +
'<button class="vjs-errors-close-button"></button>' +
'<div class="vjs-errors-content-container">' +
'<h2 class="vjs-errors-headline">' + this.localize(error.headline) + '</h2>' +
'<div><b>' + this.localize('Error Code') + '</b>: ' + (error.type || error.code) + '</div>' +
this.localize(details) +
'</div>' +
'<div class="vjs-errors-ok-button-container">' +
'<button class="vjs-errors-ok-button">' + this.localize('OK') + '</button>' +
'</div>' +
'</div>';
}

display = this.errorDisplay;

display.el().innerHTML =
'<div class="vjs-errors-dialog">' +
'<button class="vjs-errors-close-button"></button>' +
'<div class="vjs-errors-content-container">' +
'<h2 class="vjs-errors-headline">' + this.localize(error.headline) + '</h2>' +
'<div><b>' + this.localize('Error Code') + '</b>: ' + (error.type || error.code) + '</div>' +
this.localize(details) +
'</div>' +
'<div class="vjs-errors-ok-button-container">' +
'<button class="vjs-errors-ok-button">' + this.localize('OK') + '</button>' +
'</div>' +
'</div>';

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);
});
});
})();
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ok(true, 'everything is swell');
});
</script>
<script src="../node_modules/video.js/dist/video-js/video.js"></script>
<script src="../node_modules/video.js/dist/video.js"></script>
<script src="../src/videojs.errors.js"></script>
<script src="videojs-errors.test.js"></script>
</body>
Expand Down
16 changes: 10 additions & 6 deletions test/videojs-errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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();
}
});
Expand Down