forked from jtangelder/denon-remote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·47 lines (37 loc) · 1.16 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
#! /usr/bin/env node
const colors = require('colors');
const Vorpal = require('vorpal');
const DenonClient = require('./lib/DenonClient');
const setupToolCommands = require('./lib/toolCommands');
const setupDenonCommands = require('./lib/denonCommands');
const denon = new DenonClient();
const cli = Vorpal();
denon.on('connect', ()=> {
const address = denon.socket.remoteAddress;
const port = denon.socket.remotePort;
cli.log(colors.green(`Successfully connected to ${address}:${port}`));
if (process.argv.length > 2) {
for (i = 2; i < process.argv.length; i++) {
cli.log(colors.blue('Sending command ' + process.argv[i]));
cli.execSync('command ' + process.argv[i]);
}
cli.log(colors.red('All commands sent... exiting'));
process.exit(0)
}
});
denon.on('error', err => {
cli.log(colors.red('Something went wrong'), err);
denon.end();
});
denon.on('close', ()=> {
cli.log(colors.red('Connection closed'));
});
denon.on('data', buffer => {
cli.log(colors.magenta(buffer.toString().trim()));
});
cli
.delimiter('denon$')
.show();
setupToolCommands(cli, denon);
setupDenonCommands(cli, denon);
cli.execSync('connect 192.168.1.204');