Socket
Socket
Sign inDemoInstall

videojs-errors

Package Overview
Dependencies
Maintainers
171
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

videojs-errors - npm Package Compare versions

Comparing version 4.3.2 to 4.4.0

12

CHANGELOG.md

@@ -0,1 +1,13 @@

<a name="4.4.0"></a>
# [4.4.0](https://github.com/brightcove/videojs-errors/compare/v4.3.2...v4.4.0) (2021-04-13)
### Features
* Add backgroundTimeout option ([#198](https://github.com/brightcove/videojs-errors/issues/198)) ([d8d9efc](https://github.com/brightcove/videojs-errors/commit/d8d9efc))
* allow turning off timeout by setting it to Infinity ([#204](https://github.com/brightcove/videojs-errors/issues/204)) ([b73f160](https://github.com/brightcove/videojs-errors/commit/b73f160)), closes [#134](https://github.com/brightcove/videojs-errors/issues/134)
### Chores
* don't run tests on version ([#205](https://github.com/brightcove/videojs-errors/issues/205)) ([c349883](https://github.com/brightcove/videojs-errors/commit/c349883))
<a name="4.3.2"></a>

@@ -2,0 +14,0 @@ ## [4.3.2](https://github.com/brightcove/videojs-errors/compare/v4.3.1...v4.3.2) (2020-03-13)

53

dist/videojs-errors.cjs.js

@@ -1,2 +0,2 @@

/*! @name videojs-errors @version 4.3.2 @license Apache-2.0 */
/*! @name videojs-errors @version 4.4.0 @license Apache-2.0 */
'use strict';

@@ -9,3 +9,3 @@

var version = "4.3.2";
var version = "4.4.0";

@@ -22,2 +22,3 @@ var FlashObj = videojs.getComponent('Flash');

timeout: 45 * 1000,
backgroundTimeout: 300 * 1000,
dismiss: defaultDismiss,

@@ -94,4 +95,9 @@ errors: {

var resetMonitor = function resetMonitor() {
// at this point the player has recovered
// clear out any existing player error now that playback has recovered
if (player.error() && player.error().code === -2) {
player.error(null);
}
player.clearTimeout(waiting);
player.clearTimeout(monitor);

@@ -101,2 +107,9 @@ if (isStalling) {

player.removeClass('vjs-waiting');
} // Disable timeouts in the background altogether according to the backgroundTimeout
// option, or if the player is muted, as browsers may throttle javascript timers to
// 1 minute in that case
if (document.visibilityState === 'hidden' && (options.backgroundTimeout === Infinity || player.muted()) || document.visibilityState === 'visible' && options.timeout === Infinity) {
return;
} // start the loading spinner if player has stalled

@@ -115,3 +128,2 @@

}, 1000);
player.clearTimeout(monitor);
monitor = player.setTimeout(function () {

@@ -128,8 +140,3 @@ // player already has an error

});
}, options.timeout); // clear out any existing player timeout
// playback has recovered
if (player.error() && player.error().code === -2) {
player.error(null);
}
}, document.visibilityState === 'hidden' ? options.backgroundTimeout : options.timeout);
}; // clear any previously registered listeners

@@ -197,3 +204,7 @@

}
});
}); // Restart timeout monitor when the document transitions between the
// foreground and background
player.off(document, 'visibilitychange', onPlayStartMonitor);
player.on(document, 'visibilitychange', onPlayStartMonitor);
};

@@ -219,4 +230,6 @@

return;
}
} // Stop restarting the monitor on visibilitychanges now that an error has occurred
player.off(document, 'visibilitychange', onPlayStartMonitor);
error = videojs.mergeOptions(error, options.errors[error.code || error.type || 0]);

@@ -267,2 +280,3 @@

player.off('play', onPlayStartMonitor);
player.off(document, 'visibilitychange', onPlayStartMonitor);
player.off('play', onPlayNoSource);

@@ -299,2 +313,17 @@ player.off('dispose', onDisposeHandler);

}
}; // Get / set backgroundTimeout value. Restart monitor if changed.
reInitPlugin.backgroundTimeout = function (timeout) {
if (typeof timeout === 'undefined') {
return options.backgroundTimeout;
}
if (timeout !== options.backgroundTimeout) {
options.backgroundTimeout = timeout;
if (!player.paused()) {
onPlayStartMonitor();
}
}
}; // no-op API

