]>
Commit | Line | Data |
---|---|---|
b9c5fcf0 BW |
1 | <template> |
2 | <div v-if="offline" class="offline-message"> | |
3 | <i class="far fa-dizzy"></i> | |
4 | <h1> | |
c701075d | 5 | You're offline friend. |
b9c5fcf0 BW |
6 | <span @click="checkOffline"> <i class="fas fa-redo-alt"></i></span> |
7 | </h1> | |
8 | </div> | |
9 | </template> | |
10 | ||
11 | <script> | |
12 | export default { | |
13 | name: "ConnectivityChecker", | |
14 | data: function () { | |
15 | return { | |
16 | offline: false, | |
17 | }; | |
18 | }, | |
19 | created: function () { | |
20 | let that = this; | |
21 | this.checkOffline(); | |
22 | ||
23 | document.addEventListener( | |
24 | "visibilitychange", | |
25 | function () { | |
26 | if (document.visibilityState == "visible") { | |
27 | that.checkOffline(); | |
28 | } | |
29 | }, | |
30 | false | |
31 | ); | |
32 | }, | |
33 | methods: { | |
34 | checkOffline: function () { | |
35 | let that = this; | |
36 | return fetch(window.location.href + "?alive", { | |
37 | method: "HEAD", | |
38 | cache: "no-store", | |
39 | }) | |
a5fe53be | 40 | .then(function (response) { |
41 | if (response.status >= 200 && response.status < 300) { | |
42 | that.offline = false; | |
43 | } else { | |
44 | that.offline = true; | |
45 | } | |
b9c5fcf0 BW |
46 | }) |
47 | .catch(function () { | |
48 | that.offline = true; | |
49 | }) | |
50 | .finally(function () { | |
ed8b17e0 | 51 | that.$emit("network-status-update", that.offline); |
b9c5fcf0 BW |
52 | }); |
53 | }, | |
54 | }, | |
55 | }; | |
56 | </script> |