filo_caspar/app/client/index.js

45 lines
854 B
JavaScript
Raw Normal View History

var socket = require('../shared/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
}
function display(data) {
var exists = document.getElementById(data.graphic.name)
2016-04-10 08:37:05 +00:00
2018-06-26 18:35:12 +00:00
var engine = data.graphic.engine
2016-04-10 08:37:05 +00:00
if (exists) {
2018-06-26 18:35:12 +00:00
exists.innerHtml = data.html
exists.tag.innerHtml = data.css
2016-04-10 08:37:05 +00:00
2018-06-26 18:35:12 +00:00
engines[engine].update(data)
return
2016-04-14 04:01:51 +00:00
}
2016-04-10 08:37:05 +00:00
2016-04-14 04:01:51 +00:00
if (engines[engine]) {
2018-06-26 18:35:12 +00:00
engines[engine].init(data)
2016-04-14 04:01:51 +00:00
}
}
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) {
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)
})