2020-04-06 22:47:58 +00:00
|
|
|
import { connect } from '../casparcg/client.mjs'
|
2018-06-26 18:35:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Event: 'settings.all'
|
|
|
|
*
|
|
|
|
* Request all settings in store
|
|
|
|
*/
|
|
|
|
export async function all(ctx) {
|
2020-04-06 22:47:58 +00:00
|
|
|
let data = ctx.db.get('settings').value()
|
2018-06-26 18:35:12 +00:00
|
|
|
|
|
|
|
ctx.socket.emit('settings.all', data)
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Event: 'settings.update'
|
|
|
|
*
|
|
|
|
* Update a single setting value
|
|
|
|
*
|
|
|
|
* @body {string} [name] - Name of the settings
|
|
|
|
* @body {string} [value] - Value of the settings
|
|
|
|
*/
|
|
|
|
export async function update(ctx, data) {
|
|
|
|
if (!data || data.name == null || data.value == null) {
|
|
|
|
ctx.log.warn(data, 'called settings update but no name or value specified, body was:')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-12-08 11:09:46 +00:00
|
|
|
await ctx.db.set('settings.' + data.name, data.value).write()
|
2018-06-26 18:35:12 +00:00
|
|
|
|
2020-12-08 11:09:46 +00:00
|
|
|
let output = ctx.db.get('settings').value()
|
2018-06-26 18:35:12 +00:00
|
|
|
ctx.io.emit('settings.all', output)
|
|
|
|
|
2020-12-08 11:09:46 +00:00
|
|
|
if (data.name.startsWith('caspar')) {
|
2018-06-26 18:35:12 +00:00
|
|
|
connect()
|
|
|
|
}
|
|
|
|
}
|