-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·69 lines (63 loc) · 1.49 KB
/
app.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
#!/usr/bin/env node
const meow = require('meow');
const cli = meow(`
Usage
$ lgtv <input>
Options
--help Display help message
--setvolume Set your TV volume
--turnoff Turn off your TV
--message Display a toast message on your TV
Examples
$ lgtv --setvolume 35
$ lgtv --turnoff
$ lgtv --message "Hello World!"
`, {
flags: {
setvolume: {
type: 'int',
alias: 'sv'
},
turnoff: {
alias: 'to'
},
message: {
alias: 'm'
}
}
});
const action = Object.keys(cli.flags)[0];
console.log(action);
var lgtv = require('lgtv2')({
url: 'ws://lgwebostv:3000'
});
lgtv.on('error', function(err) {
console.log(err);
lgtv.disconnect();
});
lgtv.on('connect', function() {
console.log('connected to tv.');
switch (action) {
case 'sv':
case 'setvolume':
lgtv.request('ssap://audio/setVolume', { volume: parseInt(cli.flags.setvolume) });
console.log("Volume changed to " + cli.flags.setvolume);
lgtv.disconnect();
break;
case 'to':
case 'turnoff':
lgtv.request('ssap://system/turnOff', function(err, res) {
lgtv.disconnect();
});
break;
case 'm':
case 'message':
lgtv.request('ssap://system.notifications/createToast', {
message: cli.flags.message
});
break;
default:
console.log('No matching params provided');
lgtv.disconnect();
}
});