filo_caspar/app/client/index.js

49 lines
934 B
JavaScript
Raw Normal View History

2017-12-03 11:34:43 +00:00
var socket = require('../socket')
2016-04-10 08:37:05 +00:00
2016-04-14 04:01:51 +00:00
var engines = {
2017-12-03 11:34:43 +00:00
text: require('./text'),
countdown: require('./countdown'),
schedule: require('./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)
})