-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedbacks.js
46 lines (41 loc) · 1.35 KB
/
feedbacks.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
45
46
import { combineRgb } from '@companion-module/base'
export default async function (self) {
self.setFeedbackDefinitions({
syncer_state: {
name: 'Syncer State',
type: 'boolean',
defaultStyle: {
bgcolor: combineRgb(255, 0, 0),
color: combineRgb(0, 0, 0),
},
options: [
{
id: 'groupId',
type: 'textinput',
label: 'Remote Group ID',
required: true,
},
],
callback: async (feedback) => {
const res = await fetch(`https://syncer.live/control?groupId=${feedback.options.groupId}`)
const data = await res.json()
self.log('debug', `Received ${JSON.stringify(data)}`)
return data.show
},
subscribe: async (feedback, context) => {
const res = await fetch(`https://syncer.live/control?groupId=${feedback.options.groupId}`)
const data = await res.json()
self.log('debug', `Subscribing to ${data.recordId}, ${JSON.stringify(feedback)}`)
await self.pb.collection('groups').subscribe(data.recordId, ({ record }) => {
self.log('debug', `Received ${JSON.stringify(record)}`)
self.checkFeedbacksById(feedback.id)
})
},
unsubscribe: async (feedback, context) => {
const res = await fetch(`https://syncer.live/control?groupId=${feedback.options.groupId}`)
const data = await res.json()
await self.pb.collection('groups').unsubscribe(data.recordId)
},
},
})
}