perf: service worker lifecycle method (#21532)
Co-authored-by: Alex van Andel <me@alexvanandel.com>
This commit is contained in:
1 parent
71a5d8b261
commit
e5868837d5
2 files changed
+17
-12
No files matched your search
@@ -91,6 +91,11 @@ export function NotificationSoundHandler() {
|
||||
// Don't automatically initialize - wait for user interaction
|
||||
return () => {
|
||||
stopSound();
|
||||
if (audioContextRef.current && audioContextRef.current.state !== "closed") {
|
||||
audioContextRef.current.close();
|
||||
}
|
||||
audioContextRef.current = null;
|
||||
audioBufferRef.current = null;
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -25,18 +25,7 @@ self.addEventListener("push", async (event) => {
|
||||
});
|
||||
|
||||
existingNotifications.forEach((notification) => {
|
||||
const options = {
|
||||
body: notification.body,
|
||||
icon: notification.icon,
|
||||
badge: notification.badge,
|
||||
data: notification.data,
|
||||
silent: notification.silent,
|
||||
vibrate: notification.vibrate,
|
||||
requireInteraction: notification.requireInteraction,
|
||||
tag: notification.tag,
|
||||
};
|
||||
|
||||
self.registration.showNotification(notification.title, options);
|
||||
notification.close();
|
||||
});
|
||||
|
||||
// Special handling for instant meetings
|
||||
@@ -87,6 +76,8 @@ self.addEventListener("notificationclick", (event) => {
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
event.waitUntil(stopSound());
|
||||
}
|
||||
|
||||
if (!event.action) {
|
||||
@@ -111,4 +102,13 @@ self.addEventListener('install', (event) => {
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
console.log('Service Worker activated.');
|
||||
|
||||
event.waitUntil(
|
||||
(async () => {
|
||||
const notifications = await self.registration.getNotifications();
|
||||
notifications.forEach(notification => notification.close());
|
||||
|
||||
return self.clients.claim();
|
||||
})()
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user