-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe6-remote.js
147 lines (127 loc) · 3.92 KB
/
e6-remote.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
142
143
144
145
146
147
const winston = require('winston');
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, {timestamp: true});
const keypress = require('keypress');
keypress(process.stdin);
var lgtv = require("lgtv2")({
url: 'ws://' + process.argv[2] + ':3000'
});
function logOp(message) {
return () => {
Promise.resolve(winston.log('info', message));
};
}
function sleepOp(time) {
return sleep.bind(null, time);
}
function sleep(time) {
return new Promise(resolve => {
winston.log('info', 'Sleeping for ' + time + 'ms');
setTimeout(() => {
winston.log('info', 'Sleep complete');
resolve();
}, time);
});
}
function sendButtonOp(sock, button) {
return sendButton.bind(null, sock, button);
}
function sendButton(sock, button) {
return new Promise(resolve => {
winston.log('info', 'Sending ' + button);
sock.send('button', {name: button});
resolve();
});
};
function chanDownOp(sock) {
return sendChanDown.bind(null, sock);
}
function sendChanDown(sock) {
return new Promise(resolve => {
winston.log('info', 'Sending channel down');
lgtv.request('ssap://tv/channelDown');
resolve();
});
}
function interactive(sock) {
// listen for the "keypress" event
process.stdin.on('keypress', function (ch, key) {
winston.log('info', '"' + key.name + '" pressed');
if (key.ctrl && key.name === 'c') {
process.stdin.pause();
process.exit(0);
} else {
var button = key.name.toUpperCase();
if (button === 'RETURN') {
button = 'ENTER';
} else if (button === 'BACKSPACE' || button === 'ESCAPE') {
button = 'BACK';
}
if (button === 'S') {
openSettings(sock);
} else if (button === 'M') {
openMenu(sock);
} else {
sendButton(sock, button);
}
}
});
process.stdin.setRawMode(true);
process.stdin.resume();
}
function openMenu(sock) {
winston.log('info', 'Opening App menu');
return sendButton(sock, 'HOME')
}
function openSettings(sock) {
const pictureModeWait = 90;
winston.log('info', 'Opening settings');
lgtv.request('ssap://com.webos.applicationManager/launch', {id: 'com.webos.app.accessibility'});
console.log('\nSwitching to Picture settings menu');
sleep(2400)
.then(sendButtonOp(sock, 'DOWN'))
.then(sleepOp(1500))
.then(sendButtonOp(sock, 'RIGHT'))
.then(logOp('\nSwitching to Picture mode settings menu'))
.then(sleepOp(200))
.then(sendButtonOp(sock, 'ENTER'))
.then(logOp('\nSwitching to Expert Controls menu'))
.then(sleepOp(1500))
.then(chanDownOp())
.then(chanDownOp())
.then(sleepOp(80))
.then(sleepOp(pictureModeWait))
.then(sendButtonOp(sock, 'UP'))
.then(sleepOp(pictureModeWait))
.then(sendButtonOp(sock, 'UP'))
.then(sleepOp(pictureModeWait))
.then(sendButtonOp(sock, 'UP'))
.then(sleepOp(90))
.then(sendButtonOp(sock, 'ENTER'))
.then(logOp('\nSwitching to White Balance menu'))
.then(sleepOp(1300))
.then(sendButtonOp(sock, 'DOWN'))
.then(sleepOp(pictureModeWait))
.then(sendButtonOp(sock, 'DOWN'))
.then(sleepOp(pictureModeWait))
.then(sendButtonOp(sock, 'DOWN'))
.then(sleepOp(pictureModeWait))
.then(sendButtonOp(sock, 'DOWN'))
.then(sleepOp(pictureModeWait))
.then(sendButtonOp(sock, 'DOWN'))
.then(sleepOp(pictureModeWait))
.then(sendButtonOp(sock, 'DOWN'))
.then(sleepOp(90))
.then(sendButtonOp(sock, 'ENTER'));
}
lgtv.on('connect', function () {
winston.log('info', 'Connected');
lgtv.getSocket(
'ssap://com.webos.service.networkinput/getPointerInputSocket',
function(err, sock) {
if (!err) {
interactive(sock);
}
}
);
});