-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathserver.coffee
95 lines (80 loc) · 2.39 KB
/
server.coffee
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
express = require 'express'
app = express()
bodyParser = require 'body-parser'
ATEM = require 'applest-atem'
config = require './config.json'
switchers = []
for switcher in config.switchers
atem = new ATEM
atem.event.setMaxListeners(5)
atem.connect(switcher.addr, switcher.port)
switchers.push(atem)
app.use(bodyParser.json())
app.use('/', express.static(__dirname + '/public'))
app.get('/api/channels', (req, res) ->
res.send(JSON.stringify(config.channels))
)
app.get('/api/switchersState', (req, res) ->
res.send(JSON.stringify((atem.state for atem in switchers)))
)
app.get('/api/switchersStatePolling', (req, res) ->
for atem in switchers
atem.once('stateChanged', (err, state) ->
res.end(JSON.stringify((atem.state for atem in switchers)))
)
)
app.post('/api/changePreviewInput', (req, res) ->
device = req.body.device
input = req.body.input
switchers[device].changePreviewInput(input)
res.send('success')
)
app.post('/api/changeProgramInput', (req, res) ->
device = req.body.device
input = req.body.input
switchers[device].changeProgramInput(input)
res.send('success')
)
app.post('/api/autoTransition', (req, res) ->
device = req.body.device
switchers[device].autoTransition()
res.send('success')
)
app.post('/api/cutTransition', (req, res) ->
device = req.body.device
switchers[device].cutTransition()
res.send('success')
)
app.post('/api/changeTransitionPosition', (req, res) ->
device = req.body.device
position = req.body.position
switchers[device].changeTransitionPosition(position)
res.send('success')
)
app.post('/api/changeTransitionType', (req, res) ->
type = req.body.type
for switcher in switchers
switcher.changeTransitionType(type)
res.send('success')
)
app.post('/api/changeUpstreamKeyState', (req, res) ->
device = req.body.device
number = req.body.number
state = req.body.state
switchers[device].changeUpstreamKeyState(number, state)
res.send('success')
)
app.post('/api/changeUpstreamKeyNextBackground', (req, res) ->
device = req.body.device
state = req.body.state
switchers[device].changeUpstreamKeyNextBackground(state)
res.send('success')
)
app.post('/api/changeUpstreamKeyNextState', (req, res) ->
device = req.body.device
number = req.body.number
state = req.body.state
switchers[device].changeUpstreamKeyNextState(number, state)
res.send('success')
)
app.listen(8080)