feat(pwa) add pwa specifics

This commit is contained in:
Tudor-Ovidiu Avram 2020-10-12 12:05:56 +03:00 committed by Saúl Ibarra Corretgé
parent 59caa0cf42
commit 0d7a730497
7 changed files with 197 additions and 0 deletions

View File

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

88
pwa-worker.js Normal file
View File

@ -0,0 +1,88 @@
/*
Copyright 2015, 2019, 2020 Google LLC. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const CACHE_NAME = 'offline';
// Customize this with a different URL if needed.
const OFFLINE_URL = 'static/offline.html';
self.addEventListener('install', event => {
event.waitUntil(
(async () => {
const cache = await caches.open(CACHE_NAME);
// Setting {cache: 'reload'} in the new request will ensure that the
// response isn't fulfilled from the HTTP cache; i.e., it will be from
// the network.
await cache.add(new Request(OFFLINE_URL, { cache: 'reload' }));
})()
);
// Force the waiting service worker to become the active service worker.
self.skipWaiting();
});
self.addEventListener('activate', event => {
event.waitUntil(
(async () => {
// Enable navigation preload if it's supported.
// See https://developers.google.com/web/updates/2017/02/navigation-preload
if ('navigationPreload' in self.registration) {
await self.registration.navigationPreload.enable();
}
})()
);
// Tell the active service worker to take control of the page immediately.
self.clients.claim();
});
self.addEventListener('fetch', event => {
// We only want to call event.respondWith() if this is a navigation request
// for an HTML page.
if (event.request.mode === 'navigate') {
event.respondWith((async () => {
try {
// First, try to use the navigation preload response if it's supported.
const preloadResponse = await event.preloadResponse;
if (preloadResponse) {
return preloadResponse;
}
// Always try the network first.
const networkResponse = await fetch(event.request);
return networkResponse;
} catch (error) {
// catch is only triggered if an exception is thrown, which is likely
// due to a network error.
// If fetch() returns a valid HTTP response with a response code in
// the 4xx or 5xx range, the catch() will NOT be called.
console.log('Fetch failed; returning offline page instead.', error);
const cache = await caches.open(CACHE_NAME);
const cachedResponse = await cache.match(OFFLINE_URL);
return cachedResponse;
}
})());
}
// If our if() condition is false, then this fetch handler won't intercept the
// request. If there are any other fetch handlers registered, they will get a
// chance to call event.respondWith(). If no fetch handlers call
// event.respondWith(), the request will be handled by the browser as if there
// were no service worker involvement.
});

64
static/offline.html Normal file
View File

@ -0,0 +1,64 @@
<html>
<head>
<head>
<!--#include virtual="head.html" -->
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--#include virtual="base.html" -->
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<!--#include virtual="title.html" -->
</head>
<style>
body,
.content {
display: flex;
}
.content {
align-items: center;
flex-direction: column;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: 400;
line-height: 19px;
margin: auto;
max-width: 376px;
text-align: center;
}
h4 {
font-size: 24px;
font-weight: 600;
line-height: 32px;
margin: 24px auto;
}
.icon {
background-color: #FDD13A;
border-radius: 50%;
box-sizing: border-box;
height: 56px;
padding: 16px;
width: 56px;
}
</style>
</head>
<body>
<div class="content">
<div class="icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
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"
fill="#131519" fill-opacity="0.87" />
</svg>
</div>
<h4>Connection error</h4>
Your device may be offline or our servers may be experiencing problems.
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

30
static/pwa/manifest.json Normal file
View File

@ -0,0 +1,30 @@
{
"android_package_name": "org.jitsi.meet",
"prefer_related_applications": true,
"related_applications": [
{
"id": "org.jitsi.meet",
"platform": "chromeos_play"
}
],
"short_name": "Jitsi Meet",
"name": "Jitsi Meet",
"icons": [
{
"src": "icons/icon192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "icons/icon512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": "/",
"background_color": "#2a3a4b",
"display": "standalone",
"scope": "/",
"theme_color": "#2a3a4b"
}

12
static/pwa/registrator.js Normal file
View File

@ -0,0 +1,12 @@
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker
.register('pwa-worker.js')
.then(reg => {
console.log('Service worker registered.', reg);
})
.catch(err => {
console.log(err);
});
});
}