2022-04-09 13:03:07 +03:00
|
|
|
createjs.Sound.registerSound("/assets/packages/static/openvk/audio/notify.mp3", "notification");
|
2021-10-15 23:05:27 +03:00
|
|
|
|
|
|
|
function __actualPlayNotifSound() {
|
|
|
|
createjs.Sound.play("notification");
|
|
|
|
}
|
|
|
|
|
|
|
|
window.playNotifSound = Function.noop;
|
|
|
|
|
|
|
|
async function setupNotificationListener() {
|
|
|
|
console.warn("Setting up notifications listener...");
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
let notif;
|
|
|
|
try {
|
|
|
|
notif = await API.Notifications.fetch();
|
|
|
|
} catch(rejection) {
|
|
|
|
if(rejection.message !== "Nothing to report") {
|
|
|
|
console.error(rejection);
|
2022-10-27 12:44:46 +03:00
|
|
|
return;
|
2021-10-15 23:05:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
console.info("No new notifications discovered... Redialing event broker");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
playNotifSound();
|
|
|
|
NewNotification(notif.title, notif.body, notif.ava, Function.noop, notif.priority * 6000);
|
|
|
|
console.info("New notification", notif);
|
|
|
|
|
|
|
|
API.Notifications.ack();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
setupNotificationListener();
|
|
|
|
|
|
|
|
u(document.body).on("click", () => window.playNotifSound = window.__actualPlayNotifSound);
|