forked from FritzAndFriends/StreamDeckEmulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (79 loc) · 2.44 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
const config = require('./config');
const { fork } = require('child_process');
const colors = require('colors');
const rlSync = require('readline-sync');
const exec = require('child_process').execFile;
const path = require('path');
const os = require('os');
let manifest = require(path.join(config.executable.path, config.executable.manifest));
const pluginExe = os.platform == 'win32' ? config.executable.winexe : config.executable.osxexe;
const forked = fork('server.js');
console.log('<status>Web Socket Server Started....'.green);
console.log('Green Text denotes hardware action\nGreen Highlight denotes hardware messages sent\nCyan highlight denotes messages received from plugin\n');
// Registration Stuff
let info = {
'application': {
'language': 'en',
'platform': os.platform == 'win32' ? config.server.winplatform : config.server.osxplatform,
'version': '4.0.0'
},
'devices': [
{
'id': config.server.deviceId,
'size': {
'columns': 5,
'rows': 3
},
'type': 0
}
]
};
let registrationParams = ['-port', config.server.port, '-pluginUUID', manifest.Actions[0].UUID,'-registerEvent','registerEvent','-info', JSON.stringify(info)];
exec(pluginExe, registrationParams, { cwd: config.executable.path }, (err, data) => {
if(err){
console.log(`ERROR: ${err}`.red);
} else {
console.log(`DATA: ${data}`.green);
}
} );
// Type b at any time to send a KeyUp event to the plugin
promptUser();
function promptUser() {
var cmd = rlSync.question(`
Enter:
'kd' for keyDown
'ku' for keyUp
'wa' for willAppear
'wd' for willDisappear
'dc' for deviceDidConnect
'dd' for deviceDidDisconnect
To quit, press 'q'\n`);
switch(cmd) {
case 'kd':
forked.send('keyDown');
break;
case 'ku':
forked.send('keyUp');
break;
case 'wa':
forked.send('willAppear');
break;
case 'wd':
forked.send('willDisappear');
break;
case 'dc':
forked.send('deviceDidConnect');
break;
case 'dd':
forked.send('deviceDidDisconnect');
case 'q':
// Is this too much? Unnecessary? Over-achiever?
forked.disconnect();
forked.removeAllListeners();
forked.kill();
return;
default:
break;
}
promptUser();
}