@@ -301,0 +330,0 @@ // TODO: remove in a major version

@@ -1,6 +0,6 @@

/*! @name videojs-errors @version 4.3.2 @license Apache-2.0 */
/*! @name videojs-errors @version 4.4.0 @license Apache-2.0 */
import videojs from 'video.js';
import document from 'global/document';
var version = "4.3.2";
var version = "4.4.0";

@@ -17,2 +17,3 @@ var FlashObj = videojs.getComponent('Flash');

timeout: 45 * 1000,
backgroundTimeout: 300 * 1000,
dismiss: defaultDismiss,

@@ -89,4 +90,9 @@ errors: {

var resetMonitor = function resetMonitor() {
// at this point the player has recovered
// clear out any existing player error now that playback has recovered
if (player.error() && player.error().code === -2) {
player.error(null);
}
player.clearTimeout(waiting);
player.clearTimeout(monitor);

@@ -96,2 +102,9 @@ if (isStalling) {

player.removeClass('vjs-waiting');
} // Disable timeouts in the background altogether according to the backgroundTimeout
// option, or if the player is muted, as browsers may throttle javascript timers to
// 1 minute in that case
if (document.visibilityState === 'hidden' && (options.backgroundTimeout === Infinity || player.muted()) || document.visibilityState === 'visible' && options.timeout === Infinity) {
return;
} // start the loading spinner if player has stalled

@@ -110,3 +123,2 @@

}, 1000);
player.clearTimeout(monitor);
monitor = player.setTimeout(function () {

@@ -123,8 +135,3 @@ // player already has an error

});
}, options.timeout); // clear out any existing player timeout
// playback has recovered
if (player.error() && player.error().code === -2) {
player.error(null);
}
}, document.visibilityState === 'hidden' ? options.backgroundTimeout : options.timeout);
}; // clear any previously registered listeners

@@ -192,3 +199,7 @@

}
});
}); // Restart timeout monitor when the document transitions between the
// foreground and background
player.off(document, 'visibilitychange', onPlayStartMonitor);
player.on(document, 'visibilitychange', onPlayStartMonitor);
};

@@ -214,4 +225,6 @@

return;
}
} // Stop restarting the monitor on visibilitychanges now that an error has occurred
player.off(document, 'visibilitychange', onPlayStartMonitor);
error = videojs.mergeOptions(error, options.errors[error.code || error.type || 0]);

@@ -262,2 +275,3 @@

player.off('play', onPlayStartMonitor);
player.off(document, 'visibilitychange', onPlayStartMonitor);
player.off('play', onPlayNoSource);

@@ -294,2 +308,17 @@ player.off('dispose', onDisposeHandler);

}
}; // Get / set backgroundTimeout value. Restart monitor if changed.
reInitPlugin.backgroundTimeout = function (timeout) {
if (typeof timeout === 'undefined') {
return options.backgroundTimeout;
}
if (timeout !== options.backgroundTimeout) {
options.backgroundTimeout = timeout;
if (!player.paused()) {
onPlayStartMonitor();
}
}
}; // no-op API

@@ -296,0 +325,0 @@ // TODO: remove in a major version

@@ -1,2 +0,2 @@

