1 | (function() |
||
2 | { |
||
3 | const fs = require('fs'); |
||
0 ignored issues
–
show
Backwards Compatibility
introduced
by
![]() |
|||
4 | const path = require('path'); |
||
0 ignored issues
–
show
|
|||
5 | const Listener = require('Listener'); |
||
0 ignored issues
–
show
|
|||
6 | |||
7 | //Where the presets are located |
||
8 | const presetDirectory = path.join(__dirname, '../../static/presets/'); |
||
0 ignored issues
–
show
|
|||
9 | |||
10 | class InputController |
||
0 ignored issues
–
show
|
|||
11 | { |
||
12 | constructor(name, deps) |
||
13 | { |
||
14 | deps.logger.debug('InputController plugin loaded'); |
||
15 | |||
16 | this.globalBus = deps.globalEventLoop; |
||
17 | this.cockpitBus = deps.cockpit; |
||
18 | |||
19 | this.presetPaths = []; |
||
20 | } |
||
21 | |||
22 | searchForExistingPresets( directoryIn ) |
||
23 | { |
||
24 | var self = this; |
||
25 | |||
26 | fs.readdir(directoryIn, (err, files) => { |
||
0 ignored issues
–
show
'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').
Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code. Further Reading: ![]() |
|||
27 | if (err) { |
||
28 | throw err; |
||
29 | } |
||
30 | files.forEach(file => { |
||
0 ignored issues
–
show
'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').
Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code. Further Reading: ![]() |
|||
31 | var filePath = directoryIn + file; |
||
32 | self.presetPaths.push(filePath); |
||
33 | }); |
||
34 | |||
35 | //Send to the client |
||
36 | var presetAccu = []; |
||
37 | for(var i = 0; i < self.presetPaths.length; ++i) |
||
38 | { |
||
39 | var presetObj = JSON.parse(fs.readFileSync(self.presetPaths[i]), 'utf8'); |
||
40 | presetAccu.push(presetObj); |
||
41 | } |
||
42 | self.cockpitBus.emit('plugin.inputConfigurator.existingPresets', presetAccu); |
||
43 | |||
44 | presetAccu = []; |
||
45 | self.presetPaths = []; |
||
46 | }) |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
47 | |||
48 | } |
||
49 | |||
50 | start() |
||
51 | { |
||
52 | this.searchForExistingPresets( presetDirectory ); |
||
53 | } |
||
54 | |||
55 | stop() |
||
56 | { |
||
57 | } |
||
58 | |||
59 | } |
||
60 | |||
61 | module.exports = function(name, deps) |
||
62 | { |
||
63 | return new InputController(name, deps); |
||
64 | }; |
||
65 | |||
66 | |||
67 | }()); |
||
68 |