generated from bitfocus/companion-module-template-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
67 lines (50 loc) · 1.38 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
const { Regex, InstanceBase, InstanceStatus, runEntrypoint } = require('@companion-module/base')
const UpgradeScripts = require('./src/upgrades')
const net = require('net')
const actions = require('./actions')
const configs = require('./configs')
const vars = require('./src/variables')
const sim = require('./src/simulator')
var enableDestroy = require('server-destroy')
var server = net.createServer(sim.Simulator.handleConnection)
enableDestroy(server)
var client = new net.Socket()
// TODO(Peter): Make the port configurable
var PORT = 6254
class SimonHydePiClockInstance extends InstanceBase {
constructor(internal) {
super(internal)
Object.assign(this, {
...actions,
...configs,
})
}
async init(config) {
this.configUpdated(config)
this.sim = sim
//exports.serverIsActive = true
try {
server.listen(PORT)
this.updateStatus(InstanceStatus.Ok)
} catch (error) {
this.log('error', 'Port is occupied. Are you running another instance of this module?')
}
}
async configUpdated(config) {
if (config) {
this.config = config
}
this.initActions(this)
}
async destroy() {
server.close()
// server.destroy()
//exports.serverIsActive = false
}
}
/*function discoverSimulatorServer(ip) {
return tcping.probe(ip, 9990, function (err, available) {
this.log('debug', available)
})
}*/
runEntrypoint(SimonHydePiClockInstance, UpgradeScripts)