/*! @name videojs-errors @version 4.3.2 @license Apache-2.0 */
/*! @name videojs-errors @version 4.4.0 @license Apache-2.0 */
(function (global, factory) {

@@ -8,6 +8,6 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('video.js'), require('global/document')) :

videojs = videojs && videojs.hasOwnProperty('default') ? videojs['default'] : videojs;
document = document && document.hasOwnProperty('default') ? document['default'] : document;
videojs = videojs && Object.prototype.hasOwnProperty.call(videojs, 'default') ? videojs['default'] : videojs;
document = document && Object.prototype.hasOwnProperty.call(document, 'default') ? document['default'] : document;
var version = "4.3.2";
var version = "4.4.0";

@@ -24,2 +24,3 @@ var FlashObj = videojs.getComponent('Flash');

timeout: 45 * 1000,
backgroundTimeout: 300 * 1000,
dismiss: defaultDismiss,

@@ -96,4 +97,9 @@ errors: {

var resetMonitor = function resetMonitor() {
// at this point the player has recovered
// clear out any existing player error now that playback has recovered
if (player.error() && player.error().code === -2) {
player.error(null);
}
player.clearTimeout(waiting);
player.clearTimeout(monitor);

@@ -103,2 +109,9 @@ if (isStalling) {

player.removeClass('vjs-waiting');
} // Disable timeouts in the background altogether according to the backgroundTimeout
// option, or if the player is muted, as browsers may throttle javascript timers to
// 1 minute in that case
if (document.visibilityState === 'hidden' && (options.backgroundTimeout === Infinity || player.muted()) || document.visibilityState === 'visible' && options.timeout === Infinity) {
return;
} // start the loading spinner if player has stalled

@@ -117,3 +130,2 @@

}, 1000);
player.clearTimeout(monitor);
monitor = player.setTimeout(function () {

@@ -130,8 +142,3 @@ // player already has an error

});
}, options.timeout); // clear out any existing player timeout
// playback has recovered
if (player.error() && player.error().code === -2) {
player.error(null);
}
}, document.visibilityState === 'hidden' ? options.backgroundTimeout : options.timeout);
}; // clear any previously registered listeners

@@ -199,3 +206,7 @@

}
});
}); // Restart timeout monitor when the document transitions between the
// foreground and background
player.off(document, 'visibilitychange', onPlayStartMonitor);
player.on(document, 'visibilitychange', onPlayStartMonitor);
};

@@ -221,4 +232,6 @@

return;
}
} // Stop restarting the monitor on visibilitychanges now that an error has occurred
player.off(document, 'visibilitychange', onPlayStartMonitor);
error = videojs.mergeOptions(error, options.errors[error.code || error.type || 0]);

@@ -269,2 +282,3 @@

player.off('play', onPlayStartMonitor);
player.off(document, 'visibilitychange', onPlayStartMonitor);
player.off('play', onPlayNoSource);

@@ -301,2 +315,17 @@ player.off('dispose', onDisposeHandler);

}
}; // Get / set backgroundTimeout value. Restart monitor if changed.
reInitPlugin.backgroundTimeout = function (timeout) {
if (typeof timeout === 'undefined') {
return options.backgroundTimeout;
}
if (timeout !== options.backgroundTimeout) {
options.backgroundTimeout = timeout;
if (!player.paused()) {
onPlayStartMonitor();
}
}
}; // no-op API

@@ -303,0 +332,0 @@ // TODO: remove in a major version

@@ -1,2 +0,2 @@

