-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
50 lines (46 loc) · 1.21 KB
/
sw.js
File metadata and controls
50 lines (46 loc) · 1.21 KB
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
// Service Worker for Audio Player PWA
const CACHE_NAME = 'audio-player-v1';
const urlsToCache = [
'./',
'./index.html',
'./main.js',
'./analyzeTrack.js',
'./style.css',
'./manifest.json'
];
// Install event - cache resources
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
// Fetch event - serve from cache when offline
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
// Return cached version or fetch from network
return response || fetch(event.request);
})
);
});
// Background sync for audio playback
self.addEventListener('sync', event => {
if (event.tag === 'audio-sync') {
event.waitUntil(
// Handle background audio sync
console.log('Background audio sync triggered')
);
}
});
// Handle background audio session
self.addEventListener('message', event => {
if (event.data && event.data.type === 'AUDIO_SESSION') {
// Handle audio session management
console.log('Audio session message received:', event.data);
}
});