2016-04-10 08:37:05 +00:00
|
|
|
import _ from 'lodash'
|
|
|
|
|
2016-04-14 04:01:51 +00:00
|
|
|
export const active = { }
|
|
|
|
|
|
|
|
function getSocket(ctx, all) {
|
|
|
|
if (all === true) return ctx.io
|
|
|
|
return ctx.socket
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:37:05 +00:00
|
|
|
export function display(ctx, data) {
|
2016-04-14 04:01:51 +00:00
|
|
|
let compiled = _.template(data.graphic.settings.html)
|
|
|
|
let html = compiled(data.data)
|
2016-04-10 08:37:05 +00:00
|
|
|
|
2016-04-14 04:01:51 +00:00
|
|
|
let payload = {
|
|
|
|
graphic: data.graphic,
|
2016-04-10 08:37:05 +00:00
|
|
|
html,
|
2016-04-14 04:01:51 +00:00
|
|
|
css: data.graphic.settings.css,
|
|
|
|
data: data.data,
|
|
|
|
}
|
|
|
|
|
|
|
|
active[data.graphic.name] = payload
|
|
|
|
ctx.io.emit('client.display', payload)
|
|
|
|
|
|
|
|
list(ctx, true)
|
2016-04-10 08:37:05 +00:00
|
|
|
}
|
|
|
|
|
2016-04-14 04:01:51 +00:00
|
|
|
export function hide(ctx, data) {
|
|
|
|
delete active[data.name]
|
|
|
|
|
2016-04-10 08:37:05 +00:00
|
|
|
ctx.io.emit('client.hide', {
|
2016-04-14 04:01:51 +00:00
|
|
|
name: data.name,
|
2016-04-10 08:37:05 +00:00
|
|
|
})
|
2016-04-14 04:01:51 +00:00
|
|
|
|
|
|
|
list(ctx, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateDisplayText(item) {
|
|
|
|
if (item.graphic.engine === 'countdown') {
|
|
|
|
return `${item.data[item.graphic.settings.main]} - ${item.data.countdown}`
|
|
|
|
}
|
|
|
|
return item.data[item.graphic.settings.main]
|
|
|
|
}
|
|
|
|
|
|
|
|
export function list(ctx, all) {
|
|
|
|
let payload = Object.keys(active).map(key => ({
|
|
|
|
name: active[key].graphic.name,
|
|
|
|
display: generateDisplayText(active[key]),
|
|
|
|
}))
|
|
|
|
|
|
|
|
getSocket(ctx, all).emit('content.list', payload)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function reset(ctx) {
|
|
|
|
ctx.socket.emit('client.reset', _.values(active))
|
2016-04-10 08:37:05 +00:00
|
|
|
}
|