mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 22:14:25 +01:00
* Format Javascript and CSS files with `prettier`: `prettier --write 'CTFd/themes/**/*'` * Format Python with `black`: `black CTFd` & `black tests` * Travis now uses xenial instead of trusty.
50 lines
894 B
JavaScript
50 lines
894 B
JavaScript
var wc = new WindowController();
|
|
|
|
var sound = new Howl({
|
|
src: [
|
|
script_root + "/themes/core/static/sounds/notification.webm",
|
|
script_root + "/themes/core/static/sounds/notification.mp3"
|
|
]
|
|
});
|
|
|
|
function connect() {
|
|
window.ctfEventSource = new EventSource(script_root + "/events");
|
|
|
|
window.ctfEventSource.addEventListener(
|
|
"notification",
|
|
function(event) {
|
|
var data = JSON.parse(event.data);
|
|
wc.broadcast("notification", data);
|
|
render(data);
|
|
},
|
|
false
|
|
);
|
|
}
|
|
|
|
function disconnect() {
|
|
if (window.ctfEventSource) {
|
|
window.ctfEventSource.close();
|
|
}
|
|
}
|
|
|
|
function render(data) {
|
|
ezal({
|
|
title: data.title,
|
|
body: data.content,
|
|
button: "Got it!"
|
|
});
|
|
sound.play();
|
|
}
|
|
|
|
wc.notification = function(data) {
|
|
render(data);
|
|
};
|
|
|
|
wc.masterDidChange = function() {
|
|
if (this.isMaster) {
|
|
connect();
|
|
} else {
|
|
disconnect();
|
|
}
|
|
};
|