-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
36 lines (31 loc) · 1.14 KB
/
test.js
File metadata and controls
36 lines (31 loc) · 1.14 KB
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
const SourceBridge = require('./sourceBridge');
const readline = require('readline');
const bridge = new SourceBridge();
bridge.on('connect', (gameName, method) => console.log('Connected to '+ (gameName||"a Compatible Source Game") +' using '+ method +'!'));
bridge.on('disconnect', () => {console.log('Disconnected!'); process.exit(0);});
bridge.connect().then(() => {
if (bridge.isConnected) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const promptCommand = () => {
rl.question('> ', async (command) => {
try {
await bridge.run(command);
if (['quit', 'exit'].includes(command.toLowerCase())) {
rl.close();
} else {
promptCommand();
}
} catch (err) {
console.error(err);
promptCommand();
}
});
};
promptCommand();
} else {
console.log('No compatible Source game connected.');
}
});