forked from carherco/ow_ejercicios_awp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
notificacionesP.js
60 lines (51 loc) · 1.24 KB
/
notificacionesP.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
if (Notification.permission === 'granted') {
mostrarNotificacion();
}
if (Notification.permission !== 'denied') {
Notification.requestPermission().then( p => {
if(p === 'granted') mostrarNotificacion();
});
}
function mostrarNotificacion() {
self.registration.showNotification('Título de la notificación',{
body: 'Texto del notificación',
badge: '',
icon: '',
image: '',
tag: 'etiqueta',
renotify: false,
data: { },
requireInteraction: false,
actions: [{
action: 'identificador',
title: 'Action Title',
icon: 'path/icono'
}],
silent: false,
sound: '/path/to/adiofile',
vibrate: [200, 100, 200],
dir: 'ltr',
lang: 'es-ES',
timestamp: Date.now(),
});
self.addEventListener('notificationclick', evento => {
if(!evento.action){
console.log('El usuario hizo click en el body');
return;
}
switch(evento.action) {
case 'view':
//...
break;
case 'buy':
//...
break;
default:
console.warn(`${evento.action} clicked`);
break;
}
});
self.addEventListener('notificationclose', evento => {
console.log('El usuario ha cerrado la notificación con la x');
});
}