2020-12-28 20:43:03 +00:00
|
|
|
// Copyright Chris Josten 2020
|
|
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
|
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
|
|
// https://www.boost.org/LICENSE_1_0.txt)
|
2020-12-12 16:14:09 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|