serviceWorker.js 712 B

12345678910111213141516171819202122232425
  1. /* eslint-disable no-restricted-globals */
  2. self.addEventListener('activate', event => {
  3. console.log('Owncast service worker activated', event);
  4. });
  5. self.addEventListener('install', event => {
  6. console.log('installing Owncast service worker...', event);
  7. });
  8. self.addEventListener('push', event => {
  9. const data = JSON.parse(event.data.text());
  10. const { title, body, icon, tag } = data;
  11. const options = {
  12. title: title || 'Live!',
  13. body: body || 'This live stream has started.',
  14. icon: icon || '/logo/external',
  15. tag,
  16. };
  17. event.waitUntil(self.registration.showNotification(options.title, options));
  18. });
  19. self.addEventListener('notificationclick', event => {
  20. clients.openWindow('/');
  21. });