-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (37 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict'
const settings = require('standard-settings')
const { SpacebroClient } = require('spacebro-client')
const fetch = require('node-fetch')
const verbose = settings.get('verbose') || false
const events = settings.get('events')
const URL = settings.get('dmx-web-URL')
const client = new SpacebroClient({
host: settings.get('spacebro:host') || '127.0.0.1',
port: settings.get('spacebro:port') || 8888,
channelName: settings.get('spacebro:channelName') || '',
client: {
name: 'dmx-web-bro',
description: 'dmx-web forward tool'
},
verbose
})
events.forEach((event) => {
client.on(event.name, (datas) => {
if (!event.requiredData || Object.values(datas).includes(event.requiredData)) {
console.log(`sending "${event.name}"" event to ${URL}`)
if (event.delay) console.log(`waiting ${event.delay}s...`)
setTimeout(() => {
fetch(URL, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(event.datas)
}).then((res) => {
console.log(`"${event.name}" returned status ${res.status}`)
})
}, (event.delay || 0) * 1000)
}
})
})