-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
141 lines (129 loc) · 3.43 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
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
136
137
138
139
140
141
console.log('twitch.tv/kingslimtim');
const ioHook = require('iohook');
const fs = require('fs');
const SockJS = require('sockjs-client');
const binds = JSON.parse(fs.readFileSync(`${__dirname}/config.json`));
const sock = new SockJS('http://127.0.0.1:59650/api');
const pendingTransactions = [];
var currWindow;
sock.onopen = () => {
console.log('===> Connected Successfully to Streamlabs');
};
sock.onmessage = e => {
// Remove pending transaction.
if (pendingTransactions.length <= 0) return;
var transactionType = pendingTransactions.shift();
// Parse JSON Data
var response = JSON.parse(e.data);
if (transactionType.type === 'sceneRequest') {
if (response.result[0].name === undefined) {
console.log('Was unable to parse a result.');
return;
}
var foundScene = response.result.find(x => x.name === transactionType.sceneName);
if (foundScene === undefined) return;
console.log(`Transition to Scene: ${transactionType.sceneName}`);
sock.send(
JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'makeSceneActive',
params: {
resource: 'ScenesService',
args: [foundScene.id]
}
})
);
return;
}
};
function sendSceneRequest(nameOfScene) {
pendingTransactions.push({ type: 'sceneRequest', sceneName: nameOfScene });
sock.send(
JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getScenes',
params: {
resource: 'ScenesService'
}
})
);
}
ioHook.on("keypress", event => {
switch(event.keychar){
case 49:
var windowFound = binds.data.find(x => {
if (x.NumPad == 1) return x;
});
if (windowFound !== undefined) {
sendSceneRequest(windowFound.sceneSelect);
}
break;
case 50:
var windowFound = binds.data.find(x => {
if (x.NumPad == 2) return x;
});
if (windowFound !== undefined) {
sendSceneRequest(windowFound.sceneSelect);
}
break;
case 51:
var windowFound = binds.data.find(x => {
if (x.NumPad == 3) return x;
});
if (windowFound !== undefined) {
sendSceneRequest(windowFound.sceneSelect);
}
break;
case 52:
var windowFound = binds.data.find(x => {
if (x.NumPad == 4) return x;
});
if (windowFound !== undefined) {
sendSceneRequest(windowFound.sceneSelect);
}
break;
case 53:
var windowFound = binds.data.find(x => {
if (x.NumPad == 5) return x;
});
if (windowFound !== undefined) {
sendSceneRequest(windowFound.sceneSelect);
}
break;
case 54:
var windowFound = binds.data.find(x => {
if (x.NumPad == 6) return x;
});
if (windowFound !== undefined) {
sendSceneRequest(windowFound.sceneSelect);
}
break;
case 55:
var windowFound = binds.data.find(x => {
if (x.NumPad == 7) return x;
});
if (windowFound !== undefined) {
sendSceneRequest(windowFound.sceneSelect);
}
break;
case 56:
var windowFound = binds.data.find(x => {
if (x.NumPad == 8) return x;
});
if (windowFound !== undefined) {
sendSceneRequest(windowFound.sceneSelect);
}
break;
case 57:
var windowFound = binds.data.find(x => {
if (x.NumPad == 9) return x;
});
if (windowFound !== undefined) {
sendSceneRequest(windowFound.sceneSelect);
}
break;
}
});
ioHook.start();