-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (32 loc) · 1011 Bytes
/
index.js
File metadata and controls
38 lines (32 loc) · 1011 Bytes
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
const path = require('path');
const StreamDeck = require('elgato-stream-deck');
class ControlDeck {
constructor(buttonLayoutPath, options = {}) {
this.debug = !!options.debug;
this.streamDeck = new StreamDeck();
this.streamDeck.clearAllKeys();
const buttonDefinitions = require(path.resolve(
path.dirname(require.main.filename),
buttonLayoutPath
));
for (let key in buttonDefinitions) {
let button_id = parseInt(key.split('_')[1]);
this._initButton(button_id, buttonDefinitions[key]);
}
}
_initButton(buttonId, buttonData) {
console.log(`initiating button ${buttonId}`);
try {
let plugin = require(path.resolve(
path.dirname(require.main.filename),
'node_modules',
buttonData.plugin
));
new plugin(this.streamDeck, buttonId, buttonData.options);
} catch (error) {
console.log(`Couldn't initialize button ${buttonId}`);
console.log(error);
}
}
}
module.exports = ControlDeck;