70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
|
var knop;
|
||
|
var bus;
|
||
|
|
||
|
function werkKnopBij(tekst, aan) {
|
||
|
knop.innerText = tekst;
|
||
|
knop.disabled = !aan;
|
||
|
}
|
||
|
|
||
|
function trommel() {
|
||
|
bus.send("trommel");
|
||
|
}
|
||
|
|
||
|
function aftellen(tijd) {
|
||
|
if (bus.readyState !== bus.OPEN) return;
|
||
|
werkKnopBij(v9n["knop.afkoelen"].replace("{seconden}", Math.ceil((tijd - Date.now()) / 1000)), false);
|
||
|
if (tijd - Date.now() > 0) {
|
||
|
window.setTimeout(function() { aftellen(tijd) }, 1000);
|
||
|
} else {
|
||
|
werkKnopBij(v9n["knop.activeer"], true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function verbind() {
|
||
|
werkKnopBij(v9n["knop.initialiseren"], false);
|
||
|
var bestemming =( window.location.protocol == "http:"
|
||
|
? "ws://" : "wss://") + window.location.hostname + ":" + window.location.port + "/arreslee";
|
||
|
bus = new WebSocket(bestemming);
|
||
|
bus.onopen = function() {
|
||
|
werkKnopBij(v9n["knop.initialiseren2"], false);
|
||
|
knop.removeEventListener("click", verbind);
|
||
|
knop.addEventListener("click", trommel);
|
||
|
}
|
||
|
bus.onmessage = function(bericht) {
|
||
|
var gegevens = JSON.parse(bericht.data);
|
||
|
if (gegevens.verbondenMetKerstman) {
|
||
|
var doelTijd = gegevens.trommelenVerbodenTot * 1000;
|
||
|
var tijdVerschil = Date.now() - doelTijd;
|
||
|
if (tijdVerschil > 0) {
|
||
|
werkKnopBij(v9n["knop.activeer"], true);
|
||
|
} else {
|
||
|
aftellen(doelTijd);
|
||
|
}
|
||
|
} else {
|
||
|
werkKnopBij(v9n["knop.initialiseren2"], false);
|
||
|
}
|
||
|
}
|
||
|
bus.onclose = function() {
|
||
|
werkKnopBij("Opnieuw verbinden", true);
|
||
|
knop.removeEventListener("click", trommel);
|
||
|
knop.addEventListener("click", verbind);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
window.addEventListener("load", function() {
|
||
|
knop = document.getElementById("knop");
|
||
|
verbind();
|
||
|
|
||
|
try {
|
||
|
snow.count = 100; // number of flakes
|
||
|
snow.delay = 20; // timer interval
|
||
|
snow.minSpeed = 0.2; // minimum movement/time slice
|
||
|
snow.maxSpeed = 2; // maximum movement/time slice
|
||
|
snow.wobble = 2;
|
||
|
snow.flutter = 0.1;
|
||
|
snow.start();
|
||
|
} catch(e) {
|
||
|
console.log(e);
|
||
|
}
|
||
|
});
|