Browse Source

Merge pull request #1197 from jitsi/reload_on_error

Reload when resource fails to load
master
Paweł Domas 9 years ago
parent
commit
b646e8d213
1 changed files with 83 additions and 2 deletions
  1. 83
    2
      index.html

+ 83
- 2
index.html View File

@@ -28,9 +28,90 @@
28 28
                 && criticalFiles.some(
29 29
                     function(file) { return fileRef.indexOf(file) !== -1 })) {
30 30
                 window.onload = function() {
31
+                    // The whole complex part below implements page reloads with
32
+                    // "exponential backoff". The retry attempt is passes as
33
+                    // "rCounter" query parameter
34
+                    var href = window.location.href;
35
+
36
+                    var retryMatch = href.match(/.+(\?|&)rCounter=(\d+)/);
37
+                    var retryCountStr = retryMatch ? retryMatch[2] : "0";
38
+                    var retryCount = Number.parseInt(retryCountStr);
39
+
40
+                    if (retryMatch == null) {
41
+                        var separator = href.indexOf("?") === -1 ? "?" : "&";
42
+                        var hashIdx = href.indexOf("#");
43
+
44
+                        if (hashIdx === -1) {
45
+                            href += separator + "rCounter=1";
46
+                        } else {
47
+                            var hashPart = href.substr(hashIdx);
48
+
49
+                            href = href.substr(0, hashIdx)
50
+                                + separator + "rCounter=1" + hashPart;
51
+                        }
52
+                    } else {
53
+                        var separator = retryMatch[1];
54
+
55
+                        href = href.replace(
56
+                            /(\?|&)rCounter=(\d+)/,
57
+                            separator + "rCounter=" + (retryCount + 1));
58
+                    }
59
+
60
+                    var delay = Math.pow(2, retryCount) * 2000;
61
+                    if (isNaN(delay) || delay < 2000 || delay > 60000)
62
+                        delay = 10000;
63
+
64
+                    var showMoreText = "show more";
65
+                    var showLessText = "show less";
66
+
31 67
                     document.body.innerHTML
32
-                        = "The application failed to load, missing file: "
33
-                            + fileRef;
68
+                        = "<div style='"
69
+                        + "position: absolute;top: 50%;left: 50%;"
70
+                        + "text-align: center;"
71
+                        + "font-size: medium;"
72
+                        + "font-weight: 400;"
73
+                        + "transform: translate(-50%, -50%)'>"
74
+                        + "Uh oh! We couldn't fully download everything we needed :(" // jshint ignore:line
75
+                        + "<br/> "
76
+                        + "We will try again shortly. In the mean time, check for problems with your Internet connection!" // jshint ignore:line
77
+                        + "<br/><br/> "
78
+                        + "<div id='moreInfo' style='"
79
+                        + "display: none;'>" + "Missing " + fileRef
80
+                        + "<br/><br/></div>"
81
+                        + "<a id='showMore' style='"
82
+                        + "text-decoration: underline;"
83
+                        + "font-size:small;"
84
+                        + "cursor: pointer'>" + showMoreText + "</a>"
85
+                        + "&nbsp;&nbsp;&nbsp;"
86
+                        + "<a href='" + href + "' style='"
87
+                        + "text-decoration: underline;"
88
+                        + "font-size:small;"
89
+                        + "'>reload now</a>"
90
+                        + "</div>";
91
+
92
+                    var showMoreElem = document.getElementById("showMore");
93
+                    showMoreElem.addEventListener('click', function () {
94
+                            var moreInfoElem
95
+                                    = document.getElementById("moreInfo");
96
+
97
+                            if (showMoreElem.innerHTML === showMoreText) {
98
+                                moreInfoElem.setAttribute(
99
+                                    "style",
100
+                                    "display: block;"
101
+                                    + "color:#FF991F;"
102
+                                    + "font-size:small;"
103
+                                    + "user-select:text;");
104
+                                showMoreElem.innerHTML = showLessText;
105
+                            }
106
+                            else {
107
+                                moreInfoElem.setAttribute(
108
+                                    "style", "display: none;");
109
+                                showMoreElem.innerHTML = showMoreText;
110
+                            }
111
+                        });
112
+
113
+                    window.setTimeout(
114
+                        function () { window.location.replace(href); }, delay);
34 115
                 };
35 116
                 window.removeEventListener(
36 117
                     'error', loadErrHandler, true /* capture phase */);

Loading…
Cancel
Save