-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_helper.js
37 lines (34 loc) · 1.13 KB
/
node_helper.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
const NodeHelper = require('node_helper')
const bodyParser = require('body-parser')
const Log = require('../../js/logger.js')
module.exports = NodeHelper.create({
start: function () {
this.expressApp.use(bodyParser.json())
this.expressApp.use(bodyParser.urlencoded({ extended: true }))
this.expressApp.get('/scenes/:action', (req, res) => {
const action = req?.params?.action || null
if (!action) {
res.status(400).send({ message: 'Invalid request'})
return
}
Log.log(`[SCENES] Received request: ${action}`)
switch (action) {
case 'next':
case 'prev':
case 'pause':
case 'resume':
case 'play':
this.sendSocketNotification('ACTION', { command: `SCENES_${action.toUpperCase()}` })
break
default:
this.sendSocketNotification('ACTION', { command: 'SCENES_PLAY', scene: action })
break
}
res.status(200).send({ status: 200 })
return
})
},
socketNotificationReceived: function (notification, payload) {
this.sendSocketNotification(notification, payload) // just for check
}
})