generated from bitfocus/companion-module-template-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
89 lines (67 loc) · 1.87 KB
/
main.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
// Panasonic Lumix
const { InstanceBase, InstanceStatus, runEntrypoint } = require('@companion-module/base')
const upgrades = require('./src/upgrades')
const config = require('./src/config')
const actions = require('./src/actions')
const feedbacks = require('./src/feedbacks')
const variables = require('./src/variables')
const presets = require('./src/presets')
const api = require('./src/api')
const constants = require('./src/constants')
const icons = require('./src/icons')
class rundownInstance extends InstanceBase {
constructor(internal) {
super(internal)
// Assign the methods from the listed files to this class
Object.assign(this, {
...config,
...actions,
...feedbacks,
...variables,
...presets,
...api,
...constants,
...icons,
})
this.socket = null //used for socketio connection
this.serverTime = null //current server time
this.timeOffset = 0 //offset between server time and local time
this.DATA = {}
this.INTERVAL = null //used to update timers based on latest data from the server
}
async init(config) {
this.configUpdated(config)
}
// When module gets deleted
async destroy() {
try {
if (this.socket) {
//close the socket if open
this.socket.disconnect()
this.socket = null
}
this.serverTime = null
this.timeOffset = 0
this.DATA = {}
//clear the interval
clearInterval(this.INTERVAL)
this.log('debug', 'destroy')
} catch (error) {
this.log('error', 'destroy error:', error)
}
}
async configUpdated(config) {
this.config = config
if (this.config.advancedConfig == true) {
this.API_BASE_URL = this.config.apiBaseUrl
this.SOCKET_BASE_URL = this.config.socketBaseUrl
this.SOCKET_PATH = this.config.socketPath
}
this.initActions()
this.initFeedbacks()
this.initVariables()
this.initPresets()
this.initConnection()
}
}
runEntrypoint(rundownInstance, upgrades)