-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
102 lines (84 loc) · 2.7 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
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
96
97
98
99
100
101
102
const { InstanceBase, InstanceStatus, runEntrypoint } = require('@companion-module/base')
const config = require('./src/config')
const variables = require('./src/variables')
const polling = require('./src/polling')
const actions = require('./src/actions')
const presets = require('./src/presets')
const feedbacks = require('./src/feedbacks')
const utils = require('./src/util')
const Helo = require('./src/Helo')
class HeloInstance extends InstanceBase {
constructor(internal) {
super(internal)
let self = this
// Assign the methods from the listed files to this class
Object.assign(self, {
...config,
...variables,
...polling,
...actions,
...presets,
...feedbacks,
...utils,
})
}
async init(config) {
let self = this
self.STATE = {
recorder_status_value: 0,
recorder_status: 'eRRSUninitialized',
stream_status_value: 0,
stream_status: 'eRRSUninitialized',
storage_media_available: 0,
beer_goggles: 'No Beer...',
NameCounter: 0,
RecordingProfileNames: Array.from(Array(10)).map((e, i) => `${i + 1}`),
StreamingProfileNames: Array.from(Array(10)).map((e, i) => `${i + 1}`),
LayoutNames: Array.from(Array(10)).map((e, i) => `Layout ${i + 1}`),
}
self.pollingInterval = undefined
self.config = config
// Update Variables
self.updateVariableDefinitions()
self.updateFeedbacks()
await self.configUpdated(config)
}
async configUpdated(config) {
let self = this
if (config) {
self.config = config
}
// Update the actions
self.updateActions() //build actions regardless of connection status
// Quickly check if certain config values are present and continue setup
if (self.config.host && self.config.port) {
self.updateStatus(InstanceStatus.Connecting, 'Config Updated')
// update our connection in case host has changed
self.connection = new Helo(self, self.config)
// Test to confirm connection
// Simply send a request to get the current media available
let result = await self.connection.sendRequest('action=get¶mid=eParamID_CurrentMediaAvailable')
if (result.status != 'success') {
self.log('error', 'Confirm connection Failure: ' + JSON.stringify(result))
self.updateStatus(InstanceStatus.ConnectionFailure, `Could not connect to Helo @ ${self.connection.baseUrl}`)
return
}
// Start polling for settings values
self.initPolling()
// Init the presets
self.presets()
self.updateStatus(InstanceStatus.Ok)
} else {
self.updateStatus(InstanceStatus.BadConfig, 'Missing required values')
}
}
async destroy() {
let self = this
// Cleanup polling
if (self.pollingInterval) {
clearInterval(self.pollingInterval)
}
self.log('debug', 'destroy')
}
}
runEntrypoint(HeloInstance, [])