0.11.20 push w link

This commit is contained in:
SDE
2024-01-16 16:53:01 +03:00
parent 793d283d97
commit 87fbe7852c
9 changed files with 118 additions and 35 deletions

View File

@@ -7,12 +7,32 @@ self.addEventListener('push', function (event) {
const data = JSON.parse(eventInfo);
const head = data.head || 'New Notification 🕺🕺';
const body = data.body || 'This is default content. Your notification didn\'t have one 🙄🙄';
const icon = data.img || 'static/img/svg/Logo.svg';
let notificationOptions = {
body: body,
icon: icon,
};
if ('url' in data){
notificationOptions['data'] = { url: data.url };
notificationOptions['actions'] = [{action: "open_url", title: data.button_name}]
}
// Keep the service worker alive until the notification is created.
event.waitUntil(
self.registration.showNotification(head, {
body: body,
icon: 'static/img/svg/Logo.svg'
})
self.registration.showNotification(head, notificationOptions)
);
});
});
self.addEventListener('notificationclick', function(event) {
switch(event.action){
case 'open_url':
clients.openWindow(event.notification.data.url);
break;
case 'any_other_action':
clients.openWindow("https://www.example.com");
break;
}
}
, false);

View File

@@ -28,7 +28,7 @@
<script>
{#var user_id = {{ user.id }}#}
ws_url = `wss://{% get_ws_address %}/ws/socket-server/?user_id={{ user.id }}`;
ws_url = `ws://{% get_ws_address %}/ws/socket-server/?user_id={{ user.id }}`;
var chatSocket;
init_ws()
const beep = new Audio('/static/sounds/beep_2.mp3')