Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

5 years ago
  1. 'use strict';
  2. self.addEventListener('push', function(event) {
  3. console.log('Received a push message', event);
  4. let title = 'Yay a message.';
  5. let body = 'We have received a push message.';
  6. let icon = '/images/icon-192x192.png';
  7. let tag = 'simple-push-demo-notification-tag';
  8. event.waitUntil(
  9. self.registration.showNotification(title, {
  10. body: body,
  11. icon: icon,
  12. tag: tag
  13. })
  14. );
  15. });
  16. self.addEventListener('notificationclick', function(event) {
  17. console.log('On notification click: ', event.notification.tag);
  18. // Android doesn’t close the notification when you click on it
  19. // See: http://crbug.com/463146
  20. event.notification.close();
  21. // This looks to see if the current is already open and
  22. // focuses if it is
  23. event.waitUntil(clients.matchAll({
  24. type: 'window'
  25. }).then(function(clientList) {
  26. for (var i = 0; i < clientList.length; i++) {
  27. var client = clientList[i];
  28. if (client.url === '/' && 'focus' in client) {
  29. return client.focus();
  30. }
  31. }
  32. if (clients.openWindow) {
  33. return clients.openWindow('/');
  34. }
  35. }));
  36. });