@cldmv/node-android-tv-remote 1.5.5 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitattributes DELETED
@@ -1,8 +0,0 @@
1
- # Force LF endings for all relevant files
2
- *.js text eol=lf
3
- *.json text eol=lf
4
- *.xml text eol=lf
5
- *.html text eol=lf
6
- *.css text eol=lf
7
- *.md text eol=lf
8
- *.txt text eol=lf
package/.prettierrc DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "useTabs": true,
3
- "tabWidth": 2,
4
- "printWidth": 140,
5
- "trailingComma": "none",
6
- "quoteProps": "preserve",
7
- "overrides": [
8
- {
9
- "files": "*.xml",
10
- "options": {
11
- "printWidth": 300
12
- }
13
- }
14
- ]
15
- }
@@ -1,80 +0,0 @@
1
- # Keyboard Keys
2
-
3
- [Back to Main README](../README.md) | [Keycodes](./KEYCODES.md)
4
-
5
- ---
6
-
7
- ## Table of Contents
8
-
9
- - [Overview](#overview)
10
- - [Keyboard Key List](#keyboard-key-list)
11
- - [Supported Devices](#supported-devices)
12
-
13
- ---
14
-
15
- ## Overview
16
-
17
- The `keyboard.key` and `keyboard.key.shift` APIs provide programmatic access to all keyboard keys, including letters, numbers, and special characters. These keys can be sent as text (where supported) or as keycodes (fallback).
18
-
19
- - `keyboard.key.<key>()` — Sends the key as text if possible, otherwise as a keycode.
20
- - `keyboard.key.<key>.keycode()` — Always sends the key as a keycode.
21
- - `keyboard.key.shift.<key>()` — Sends the shifted version (e.g., uppercase letter or symbol).
22
- - `keyboard.key.shift.<key>.keycode()` — Shifted key as keycode only.
23
-
24
- ## Keyboard Key List
25
-
26
- | Key Name | Description | Example | Shifted Example | Notes |
27
- | -------- | -------------------- | ------------------ | ------------------------ | ----- |
28
- | a | Lowercase letter 'a' | `keyboard.key.a()` | `keyboard.key.shift.a()` | |
29
- | b | Lowercase letter 'b' | `keyboard.key.b()` | `keyboard.key.shift.b()` | |
30
- | c | Lowercase letter 'c' | `keyboard.key.c()` | `keyboard.key.shift.c()` | |
31
- | d | Lowercase letter 'd' | `keyboard.key.d()` | `keyboard.key.shift.d()` | |
32
- | e | Lowercase letter 'e' | `keyboard.key.e()` | `keyboard.key.shift.e()` | |
33
- | f | Lowercase letter 'f' | `keyboard.key.f()` | `keyboard.key.shift.f()` | |
34
- | g | Lowercase letter 'g' | `keyboard.key.g()` | `keyboard.key.shift.g()` | |
35
- | h | Lowercase letter 'h' | `keyboard.key.h()` | `keyboard.key.shift.h()` | |
36
- | i | Lowercase letter 'i' | `keyboard.key.i()` | `keyboard.key.shift.i()` | |
37
- | j | Lowercase letter 'j' | `keyboard.key.j()` | `keyboard.key.shift.j()` | |
38
- | k | Lowercase letter 'k' | `keyboard.key.k()` | `keyboard.key.shift.k()` | |
39
- | l | Lowercase letter 'l' | `keyboard.key.l()` | `keyboard.key.shift.l()` | |
40
- | m | Lowercase letter 'm' | `keyboard.key.m()` | `keyboard.key.shift.m()` | |
41
- | n | Lowercase letter 'n' | `keyboard.key.n()` | `keyboard.key.shift.n()` | |
42
- | o | Lowercase letter 'o' | `keyboard.key.o()` | `keyboard.key.shift.o()` | |
43
- | p | Lowercase letter 'p' | `keyboard.key.p()` | `keyboard.key.shift.p()` | |
44
- | q | Lowercase letter 'q' | `keyboard.key.q()` | `keyboard.key.shift.q()` | |
45
- | r | Lowercase letter 'r' | `keyboard.key.r()` | `keyboard.key.shift.r()` | |
46
- | s | Lowercase letter 's' | `keyboard.key.s()` | `keyboard.key.shift.s()` | |
47
- | t | Lowercase letter 't' | `keyboard.key.t()` | `keyboard.key.shift.t()` | |
48
- | u | Lowercase letter 'u' | `keyboard.key.u()` | `keyboard.key.shift.u()` | |
49
- | v | Lowercase letter 'v' | `keyboard.key.v()` | `keyboard.key.shift.v()` | |
50
- | w | Lowercase letter 'w' | `keyboard.key.w()` | `keyboard.key.shift.w()` | |
51
- | x | Lowercase letter 'x' | `keyboard.key.x()` | `keyboard.key.shift.x()` | |
52
- | y | Lowercase letter 'y' | `keyboard.key.y()` | `keyboard.key.shift.y()` | |
53
- | z | Lowercase letter 'z' | `keyboard.key.z()` | `keyboard.key.shift.z()` | |
54
- | 0 | Digit '0' | `keyboard.key.0()` | `keyboard.key.shift.0()` | |
55
- | 1 | Digit '1' | `keyboard.key.1()` | `keyboard.key.shift.1()` | |
56
- | 2 | Digit '2' | `keyboard.key.2()` | `keyboard.key.shift.2()` | |
57
- | 3 | Digit '3' | `keyboard.key.3()` | `keyboard.key.shift.3()` | |
58
- | 4 | Digit '4' | `keyboard.key.4()` | `keyboard.key.shift.4()` | |
59
- | 5 | Digit '5' | `keyboard.key.5()` | `keyboard.key.shift.5()` | |
60
- | 6 | Digit '6' | `keyboard.key.6()` | `keyboard.key.shift.6()` | |
61
- | 7 | Digit '7' | `keyboard.key.7()` | `keyboard.key.shift.7()` | |
62
- | 8 | Digit '8' | `keyboard.key.8()` | `keyboard.key.shift.8()` | |
63
- | 9 | Digit '9' | `keyboard.key.9()` | `keyboard.key.shift.9()` | |
64
-
65
- > All other keys are keycodes. See [Keycodes](./KEYCODES.md) for the full list.
66
-
67
- > **Note:** Not all Android TV devices support all keyboard keys as text input. Keycode fallback is used where possible.
68
-
69
- ## Supported Devices
70
-
71
- | Device | Keyboard Text Input | Keycode Fallback |
72
- | ------------------------ | ------------------- | ---------------- |
73
- | Fire TV Stick | Yes | Yes |
74
- | Chromecast w/ Google TV | Yes | Yes |
75
- | Nvidia Shield | Yes | Yes |
76
- | Roku (Android TV) | Partial | Yes |
77
- | Xiaomi Mi Box | Yes | Yes |
78
- | Sony Bravia (Android TV) | Yes | Yes |
79
-
80
- See [Keycodes](./KEYCODES.md) for the full set of keycodes available.
package/docs/KEYCODES.md DELETED
@@ -1,55 +0,0 @@
1
- # Keycodes
2
-
3
- [Back to Main README](../README.md) | [Keyboard Keys](./KEYBOARD_KEYS.md)
4
-
5
- ---
6
-
7
- ## Table of Contents
8
-
9
- - [Overview](#overview)
10
- - [Keycode List](#keycode-list)
11
- - [Supported Devices](#supported-devices)
12
-
13
- ---
14
-
15
- ## Overview
16
-
17
- The `press` API and `inputKeycode` method use Android keycodes to control the device. These keycodes map to physical or virtual buttons on Android TV remotes.
18
-
19
- - `press.<key>()` — Sends the corresponding keycode for the remote key.
20
- - `press.long.<key>()` — Sends a long-press for the remote key.
21
- - `inputKeycode(code)` — Sends a raw Android keycode.
22
-
23
- ## Keycode List
24
-
25
- | Key Name | Keycode | Description | On Native Remote? | Notes |
26
- | ---------- | ------- | ---------------------- | ----------------- | ---------------------- |
27
- | home | 3 | Home button | Yes (most) | |
28
- | back | 4 | Back button | Yes (most) | |
29
- | dpadUp | 19 | D-Pad Up | Yes | |
30
- | dpadDown | 20 | D-Pad Down | Yes | |
31
- | dpadLeft | 21 | D-Pad Left | Yes | |
32
- | dpadRight | 22 | D-Pad Right | Yes | |
33
- | dpadCenter | 23 | D-Pad Center/OK/Select | Yes | |
34
- | menu | 82 | Menu/Options | Some | |
35
- | playPause | 85 | Play/Pause | Yes (some) | |
36
- | volumeUp | 24 | Volume Up | Yes (some) | |
37
- | volumeDown | 25 | Volume Down | Yes (some) | |
38
- | volumeMute | 164 | Mute | Some | |
39
- | input | 178 | Input/Source | Some | |
40
- | ... | ... | ... | ... | See full keycodes.json |
41
-
42
- > **Note:** The full list of keycodes is available in [keycodes.json](../src/data/keycodes.json).
43
-
44
- ## Supported Devices
45
-
46
- | Device | Remote Key Support | Notes |
47
- | ------------------------ | ------------------ | ------------------------------------------- |
48
- | Fire TV Stick | Most keys | Home, Back, D-Pad, Play/Pause, Volume |
49
- | Chromecast w/ Google TV | Most keys | Home, Back, Assistant, D-Pad, Volume, Input |
50
- | Nvidia Shield | Most keys | Home, Back, D-Pad, Play/Pause, Volume |
51
- | Roku (Android TV) | Partial | Home, Back, D-Pad, Play/Pause |
52
- | Xiaomi Mi Box | Most keys | Home, Back, D-Pad, Volume |
53
- | Sony Bravia (Android TV) | Most keys | Home, Back, D-Pad, Volume, Input |
54
-
55
- See [Keyboard Keys](./KEYBOARD_KEYS.md) for keyboard input support.
package/eslint.config.mjs DELETED
@@ -1,45 +0,0 @@
1
- import js from "@eslint/js";
2
- import globals from "globals";
3
- import json from "@eslint/json";
4
- import markdown from "@eslint/markdown";
5
- import css from "@eslint/css";
6
- import { defineConfig } from "eslint/config";
7
-
8
- export default defineConfig([
9
- {
10
- files: ["**/*.{js,mjs,cjs}"],
11
- plugins: { js },
12
- extends: ["js/recommended"],
13
- rules: {
14
- "no-unused-vars": [
15
- "error",
16
- {
17
- "argsIgnorePattern": "^_$",
18
- "caughtErrorsIgnorePattern": "^_$",
19
- "destructuredArrayIgnorePattern": "^_$",
20
- "varsIgnorePattern": "^_$"
21
- }
22
- ]
23
- }
24
- },
25
- { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } },
26
- { files: ["**/*.{js,mjs,cjs}"], languageOptions: { globals: globals.node } },
27
- {
28
- files: ["**/test/**/*test.js"],
29
- languageOptions: {
30
- globals: {
31
- beforeAll: true,
32
- afterAll: true,
33
- describe: true,
34
- it: true,
35
- expect: true,
36
- test: true
37
- }
38
- }
39
- },
40
- { files: ["**/*.json"], plugins: { json }, language: "json/json", extends: ["json/recommended"] },
41
- { files: ["**/*.jsonc"], plugins: { json }, language: "json/jsonc", extends: ["json/recommended"] },
42
- { files: ["**/*.json5"], plugins: { json }, language: "json/json5", extends: ["json/recommended"] },
43
- { files: ["**/*.md"], plugins: { markdown }, language: "markdown/gfm", extends: ["markdown/recommended"] },
44
- { files: ["**/*.css"], plugins: { css }, language: "css/css", extends: ["css/recommended"] }
45
- ]);
File without changes
@@ -1,144 +0,0 @@
1
- /**
2
- * AndroidTVSetup class for configuring and managing Android TV devices via ADB.
3
- *
4
- * Usage:
5
- * const setup = new AndroidTVSetup({ ip, port, quiet });
6
- * await setup.connect();
7
- * await setup.setSettings();
8
- * await setup.ensureAwake();
9
- * await setup.disconnect();
10
- */
11
- const createRemote = require("../android-tv-remote");
12
-
13
- class AndroidTVSetup {
14
- /**
15
- * @param {Object} options
16
- * @param {string} options.ip - The IP address of the ADB device.
17
- * @param {number} [options.port=5555] - The port number for the ADB connection.
18
- * @param {boolean} [options.quiet=true] - Suppress log output except for results.
19
- */
20
- constructor({ ip, port = 5555, quiet = true }) {
21
- this.ip = ip;
22
- this.port = port;
23
- this.quiet = quiet;
24
- this.remote = createRemote({ ip, port, quiet });
25
- this.host = `${ip}:${port}`;
26
- }
27
-
28
- logWithTime(...args) {
29
- if (!this.quiet) {
30
- const now = new Date().toISOString();
31
- console.log(`[${now}]`, ...args);
32
- }
33
- }
34
- warnWithTime(...args) {
35
- if (!this.quiet) {
36
- const now = new Date().toISOString();
37
- console.warn(`[${now}]`, ...args);
38
- }
39
- }
40
- errorWithTime(...args) {
41
- const now = new Date().toISOString();
42
- console.error(`[${now}]`, ...args);
43
- }
44
-
45
- async connect() {
46
- await this.remote.connect();
47
- this.logWithTime(`Connected to ${this.host}`);
48
- }
49
-
50
- async disconnect() {
51
- try {
52
- await this.remote.disconnect();
53
- this.logWithTime("Disconnected cleanly");
54
- } catch (err) {
55
- if (err.message && err.message.includes("disconnected")) {
56
- this.warnWithTime("Warning: Device already disconnected before explicit disconnect call.");
57
- } else {
58
- this.errorWithTime("Error:", err.message || err);
59
- if (err.message && err.message.includes("device unauthorized")) {
60
- this.errorWithTime(
61
- "Your device is unauthorized. Please check your TV and accept the authorization dialog to allow this computer to connect via ADB."
62
- );
63
- }
64
- process.exit(1);
65
- }
66
- }
67
- }
68
-
69
- /**
70
- * Set all recommended settings for always-on display and max brightness.
71
- */
72
- async setSettings() {
73
- // Use the remote's handleSettings for all settings
74
- await this.remote.handleSettings("set", this.quiet);
75
- // svc power stayon true and brightness are not in handleSettings, so do them here
76
- await this.remote.connect();
77
- const cmds = ["settings put system screen_brightness_mode 0", "settings put system screen_brightness 255", "svc power stayon true"];
78
- for (const cmd of cmds) {
79
- (await this.remote.inputKeycode) ? Promise.resolve() : Promise.resolve(); // placeholder for future
80
- await this.remotePressShell(cmd);
81
- this.logWithTime(`Ran: ${cmd}`);
82
- }
83
- await this.remote.disconnect();
84
- }
85
-
86
- /**
87
- * Helper to run a shell command using the remote's ADB client.
88
- * @param {string} cmd
89
- * @returns {Promise<void>}
90
- */
91
- async remotePressShell(cmd) {
92
- // Use the internal client for shell commands
93
- if (this.remote && this.remote.inputKeycode) {
94
- // fallback: use adbkit directly if needed
95
- const adb = require("adbkit");
96
- const client = adb.createClient();
97
- await client.shell(this.host, cmd).then(adb.util.readAll);
98
- } else if (this.remote && this.remote.client) {
99
- await this.remote.client.shell(this.host, cmd).then(require("adbkit").util.readAll);
100
- }
101
- }
102
-
103
- /**
104
- * Ensures the device is awake and on the home screen.
105
- */
106
- async ensureAwake() {
107
- // Use the remote's ADB client for dumpsys power
108
- const adb = require("adbkit");
109
- const client = adb.createClient();
110
- const output = await client
111
- .shell(this.host, "dumpsys power")
112
- .then(adb.util.readAll)
113
- .then((b) => b.toString());
114
- const parsed = this.parsePowerState(output);
115
- this.logWithTime("\n--- Power State ---");
116
- this.logWithTime(`mIsPowered: ${parsed.mIsPowered}`);
117
- this.logWithTime(`mWakefulness: ${parsed.mWakefulness}`);
118
- this.logWithTime(`mDisplayReady: ${parsed.mDisplayReady}`);
119
- this.logWithTime("-------------------\n");
120
- // Use remote.inputKeycode for keyevents
121
- if (parsed.mIsPowered !== "true") await this.remote.inputKeycode(26);
122
- if (parsed.mWakefulness !== "Awake") await this.remote.inputKeycode(224);
123
- if (parsed.mDisplayReady !== "true") await this.remote.inputKeycode(26);
124
- await this.remote.inputKeycode(3); // HOME
125
- }
126
-
127
- /**
128
- * Parses the output of 'dumpsys power' to extract power, wake, and display state.
129
- * @param {string} output - The full output string from 'dumpsys power'.
130
- * @returns {{ mIsPowered: string, mWakefulness: string, mDisplayReady: string }}
131
- */
132
- parsePowerState(output) {
133
- const mIsPoweredMatch = output.match(/^\s*mIsPowered=([a-zA-Z0-9]+)/m);
134
- const mWakefulnessMatch = output.match(/^\s*mWakefulness=([a-zA-Z0-9]+)/m);
135
- const mDisplayReadyMatch = output.match(/^\s*mDisplayReady=([a-zA-Z0-9]+)/m);
136
- return {
137
- mIsPowered: mIsPoweredMatch ? mIsPoweredMatch[1] : "unknown",
138
- mWakefulness: mWakefulnessMatch ? mWakefulnessMatch[1] : "unknown",
139
- mDisplayReady: mDisplayReadyMatch ? mDisplayReadyMatch[1] : "unknown"
140
- };
141
- }
142
- }
143
-
144
- module.exports = AndroidTVSetup;