Merge pull request #1197 from jitsi/reload_on_error
Reload when resource fails to load
This commit is contained in:
commit
b646e8d213
85
index.html
85
index.html
|
@ -28,9 +28,90 @@
|
|||
&& criticalFiles.some(
|
||||
function(file) { return fileRef.indexOf(file) !== -1 })) {
|
||||
window.onload = function() {
|
||||
// The whole complex part below implements page reloads with
|
||||
// "exponential backoff". The retry attempt is passes as
|
||||
// "rCounter" query parameter
|
||||
var href = window.location.href;
|
||||
|
||||
var retryMatch = href.match(/.+(\?|&)rCounter=(\d+)/);
|
||||
var retryCountStr = retryMatch ? retryMatch[2] : "0";
|
||||
var retryCount = Number.parseInt(retryCountStr);
|
||||
|
||||
if (retryMatch == null) {
|
||||
var separator = href.indexOf("?") === -1 ? "?" : "&";
|
||||
var hashIdx = href.indexOf("#");
|
||||
|
||||
if (hashIdx === -1) {
|
||||
href += separator + "rCounter=1";
|
||||
} else {
|
||||
var hashPart = href.substr(hashIdx);
|
||||
|
||||
href = href.substr(0, hashIdx)
|
||||
+ separator + "rCounter=1" + hashPart;
|
||||
}
|
||||
} else {
|
||||
var separator = retryMatch[1];
|
||||
|
||||
href = href.replace(
|
||||
/(\?|&)rCounter=(\d+)/,
|
||||
separator + "rCounter=" + (retryCount + 1));
|
||||
}
|
||||
|
||||
var delay = Math.pow(2, retryCount) * 2000;
|
||||
if (isNaN(delay) || delay < 2000 || delay > 60000)
|
||||
delay = 10000;
|
||||
|
||||
var showMoreText = "show more";
|
||||
var showLessText = "show less";
|
||||
|
||||
document.body.innerHTML
|
||||
= "The application failed to load, missing file: "
|
||||
+ fileRef;
|
||||
= "<div style='"
|
||||
+ "position: absolute;top: 50%;left: 50%;"
|
||||
+ "text-align: center;"
|
||||
+ "font-size: medium;"
|
||||
+ "font-weight: 400;"
|
||||
+ "transform: translate(-50%, -50%)'>"
|
||||
+ "Uh oh! We couldn't fully download everything we needed :(" // jshint ignore:line
|
||||
+ "<br/> "
|
||||
+ "We will try again shortly. In the mean time, check for problems with your Internet connection!" // jshint ignore:line
|
||||
+ "<br/><br/> "
|
||||
+ "<div id='moreInfo' style='"
|
||||
+ "display: none;'>" + "Missing " + fileRef
|
||||
+ "<br/><br/></div>"
|
||||
+ "<a id='showMore' style='"
|
||||
+ "text-decoration: underline;"
|
||||
+ "font-size:small;"
|
||||
+ "cursor: pointer'>" + showMoreText + "</a>"
|
||||
+ " "
|
||||
+ "<a href='" + href + "' style='"
|
||||
+ "text-decoration: underline;"
|
||||
+ "font-size:small;"
|
||||
+ "'>reload now</a>"
|
||||
+ "</div>";
|
||||
|
||||
var showMoreElem = document.getElementById("showMore");
|
||||
showMoreElem.addEventListener('click', function () {
|
||||
var moreInfoElem
|
||||
= document.getElementById("moreInfo");
|
||||
|
||||
if (showMoreElem.innerHTML === showMoreText) {
|
||||
moreInfoElem.setAttribute(
|
||||
"style",
|
||||
"display: block;"
|
||||
+ "color:#FF991F;"
|
||||
+ "font-size:small;"
|
||||
+ "user-select:text;");
|
||||
showMoreElem.innerHTML = showLessText;
|
||||
}
|
||||
else {
|
||||
moreInfoElem.setAttribute(
|
||||
"style", "display: none;");
|
||||
showMoreElem.innerHTML = showMoreText;
|
||||
}
|
||||
});
|
||||
|
||||
window.setTimeout(
|
||||
function () { window.location.replace(href); }, delay);
|
||||
};
|
||||
window.removeEventListener(
|
||||
'error', loadErrHandler, true /* capture phase */);
|
||||
|
|
Loading…
Reference in New Issue