filo_caspar/app/client.js

49 lines
960 B
JavaScript
Raw Normal View History

var socket = require('./socket')
2016-04-10 08:37:05 +00:00
2016-04-14 04:01:51 +00:00
var engines = {
text: require('./frontend/text'),
countdown: require('./frontend/countdown'),
2016-07-28 18:21:50 +00:00
schedule: require('./frontend/schedule'),
2016-04-14 04:01:51 +00:00
}
var current = []
function display(data) {
var exists = document.getElementById(data.graphic.name)
2016-04-10 08:37:05 +00:00
if (exists) {
exists.tag.remove()
exists.remove()
2016-04-14 04:01:51 +00:00
current.splice(current.indexOf(data.graphic.name), 1)
}
current.push(data.graphic.name)
2016-04-10 08:37:05 +00:00
2016-04-14 13:28:00 +00:00
var engine = data.graphic.engine
2016-04-10 08:37:05 +00:00
2016-04-14 04:01:51 +00:00
if (engines[engine]) {
engines[engine](data)
}
}
2016-04-10 08:37:05 +00:00
2016-04-14 04:01:51 +00:00
socket.on('client.display', display)
2016-04-10 08:37:05 +00:00
socket.on('client.hide', function (data) {
2016-04-14 04:01:51 +00:00
var exists = document.getElementById(data.name)
2016-04-10 08:37:05 +00:00
if (exists) {
2016-04-14 04:01:51 +00:00
current.splice(current.indexOf(data.name), 1)
2016-04-10 08:37:05 +00:00
exists.classList.remove('root-element-display')
window.setTimeout(function () {
2016-04-10 08:37:05 +00:00
exists.tag.remove()
exists.remove()
}, 1500)
}
})
2016-04-14 04:01:51 +00:00
socket.on('client.reset', function(data) {
data.forEach(display)
})