forked from mystiq/hydrogen-web
show notification when receiving push message
This commit is contained in:
parent
7b9904e423
commit
8fcf7f8c7f
1 changed files with 21 additions and 0 deletions
|
@ -185,6 +185,27 @@ self.addEventListener('message', (event) => {
|
|||
}
|
||||
});
|
||||
|
||||
self.addEventListener('push', event => {
|
||||
const n = event.data.json();
|
||||
console.log("got a push message", n);
|
||||
let sender = n.sender_display_name || n.sender;
|
||||
if (sender && n.event_id) {
|
||||
let label;
|
||||
if (n.room_name) {
|
||||
label = `${sender} wrote you in ${n.room_name}`;
|
||||
} else {
|
||||
label = `${sender} wrote you`;
|
||||
}
|
||||
let body = n.content?.body;
|
||||
self.registration.showNotification(label, {
|
||||
body,
|
||||
data: {
|
||||
sessionId: n.session_id,
|
||||
roomId: n.room_id,
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
async function closeSession(sessionId, requestingClientId) {
|
||||
const clients = await self.clients.matchAll();
|
||||
|
|
Loading…
Reference in a new issue