Browse Source

feat(pwa) add pwa specifics

master
Tudor-Ovidiu Avram 3 years ago
parent
commit
0d7a730497

+ 3
- 0
index.html View File

@@ -8,6 +8,8 @@
8 8
 
9 9
     <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
10 10
     <link rel="stylesheet" href="css/all.css">
11
+    <link rel="manifest" href="static/pwa/manifest.json">
12
+
11 13
     <script>
12 14
         document.addEventListener('DOMContentLoaded', () => {
13 15
             if (!JitsiMeetJS.app) {
@@ -158,6 +160,7 @@
158 160
     <script><!--#include virtual="/logging_config.js" --></script>
159 161
     <script src="libs/lib-jitsi-meet.min.js?v=139"></script>
160 162
     <script src="libs/app.bundle.min.js?v=139"></script>
163
+    <script src="static/pwa/registrator.js" async></script>
161 164
     <!--#include virtual="title.html" -->
162 165
     <!--#include virtual="plugin.head.html" -->
163 166
     <!--#include virtual="static/welcomePageAdditionalContent.html" -->

+ 88
- 0
pwa-worker.js View File

@@ -0,0 +1,88 @@
1
+/*
2
+Copyright 2015, 2019, 2020 Google LLC. All Rights Reserved.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+*/
13
+
14
+const CACHE_NAME = 'offline';
15
+
16
+// Customize this with a different URL if needed.
17
+const OFFLINE_URL = 'static/offline.html';
18
+
19
+self.addEventListener('install', event => {
20
+    event.waitUntil(
21
+    (async () => {
22
+        const cache = await caches.open(CACHE_NAME);
23
+
24
+
25
+        // Setting {cache: 'reload'} in the new request will ensure that the
26
+        // response isn't fulfilled from the HTTP cache; i.e., it will be from
27
+        // the network.
28
+        await cache.add(new Request(OFFLINE_URL, { cache: 'reload' }));
29
+    })()
30
+    );
31
+
32
+    // Force the waiting service worker to become the active service worker.
33
+    self.skipWaiting();
34
+});
35
+
36
+self.addEventListener('activate', event => {
37
+    event.waitUntil(
38
+    (async () => {
39
+        // Enable navigation preload if it's supported.
40
+        // See https://developers.google.com/web/updates/2017/02/navigation-preload
41
+        if ('navigationPreload' in self.registration) {
42
+            await self.registration.navigationPreload.enable();
43
+        }
44
+    })()
45
+    );
46
+
47
+    // Tell the active service worker to take control of the page immediately.
48
+    self.clients.claim();
49
+});
50
+
51
+self.addEventListener('fetch', event => {
52
+    // We only want to call event.respondWith() if this is a navigation request
53
+    // for an HTML page.
54
+    if (event.request.mode === 'navigate') {
55
+        event.respondWith((async () => {
56
+            try {
57
+                // First, try to use the navigation preload response if it's supported.
58
+                const preloadResponse = await event.preloadResponse;
59
+
60
+                if (preloadResponse) {
61
+                    return preloadResponse;
62
+                }
63
+
64
+                // Always try the network first.
65
+                const networkResponse = await fetch(event.request);
66
+
67
+                return networkResponse;
68
+            } catch (error) {
69
+                // catch is only triggered if an exception is thrown, which is likely
70
+                // due to a network error.
71
+                // If fetch() returns a valid HTTP response with a response code in
72
+                // the 4xx or 5xx range, the catch() will NOT be called.
73
+                console.log('Fetch failed; returning offline page instead.', error);
74
+
75
+                const cache = await caches.open(CACHE_NAME);
76
+                const cachedResponse = await cache.match(OFFLINE_URL);
77
+
78
+                return cachedResponse;
79
+            }
80
+        })());
81
+    }
82
+
83
+    // If our if() condition is false, then this fetch handler won't intercept the
84
+    // request. If there are any other fetch handlers registered, they will get a
85
+    // chance to call event.respondWith(). If no fetch handlers call
86
+    // event.respondWith(), the request will be handled by the browser as if there
87
+    // were no service worker involvement.
88
+});

+ 64
- 0
static/offline.html View File

@@ -0,0 +1,64 @@
1
+<html>
2
+
3
+<head>
4
+  <head>
5
+    <!--#include virtual="head.html" -->
6
+    <meta charset="utf-8">
7
+    <meta http-equiv="content-type" content="text/html;charset=utf-8">
8
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
+    <!--#include virtual="base.html" -->
10
+
11
+    <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
12
+    <!--#include virtual="title.html" -->
13
+  </head>
14
+  <style>
15
+    body,
16
+    .content {
17
+      display: flex;
18
+    }
19
+
20
+    .content {
21
+      align-items: center;
22
+      flex-direction: column;
23
+      font-family: Arial, Helvetica, sans-serif;
24
+      font-size: 14px;
25
+      font-weight: 400;
26
+      line-height: 19px;
27
+      margin: auto;
28
+      max-width: 376px;
29
+      text-align: center;
30
+    }
31
+
32
+    h4 {
33
+      font-size: 24px;
34
+      font-weight: 600;
35
+      line-height: 32px;
36
+      margin: 24px auto;
37
+    }
38
+
39
+    .icon {
40
+      background-color: #FDD13A;
41
+      border-radius: 50%;
42
+      box-sizing: border-box;
43
+      height: 56px;
44
+      padding: 16px;
45
+      width: 56px;
46
+    }
47
+  </style>
48
+</head>
49
+
50
+<body>
51
+  <div class="content">
52
+    <div class="icon">
53
+      <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
54
+        <path fill-rule="evenodd" clip-rule="evenodd"
55
+          d="M21.8799 19.5904L12.8501 3.49284C12.7614 3.33481 12.6288 3.20474 12.4676 3.11782C11.9982 2.86467 11.4083 3.03257 11.1502 3.49284L2.1202 19.5904C2.04143 19.7309 2.00012 19.8885 2.00012 20.0488C2.00012 20.5741 2.43443 20.9999 2.97017 20.9999H21.0299C21.1934 20.9999 21.3542 20.9594 21.4974 20.8822C21.9668 20.629 22.138 20.0507 21.8799 19.5904ZM4.61072 19.0976L12 5.92477L19.3892 19.0976H4.61072ZM11.0302 16.2445C11.0302 15.7192 11.456 15.2934 11.9813 15.2934H12.0191C12.5444 15.2934 12.9702 15.7192 12.9702 16.2445C12.9702 16.7698 12.5444 17.1956 12.0191 17.1956H11.9813C11.456 17.1956 11.0302 16.7698 11.0302 16.2445ZM12.0002 10.5378C11.4645 10.5378 11.0302 10.9721 11.0302 11.5078V13.3722C11.0302 13.9079 11.4645 14.3422 12.0002 14.3422C12.5359 14.3422 12.9702 13.9079 12.9702 13.3722V11.5078C12.9702 10.9721 12.5359 10.5378 12.0002 10.5378Z"
56
+          fill="#131519" fill-opacity="0.87" />
57
+      </svg>
58
+    </div>
59
+    <h4>Connection error</h4>
60
+    Your device may be offline or our servers may be experiencing problems.
61
+  </div>
62
+</body>
63
+
64
+</html>

BIN
static/pwa/icons/icon192.png View File


BIN
static/pwa/icons/icon512.png View File


+ 30
- 0
static/pwa/manifest.json View File

@@ -0,0 +1,30 @@
1
+{
2
+  "android_package_name": "org.jitsi.meet",
3
+  "prefer_related_applications": true,
4
+  "related_applications": [
5
+    {
6
+      "id": "org.jitsi.meet",
7
+      "platform": "chromeos_play"
8
+    }
9
+  ],
10
+  "short_name": "Jitsi Meet",
11
+  "name": "Jitsi Meet",
12
+  "icons": [
13
+    {
14
+      "src": "icons/icon192.png",
15
+      "type": "image/png",
16
+      "sizes": "192x192"
17
+    },
18
+    {
19
+      "src": "icons/icon512.png",
20
+      "type": "image/png",
21
+      "sizes": "512x512"
22
+    }
23
+  ],
24
+  "start_url": "/",
25
+  "background_color": "#2a3a4b",
26
+  "display": "standalone",
27
+  "scope": "/",
28
+  "theme_color": "#2a3a4b"
29
+ }
30
+ 

+ 12
- 0
static/pwa/registrator.js View File

@@ -0,0 +1,12 @@
1
+if ('serviceWorker' in navigator) {
2
+    window.addEventListener('load', () => {
3
+        navigator.serviceWorker
4
+      .register('pwa-worker.js')
5
+      .then(reg => {
6
+          console.log('Service worker registered.', reg);
7
+      })
8
+      .catch(err => {
9
+          console.log(err);
10
+      });
11
+    });
12
+}

Loading…
Cancel
Save