-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
111 lines (104 loc) · 2.84 KB
/
service-worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
(() => {
const cacheName = 'queensbound-v101';
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(cacheName).then(function(cache) {
return (
cache.addAll([
'./',
'index.html',
'favicon.png',
'css/style.css',
'images/loader.gif',
'images/logo.jpeg',
'images/person.png',
'images/poem.png',
'js/app.js',
'js/queensbound.js',
'css/thirdparty/openlayers.css',
'js/thirdparty/openlayers.js'
])
&&
cache.addAll([
'audio/[ their spine ] by Joseph O. Legaspi.mp3',
'audio/7 to 46th Street_Bliss by KC Trommer.mp3',
'audio/A True Account of Talking to the 7 In Sunnyside by Paolo Javier.mp3',
'audio/All Possible Fates by Jared Harél.mp3',
'audio/Cornrows by Maria Lisella.mp3',
'audio/Hawthorne Court by Maria Terrone.mp3',
'audio/Here I Love You New York by Abeer Y. Hoque.mp3',
'audio/Industrial Design & Sunset by Safia Jama.mp3',
'audio/Kalpana Chawla Way by Malcolm Chang.mp3',
'audio/Liberty Ashes (Keep Rising) by Sherese Francis.mp3',
'audio/Matarose Tags G - Dragon on the 7 by Rosebud Ben-Oni.mp3',
'audio/Next Summer by Nicole Haroutunian.mp3',
'audio/Psalm of the Garden In the City by Catherine Fletcher.mp3',
'audio/Queens Communion by Vikas K. Menon.mp3',
'audio/The Odds of It by KC Trommer.mp3',
'audio/When They Come for Us on the 7 Train by Ananda Lima.mp3'
])
);
})
);
});
self.addEventListener('activate', (event) =>
(event.waitUntil(
caches.keys().then((cacheNames) =>
Promise.all(
cacheNames.map((key) =>
(key !== cacheName)
&&
caches.delete(key)
)
)
)
) || true)
&&
self.clients.claim()
);
self.addEventListener('fetch', async (e) =>
e.respondWith(
caches.match(
e.request,
{cacheName, cacheName, ignoreVary:true}
)
.then(async (response) =>
response
||
fetch(e.request)
.then(
async (response) =>
response.ok
?
response
:
((await ifMapRequestSendMessage(e)) || true)
&&
response
)
.catch(
async (error) => await ifMapRequestSendMessage(e)
)
)
)
);
async function ifMapRequestSendMessage(e) {
return (
(e.request.url.indexOf("openstreetmap") > -1)
&&
await tellClientMapFailedToLoad(e)
);
}
async function tellClientMapFailedToLoad(e) {
return (
await self.clients.matchAll().then((clients) =>
clients.forEach((client) =>
client.postMessage({
msg: "MapFailedToLoad",
url: e.request.url
})
)
)
);
}
})();