-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (53 loc) · 1.69 KB
/
Copy pathindex.js
File metadata and controls
65 lines (53 loc) · 1.69 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
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
import dotenv from 'dotenv';
import {
AndroidRemote,
RemoteKeyCode,
RemoteDirection
} from "androidtv-remote";
import Readline from "readline";
import fs from "fs";
dotenv.config();
let line = Readline.createInterface({
input: process.stdin,
output: process.stdout
});
let host = process.env.ANDROID_TV_IP;
let options = {
pairing_port : 6467,
remote_port : 6466,
name : 'androidtv-remote',
cert: {},
}
// Check if certificate files exist and load them
if (fs.existsSync('cert.pem') && fs.existsSync('key.pem')) {
options.cert = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
}
let androidRemote = new AndroidRemote(host, options)
androidRemote.on('secret', () => {
line.question("Code : ", async (code) => {
androidRemote.sendCode(code);
});
});
androidRemote.on('powered', (powered) => {
console.debug("Powered : " + powered)
});
androidRemote.on('volume', (volume) => {
console.debug("Volume : " + volume.level + '/' + volume.maximum + " | Muted : " + volume.muted);
});
androidRemote.on('current_app', (current_app) => {
console.debug("Current App : " + current_app);
});
androidRemote.on('ready', async () => {
let cert = androidRemote.getCertificate();
// Store certificate in a file
fs.writeFileSync('cert.pem', cert.cert);
fs.writeFileSync('key.pem', cert.key);
// Send power toggle keycode
androidRemote.sendKey(RemoteKeyCode.KEYCODE_POWER, RemoteDirection.SHORT)
// Send HDMI 1 input keycode
androidRemote.sendAppLink("content://android.media.tv/passthrough/com.droidlogic.tvinput%2F.services.Hdmi1InputService%2FHW5")
});
let started = await androidRemote.start();