/*! @name videojs-errors @version 4.3.2 @license Apache-2.0 */
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("video.js"),require("global/document")):"function"==typeof define&&define.amd?define(["video.js","global/document"],r):(e=e||self).videojsErrors=r(e.videojs,e.document)}(this,(function(e,r){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e,r=r&&r.hasOwnProperty("default")?r.default:r;var o=e.getComponent("Flash"),n=!e.browser.IS_IPHONE,i=e.registerPlugin||e.plugin,t={header:"",code:"",message:"",timeout:45e3,dismiss:n,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"},PLAYER_ERR_DOMAIN_RESTRICTED:{headline:"This video is restricted from playing on your current domain"},PLAYER_ERR_IP_RESTRICTED:{headline:"This video is restricted at your current IP address"},PLAYER_ERR_GEO_RESTRICTED:{headline:"This video is restricted from playing in your current geographic region"},FLASHLS_ERR_CROSS_DOMAIN:{headline:"The video could not be loaded: crossdomain access denied."}}},s=function n(i,s){var a,d,l,c=[],u=function(r){s.errors=e.mergeOptions(s.errors,r),Object.keys(s.errors).forEach((function(e){var r=s.errors[e];r.type||(r.type=e)}))};u();var f=function(){i.clearTimeout(d),l&&(l=!1,i.removeClass("vjs-waiting")),d=i.setTimeout((function(){i.error()||i.paused()||i.ended()||(l=!0,i.addClass("vjs-waiting"))}),1e3),i.clearTimeout(a),a=i.setTimeout((function(){i.error()||i.paused()||i.ended()||i.error({code:-2,type:"PLAYER_ERR_TIMEOUT"})}),s.timeout),i.error()&&-2===i.error().code&&i.error(null)},h=function(){for(var e;c.length;)e=c.shift(),i.off(e[0],e[1]);i.clearTimeout(a),i.clearTimeout(d)},p=function(){var e,r,o,n=0;h(),f(),e=["timeupdate","adtimeupdate"],r=function(){var e=i.currentTime();e!==n&&(n=e,f())},o=function(){if(!i.error()){var e=i.$(".vjs-tech");if(e&&"application/x-shockwave-flash"===e.type&&!e.vjs_getProperty)return void i.error({code:-2,type:"PLAYER_ERR_TIMEOUT"});if(i.paused())return f();if(i.ended())return f()}r.call(this)},i.on(e,o),c.push([e,o])},v=function(){i.currentSrc()||i.error({code:-1,type:"PLAYER_ERR_NO_SRC"})},E=function(){var n="",t=i.error(),a=r.createElement("div"),d="";if(t){if((t=e.mergeOptions(t,s.errors[t.code||t.type||0])).message&&(n='<div class="vjs-errors-details">'+i.localize("Technical details")+'\n : <div class="vjs-errors-message">'+i.localize(t.message)+"</div>\n </div>"),4===t.code&&o&&!o.isSupported())n+='<span class="vjs-errors-flashmessage">'+i.localize("If you are using an older browser please try upgrading or installing Flash.")+"</span>";var l=i.getChild("errorDisplay");if(a.className="vjs-errors-dialog",a.id="vjs-errors-dialog",d='<div class="vjs-errors-content-container">\n <h2 class="vjs-errors-headline">'+this.localize(t.headline)+'</h2>\n <div class="vjs-errors-code"><b>'+this.localize("Error Code")+":</b> "+(t.type||t.code)+"</div>\n "+n+"\n </div>",l.closeable(!("dismiss"in t)||t.dismiss)){d+='<div class="vjs-errors-ok-button-container">\n <button class="vjs-errors-ok-button">'+this.localize("OK")+"</button>\n </div>",a.innerHTML=d,l.fillWith(a),l.contentEl().firstChild.appendChild(l.getChild("closeButton").el());var c=l.el().querySelector(".vjs-errors-ok-button");i.on(c,"click",(function(){l.close()}))}else a.innerHTML=d,l.fillWith(a);(i.currentWidth()<=600||i.currentHeight()<=250)&&l.addClass("vjs-xs"),l.one("modalclose",(function(){return i.error(null)}))}},R=function e(){h(),i.removeClass("vjs-errors"),i.off("play",p),i.off("play",v),i.off("dispose",e),i.off(["aderror","error"],E)},m=function(r){R(),n(i,e.mergeOptions(t,r))};m.extend=function(e){return u(e)},m.getAll=function(){return e.mergeOptions(s.errors)},m.timeout=function(e){if(void 0===e)return s.timeout;e!==s.timeout&&(s.timeout=e,i.paused()||p())},m.disableProgress=function(){},i.on("play",p),i.on("play",v),i.on("dispose",R),i.on(["aderror","contenterror","error"],E),i.ready((function(){i.addClass("vjs-errors")})),i.paused()||p(),m.VERSION="4.3.2",i.errors=m},a=function(r){s(this,e.mergeOptions(t,r))};return["extend","getAll"].forEach((function(r){a[r]=function(){e.log.warn("The errors."+r+"() method is not available until the plugin has been initialized!")}})),a.VERSION="4.3.2",i("errors",a),a}));
/*! @name videojs-errors @version 4.4.0 @license Apache-2.0 */
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o(require("video.js"),require("global/document")):"function"==typeof define&&define.amd?define(["video.js","global/document"],o):(e=e||self).videojsErrors=o(e.videojs,e.document)}(this,(function(e,o){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,o=o&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o;var r=e.getComponent("Flash"),i=!e.browser.IS_IPHONE,t=e.registerPlugin||e.plugin,n={header:"",code:"",message:"",timeout:45e3,backgroundTimeout:3e5,dismiss:i,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"},PLAYER_ERR_DOMAIN_RESTRICTED:{headline:"This video is restricted from playing on your current domain"},PLAYER_ERR_IP_RESTRICTED:{headline:"This video is restricted at your current IP address"},PLAYER_ERR_GEO_RESTRICTED:{headline:"This video is restricted from playing in your current geographic region"},FLASHLS_ERR_CROSS_DOMAIN:{headline:"The video could not be loaded: crossdomain access denied."}}},s=function i(t,s){var a,d,l,c=[],u=function(o){s.errors=e.mergeOptions(s.errors,o),Object.keys(s.errors).forEach((function(e){var o=s.errors[e];o.type||(o.type=e)}))};u();var f=function(){t.error()&&-2===t.error().code&&t.error(null),t.clearTimeout(d),t.clearTimeout(a),l&&(l=!1,t.removeClass("vjs-waiting")),"hidden"===o.visibilityState&&(s.backgroundTimeout===1/0||t.muted())||"visible"===o.visibilityState&&s.timeout===1/0||(d=t.setTimeout((function(){t.error()||t.paused()||t.ended()||(l=!0,t.addClass("vjs-waiting"))}),1e3),a=t.setTimeout((function(){t.error()||t.paused()||t.ended()||t.error({code:-2,type:"PLAYER_ERR_TIMEOUT"})}),"hidden"===o.visibilityState?s.backgroundTimeout:s.timeout))},h=function(){for(var e;c.length;)e=c.shift(),t.off(e[0],e[1]);t.clearTimeout(a),t.clearTimeout(d)},p=function e(){var r,i,n,s=0;h(),f(),r=["timeupdate","adtimeupdate"],i=function(){var e=t.currentTime();e!==s&&(s=e,f())},n=function(){if(!t.error()){var e=t.$(".vjs-tech");if(e&&"application/x-shockwave-flash"===e.type&&!e.vjs_getProperty)return void t.error({code:-2,type:"PLAYER_ERR_TIMEOUT"});if(t.paused())return f();if(t.ended())return f()}i.call(this)},t.on(r,n),c.push([r,n]),t.off(o,"visibilitychange",e),t.on(o,"visibilitychange",e)},v=function(){t.currentSrc()||t.error({code:-1,type:"PLAYER_ERR_NO_SRC"})},m=function(){var i="",n=t.error(),a=o.createElement("div"),d="";if(n){if(t.off(o,"visibilitychange",p),(n=e.mergeOptions(n,s.errors[n.code||n.type||0])).message&&(i='<div class="vjs-errors-details">'+t.localize("Technical details")+'\n : <div class="vjs-errors-message">'+t.localize(n.message)+"</div>\n </div>"),4===n.code&&r&&!r.isSupported())i+='<span class="vjs-errors-flashmessage">'+t.localize("If you are using an older browser please try upgrading or installing Flash.")+"</span>";var l=t.getChild("errorDisplay");if(a.className="vjs-errors-dialog",a.id="vjs-errors-dialog",d='<div class="vjs-errors-content-container">\n <h2 class="vjs-errors-headline">'+this.localize(n.headline)+'</h2>\n <div class="vjs-errors-code"><b>'+this.localize("Error Code")+":</b> "+(n.type||n.code)+"</div>\n "+i+"\n </div>",l.closeable(!("dismiss"in n)||n.dismiss)){d+='<div class="vjs-errors-ok-button-container">\n <button class="vjs-errors-ok-button">'+this.localize("OK")+"</button>\n </div>",a.innerHTML=d,l.fillWith(a),l.contentEl().firstChild.appendChild(l.getChild("closeButton").el());var c=l.el().querySelector(".vjs-errors-ok-button");t.on(c,"click",(function(){l.close()}))}else a.innerHTML=d,l.fillWith(a);(t.currentWidth()<=600||t.currentHeight()<=250)&&l.addClass("vjs-xs"),l.one("modalclose",(function(){return t.error(null)}))}},E=function e(){h(),t.removeClass("vjs-errors"),t.off("play",p),t.off(o,"visibilitychange",p),t.off("play",v),t.off("dispose",e),t.off(["aderror","error"],m)},y=function(o){E(),i(t,e.mergeOptions(n,o))};y.extend=function(e){return u(e)},y.getAll=function(){return e.mergeOptions(s.errors)},y.timeout=function(e){if(void 0===e)return s.timeout;e!==s.timeout&&(s.timeout=e,t.paused()||p())},y.backgroundTimeout=function(e){if(void 0===e)return s.backgroundTimeout;e!==s.backgroundTimeout&&(s.backgroundTimeout=e,t.paused()||p())},y.disableProgress=function(){},t.on("play",p),t.on("play",v),t.on("dispose",E),t.on(["aderror","contenterror","error"],m),t.ready((function(){t.addClass("vjs-errors")})),t.paused()||p(),y.VERSION="4.4.0",t.errors=y},a=function(o){s(this,e.mergeOptions(n,o))};return["extend","getAll"].forEach((function(o){a[o]=function(){e.log.warn("The errors."+o+"() method is not available until the plugin has been initialized!")}})),a.VERSION="4.4.0",t("errors",a),a}));
{
"name": "videojs-errors",
"version": "4.3.2",
"version": "4.4.0",
"author": "Brightcove, Inc.",

@@ -41,3 +41,2 @@ "description": "A Video.js plugin for custom error reporting",

"update-changelog": "conventional-changelog -p videojs -i CHANGELOG.md -s",
"preversion": "npm test",
"version": "is-prerelease || npm run update-changelog && git add CHANGELOG.md",

@@ -44,0 +43,0 @@ "watch": "npm-run-all -p watch:*",

@@ -24,2 +24,3 @@ # videojs-errors

- [`timeout()`](#timeout)
- [`backgroundTimeout()`](#backgroundtimeout)
- [Known Issues](#known-issues)

@@ -176,6 +177,12 @@

Setting the timeout to `Infinity` will turn off this check.
If no argument is passed, the current timeout value is returned.
### `backgroundTimeout()`
This functions exactly like [timeout](#timeout) except the default value is 5 minutes.
## Known Issues
On iPhones, default errors are not dismissible. The video element intercepts all user interaction so error message dialogs miss the tap events. If your video is busted anyways, you may not be that upset about this.

@@ -17,2 +17,3 @@ import videojs from 'video.js';

timeout: 45 * 1000,
backgroundTimeout: 300 * 1000,
dismiss: defaultDismiss,

@@ -93,9 +94,25 @@ errors: {

const resetMonitor = function() {
// at this point the player has recovered
// clear out any existing player error now that playback has recovered
if (player.error() && player.error().code === -2) {
player.error(null);
}
player.clearTimeout(waiting);
player.clearTimeout(monitor);
if (isStalling) {
isStalling = false;
player.removeClass('vjs-waiting');
}
// Disable timeouts in the background altogether according to the backgroundTimeout
// option, or if the player is muted, as browsers may throttle javascript timers to
// 1 minute in that case
if ((document.visibilityState === 'hidden' &&
(options.backgroundTimeout === Infinity || player.muted())) ||
(document.visibilityState === 'visible' && options.timeout === Infinity)) {
return;
}
// start the loading spinner if player has stalled

@@ -113,3 +130,2 @@ waiting = player.setTimeout(function() {

player.clearTimeout(monitor);
monitor = player.setTimeout(function() {

@@ -126,9 +142,3 @@ // player already has an error

});
}, options.timeout);
// clear out any existing player timeout
// playback has recovered
if (player.error() && player.error().code === -2) {
player.error(null);
}
}, document.visibilityState === 'hidden' ? options.backgroundTimeout : options.timeout);
};

@@ -200,2 +210,7 @@

});
// Restart timeout monitor when the document transitions between the
// foreground and background
player.off(document, 'visibilitychange', onPlayStartMonitor);
player.on(document, 'visibilitychange', onPlayStartMonitor);
};

@@ -224,2 +239,5 @@

// Stop restarting the monitor on visibilitychanges now that an error has occurred
player.off(document, 'visibilitychange', onPlayStartMonitor);
error = videojs.mergeOptions(error, options.errors[error.code || error.type || 0]);

@@ -285,2 +303,3 @@

player.off('play', onPlayStartMonitor);
player.off(document, 'visibilitychange', onPlayStartMonitor);
player.off('play', onPlayNoSource);

@@ -312,2 +331,15 @@ player.off('dispose', onDisposeHandler);

// Get / set backgroundTimeout value. Restart monitor if changed.
reInitPlugin.backgroundTimeout = function(timeout) {
if (typeof timeout === 'undefined') {
return options.backgroundTimeout;
}
if (timeout !== options.backgroundTimeout) {
options.backgroundTimeout = timeout;
if (!player.paused()) {
onPlayStartMonitor();
}
}
};
// no-op API

@@ -314,0 +346,0 @@ // TODO: remove in a major version

@@ -6,2 +6,3 @@ import document from 'global/document';

import videojs from 'video.js';
import Events from 'video.js';

@@ -20,2 +21,8 @@ import plugin from '../src/plugin';

// Override document.visibilityState so we can set it in tests
Object.defineProperty(document, 'visibilityState', {
value: document.visibilityState,
writable: true
});
QUnit.test('the environment is sane', function(assert) {

@@ -50,2 +57,4 @@ assert.strictEqual(typeof Array.isArray, 'function', 'es5 exists');

this.originalVisibilityState_ = document.visibilityState;
// initialize the plugin with the default options

@@ -60,2 +69,4 @@ this.player.errors();

afterEach() {
document.visibilityState = this.originalVisibilityState_;
this.player.dispose();

@@ -147,2 +158,262 @@ this.clock.restore();

QUnit.test('timeout in background is 5 minutes by default if the document is hidden when playback starts', function(assert) {
let errors = 0;
this.player.on('error', function() {
errors++;
});
this.player.src(sources);
document.visibilityState = 'hidden';
// simulates case where player starts playing while already in a background
// tab (i.e. no 'visibilitychange' event is observed)
this.player.trigger('play');
this.clock.tick(1 * 1000);
assert.ok(
this.player.hasClass('vjs-waiting'),
'the plugin adds spinner class to the player after 1 sec of no progress'
);
this.clock.tick(44 * 1000);
assert.strictEqual(errors, 0, 'did not emit an error after default foreground 45sec timeout');
this.clock.tick(255 * 1000);
assert.strictEqual(errors, 1, 'emitted an error after 5 minutes');
assert.strictEqual(this.player.error().code, -2, 'error code is -2');
assert.strictEqual(this.player.error().type, 'PLAYER_ERR_TIMEOUT');
});
QUnit.test('timeout in background is 5 minutes by default if the document is hidden after playback starts', function(assert) {
let errors = 0;
this.player.on('error', function() {
errors++;
});
this.player.src(sources);
this.player.trigger('play');
this.clock.tick(1 * 1000);
assert.ok(
this.player.hasClass('vjs-waiting'),
'the plugin adds spinner class to the player after 1 sec of no progress'
);
// document becomes hidden
document.visibilityState = 'hidden';
Events.trigger(document, 'visibilitychange');
this.clock.tick(299 * 1000);
assert.strictEqual(errors, 0, 'did not emit an error in background after 4 min 59 sec');
this.clock.tick(1 * 1000);
assert.strictEqual(errors, 1, 'emitted an error after 5 minutes');
assert.strictEqual(this.player.error().code, -2, 'error code is -2');
assert.strictEqual(this.player.error().type, 'PLAYER_ERR_TIMEOUT');
});
QUnit.test('background timeout can be set with backgroundTimeout option', function(assert) {
let errors = 0;
// Init with custom option
this.player.errors({backgroundTimeout: 10 * 1000});
this.player.on('error', function() {
errors++;
});
this.player.src(sources);
this.player.trigger('play');
this.clock.tick(1 * 1000);
assert.ok(
this.player.hasClass('vjs-waiting'),
'the plugin adds spinner class to the player after 1 sec of no progress'
);
// document becomes hidden
document.visibilityState = 'hidden';
Events.trigger(document, 'visibilitychange');
this.clock.tick(9 * 1000);
assert.strictEqual(errors, 0, 'did not emit an error in background after 9 sec');
this.clock.tick(1 * 1000);
assert.strictEqual(errors, 1, 'emitted an error after 10 sec');
assert.strictEqual(this.player.error().code, -2, 'error code is -2');
assert.strictEqual(this.player.error().type, 'PLAYER_ERR_TIMEOUT');
});
QUnit.test('background timeout can be set/get via player.errors.backgroundTimeout()', function(assert) {
let errors = 0;
assert.strictEqual(this.player.errors.backgroundTimeout(), 300000, 'backgroundTimeout() returns default value');
this.player.errors.backgroundTimeout(20 * 1000);
assert.strictEqual(this.player.errors.backgroundTimeout(), 20000, 'backgroundTimeout() returns new value');
this.player.on('error', function() {
errors++;
});
this.player.src(sources);
this.player.trigger('play');
this.clock.tick(1 * 1000);
assert.ok(
this.player.hasClass('vjs-waiting'),
'the plugin adds spinner class to the player after 1 sec of no progress'
);
// document becomes hidden
document.visibilityState = 'hidden';
Events.trigger(document, 'visibilitychange');
this.clock.tick(19 * 1000);
assert.strictEqual(errors, 0, 'did not emit an error in background after 19 sec');
this.clock.tick(1 * 1000);
assert.strictEqual(errors, 1, 'emitted an error after 20 sec');
assert.strictEqual(this.player.error().code, -2, 'error code is -2');
assert.strictEqual(this.player.error().type, 'PLAYER_ERR_TIMEOUT');
});
QUnit.test('timeout is disabled in background if backgroundTimeout option === Infinity', function(assert) {
let errors = 0;
// Init with custom option
this.player.errors({backgroundTimeout: Infinity});
this.player.on('error', function() {
errors++;
});
this.player.src(sources);
this.player.trigger('play');
this.clock.tick(1 * 1000);
assert.ok(
this.player.hasClass('vjs-waiting'),
'the plugin adds spinner class to the player after 1 sec of no progress'
);
// document becomes hidden
document.visibilityState = 'hidden';
Events.trigger(document, 'visibilitychange');
this.clock.tick(300 * 1000);
assert.strictEqual(errors, 0, 'did not emit an error in background after 5 minutes');
this.clock.tick(300 * 1000);
assert.strictEqual(errors, 0, 'still did not emit an error in background after another 5 minutes');
});
QUnit.test('timeout is disabled in background if the player is muted', function(assert) {
let errors = 0;
this.player.on('error', function() {
errors++;
});
this.player.src(sources);
this.player.trigger('play');
this.clock.tick(1 * 1000);
assert.ok(
this.player.hasClass('vjs-waiting'),
'the plugin adds spinner class to the player after 1 sec of no progress'
);
this.player.muted(true);
// document becomes hidden
document.visibilityState = 'hidden';
Events.trigger(document, 'visibilitychange');
this.clock.tick(300 * 1000);
assert.strictEqual(errors, 0, 'did not emit an error in background after 5 minutes');
});
QUnit.test('timeout is disabled in foreground if timeout option === Infinity', function(assert) {
let errors = 0;
// Init with custom option
this.player.errors({timeout: Infinity});
this.player.on('error', function() {
errors++;
});
this.player.src(sources);
this.player.trigger('play');
this.clock.tick(1 * 1000);
assert.notOk(
this.player.hasClass('vjs-waiting'),
'the plugin does not have a spinner class because timeout is disabled'
);
// document is visible
document.visibilityState = 'visible';
this.clock.tick(45 * 1000);
assert.strictEqual(errors, 0, 'did not emit an error in background after 45 seconds');
this.clock.tick(45 * 1000);
assert.strictEqual(errors, 0, 'still did not emit an error in background after another 45 seconds');
});
QUnit.test('background/foreground timeout toggling is disabled after error has occurred', function(assert) {
let errors = 0;
this.player.on('error', function() {
errors++;
});
this.player.src(sources);
this.player.trigger('play');
this.clock.tick(45 * 1000);
assert.strictEqual(errors, 1, 'emitted an error');
assert.strictEqual(this.player.error().code, -2, 'error code is -2');
assert.strictEqual(this.player.error().type, 'PLAYER_ERR_TIMEOUT');
// document becomes hidden then visible
document.visibilityState = 'hidden';
Events.trigger(document, 'visibilitychange');
document.visibilityState = 'visible';
Events.trigger(document, 'visibilitychange');
this.clock.tick(1 * 1000);
// resetMonitor() will set player.error(null) when the 'visibilitychange' handler is
// triggered, so we should expect that *not* to happen if the handler has been removed
assert.strictEqual(errors, 1, 'still has one error');
assert.ok(this.player.error() !== null, 'error is not null after visibilitychange');
assert.strictEqual(this.player.error().code, -2, 'error code is -2');
});
QUnit.test('progress events are ignored during timeout', function(assert) {

@@ -149,0 +420,0 @@ let errors = 0;

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc