forked from FritzAndFriends/StreamDeckEmulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
135 lines (132 loc) · 4.7 KB
/
server.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const config = require('./config');
const colors = require('colors');
const path = require('path');
let manifest = require(path.join(config.executable.path, config.executable.manifest));
const WebSocket = require('ws');
const server = new WebSocket.Server({ port: config.server.port});
let _socket;
let _settings = {};
server.on('connection', (socket) => {
_socket = socket;
_socket.on('message',(msg)=> {
var evt = JSON.parse(msg);
console.log(msg.bgCyan.black);
switch(evt.event) {
case 'showOk':
console.log('*******OK ICON IS SHOWN\n'.green);
break;
case 'showAlert':
console.log('*******ALERT ICON IS DISPLAYED\n'.green);
break;
case 'registerEvent':
console.log(`********PLUGIN REGISTERED: uuid=${evt.uuid}\n`.green);
break;
case 'openUrl':
console.log(`********OPENING URL ${evt.payload.url}\n`.green)
break;
case 'setTitle':
console.log(`********TITLE SET: title: ${evt.payload.title} - Sending titleParametersDidChange event to plugin\n`.green)
var json = {
'action': manifest.Actions[0].UUID,
'event': 'titleParametersDidChange',
'context': '',
'device': config.server.deviceId,
'payload': {
'coordinates': {
'column': 3,
'row': 1
},
'settings': _settings,
'state': 0,
'title': '',
'titleParameters': {
'fontFamily': '',
'fontSize': 12,
'fontStyle': '',
'fontUnderline': false,
'showTitle': true,
'titleAlignment': 'bottom',
'titleColor': '#ffffff'
}
}
};
console.log(JSON.stringify(json).bgGreen.black);
_socket.send(JSON.stringify(json));
break;
case 'setSettings':
console.log(`********SETTINGS STORED: ${JSON.stringify(evt.payload)} *******\n`.green);
_settings = evt.payload;
break;
default:
console.log(`********UNKNOWN MESSAGE ${msg}\n`.red);
break;
}
});
});
// Message from index.js
process.on('message', (msg) => {
var json = {
'action': manifest.Actions[0].UUID,
'event': '',
'context': '',
'device': config.server.deviceId,
'payload': {
'settings': _settings,
'coordinates': {
'column': 3,
'row': 1
},
'state': 0,
'userDesiredState': 1,
'isInMultiAction': false
}
};
switch(msg) {
case 'keyDown':
json.event = 'keyDown';
console.log(JSON.stringify(json).bgGreen.black);
_socket.send(JSON.stringify(json));
break;
case 'keyUp':
json.event = 'keyUp';
console.log(JSON.stringify(json).bgGreen.black);
_socket.send(JSON.stringify(json));
break;
case 'willAppear':
json.event = 'willAppear';
console.log(JSON.stringify(json).bgGreen.black);
_socket.send(JSON.stringify(json));
break;
case 'willDisappear':
json.event = 'willDisappear';
console.log(JSON.stringify(json).bgGreen.black);
_socket.send(JSON.stringify(json));
break;
case 'deviceDidConnect':
let ddcJson = {
'event': 'deviceDidConnect',
'device': config.server.deviceId,
'deviceInfo': {
'type': 0,
'size': {
'columns': 5,
'rows': 3
}
},
};
console.log(JSON.stringify(ddcJson).bgGreen.black);
_socket.send(JSON.stringify(ddcJson));
break;
case 'deviceDidDisconnect':
let dddJson= {
'event': 'deviceDidDisconnect',
'device': config.server.deviceId
};
console.log(JSON.stringify(dddJson).bgGreen.black);
_socket.send(JSON.stringify(dddJson));
break;
default:
console.log(`\nUnknown Index message: ${msg}`.red);
break;
}
});