Files
CTFd/CTFd/themes/core/static/js/events.js
Kevin Chung 6833378c36 Format all the things (#991)
* 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.
2019-05-11 21:09:37 -04:00

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();
}
};