@cldmv/node-android-tv-remote 2.0.0 → 2.1.7

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
- ]);
@@ -1,291 +0,0 @@
1
- /**
2
- * @Project: @cldmv/node-android-tv-remote
3
- * @Filename: /src/lib/adb/setup.mjs
4
- * @Date: 2025-10-15 10:19:05 -07:00 (1760548745)
5
- * @Author: Nate Hyson <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Hyson <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2025-10-15 12:04:44 -07:00 (1760555084)
10
- * -----
11
- * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- /**
15
- * AndroidTVSetup class for configuring and managing Android TV devices via ADB.
16
- *
17
- * Usage:
18
- * const setup = new AndroidTVSetup({ ip, port, quiet });
19
- * await setup.connect();
20
- * await setup.setSettings();
21
- * await setup.ensureAwake();
22
- * await setup.disconnect();
23
- */
24
- import createRemote from "../android-tv-remote.mjs";
25
- import adbkit from "@devicefarmer/adbkit";
26
- import { EventEmitter } from "events";
27
-
28
- /**
29
- * Android keycodes mapping loaded from JSON file.
30
- * @internal
31
- * @type {Object.<string, number>}
32
- * @see https://developer.android.com/reference/android/view/KeyEvent
33
- */
34
- import keycodes from "../../data/keycodes.json" with { type: "json" };
35
-
36
- const Adb = adbkit.Adb;
37
-
38
- class AndroidTVSetup extends EventEmitter {
39
- /**
40
- * Create an AndroidTVSetup instance.
41
- * @param {Object} options - Configuration options.
42
- * @param {string} options.ip - Device IP address.
43
- * @param {number} [options.port=5555] - Device port.
44
- * @param {boolean} [options.quiet=false] - Suppress log output.
45
- */
46
- constructor(options = {}) {
47
- super();
48
- const { ip, port = 5555, quiet = false, autoConnect = true } = options;
49
- this.ip = ip;
50
- this.port = port;
51
- this.quiet = quiet;
52
- this.remote = createRemote({ ip, port, quiet, autoConnect });
53
- this.host = `${ip}:${port}`;
54
- }
55
-
56
- /**
57
- * Emit a log event with structured data.
58
- * @private
59
- * @param {string} level - Log level (info, warn, error, debug).
60
- * @param {string} message - Log message.
61
- * @param {string} [source] - Source of the log message.
62
- * @param {any} [data] - Additional data to include.
63
- */
64
- emitLog(level, message, source = "android-tv-setup", data = null) {
65
- if (!this.quiet || level === "error") {
66
- this.emit("log", {
67
- level,
68
- message,
69
- source,
70
- timestamp: new Date().toISOString(),
71
- ...(data && { data })
72
- });
73
- }
74
- }
75
-
76
- /**
77
- * Emit an error event with structured data.
78
- * @private
79
- * @param {Error} error - The error object.
80
- * @param {string} [source] - Source of the error.
81
- * @param {string} [message] - Additional error message.
82
- */
83
- emitError(error, source = "android-tv-setup", message = null) {
84
- this.emit("error", {
85
- error,
86
- source,
87
- message: message || error.message,
88
- timestamp: new Date().toISOString()
89
- });
90
- }
91
-
92
- async connect() {
93
- await this.remote.connect();
94
- this.emitLog("info", `Connected to ${this.host}`, "connect");
95
- }
96
-
97
- async disconnect() {
98
- try {
99
- await this.remote.disconnect();
100
- this.emitLog("info", "Disconnected cleanly", "disconnect");
101
- } catch (err) {
102
- if (err.message && err.message.includes("disconnected")) {
103
- this.emitLog("warn", "Device already disconnected before explicit disconnect call", "disconnect");
104
- } else {
105
- this.emitError(err, "disconnect");
106
- if (err.message && err.message.includes("device unauthorized")) {
107
- this.emitLog(
108
- "error",
109
- "Your device is unauthorized. Please check your TV and accept the authorization dialog to allow this computer to connect via ADB.",
110
- "disconnect"
111
- );
112
- }
113
- // Don't exit the process, just emit the error
114
- throw err;
115
- }
116
- }
117
- }
118
-
119
- /**
120
- * Set all recommended settings for always-on display and max brightness.
121
- */
122
- async setSettings() {
123
- // Use the remote's handleSettings for all settings
124
- await this.remote.handleSettings("set", this.quiet);
125
- // svc power stayon true and brightness are not in handleSettings, so do them here
126
- await this.remote.connect();
127
- const cmds = ["settings put system screen_brightness_mode 0", "settings put system screen_brightness 255", "svc power stayon true"];
128
- for (const cmd of cmds) {
129
- (await this.remote.inputKeycode) ? Promise.resolve() : Promise.resolve(); // placeholder for future
130
- await this.remotePressShell(cmd);
131
- this.emitLog("info", `Ran: ${cmd}`, "setSettings");
132
- }
133
- await this.remote.disconnect();
134
- }
135
-
136
- /**
137
- * Helper to run a shell command using the remote's ADB client.
138
- * @param {string} cmd
139
- * @returns {Promise<void>}
140
- */
141
- async remotePressShell(cmd) {
142
- // Use the internal client for shell commands
143
- if (this.remote && this.remote.inputKeycode) {
144
- // fallback: use @devicefarmer/adbkit directly if needed
145
- const client = Adb.createClient();
146
- const device = client.getDevice(this.host);
147
- await device.shell(cmd).then(Adb.util.readAll);
148
- } else if (this.remote && this.remote.client) {
149
- const device = this.remote.client.getDevice(this.host);
150
- await device.shell(cmd).then(Adb.util.readAll);
151
- }
152
- }
153
-
154
- /**
155
- * Ensures the device is awake and on the home screen.
156
- * Checks initial state, sends all necessary commands, then verifies final state.
157
- * Only reports errors for states that remain incorrect after all commands are sent.
158
- */
159
- async ensureAwake() {
160
- this.emitLog("info", "=== Starting ensureAwake sequence ===", "ensureAwake");
161
-
162
- // Helper function to get current power state
163
- const getCurrentPowerState = async () => {
164
- const client = Adb.createClient();
165
- const device = client.getDevice(this.host);
166
- const output = await device
167
- .shell("dumpsys power")
168
- .then(Adb.util.readAll)
169
- .then((b) => b.toString());
170
- return this.parsePowerState(output);
171
- };
172
-
173
- // Helper function to emit power state
174
- const emitPowerState = (parsed, context = "") => {
175
- const prefix = context ? `${context} - ` : "";
176
- this.emitLog("info", `${prefix}Power State:`, "ensureAwake");
177
- this.emitLog("info", ` mIsPowered: ${parsed.mIsPowered}`, "ensureAwake");
178
- this.emitLog("info", ` mWakefulness: ${parsed.mWakefulness}`, "ensureAwake");
179
- this.emitLog("info", ` mDisplayReady: ${parsed.mDisplayReady}`, "ensureAwake");
180
- };
181
-
182
- // Get initial state
183
- let powerState = await getCurrentPowerState();
184
- emitPowerState(powerState, "Initial");
185
-
186
- // Track what commands we need to send
187
- const commandsToSend = [];
188
-
189
- // Check what needs to be fixed
190
- if (powerState.mIsPowered !== "true") {
191
- this.emitLog("info", `Device not powered (${powerState.mIsPowered}), will send POWER keycode`, "ensureAwake");
192
- commandsToSend.push({ keycode: keycodes.power, reason: "power on device" });
193
- } else {
194
- this.emitLog("info", "✅ Device already powered", "ensureAwake");
195
- }
196
-
197
- if (powerState.mWakefulness !== "Awake") {
198
- this.emitLog("info", `Device not awake (${powerState.mWakefulness}), will send WAKEUP keycode`, "ensureAwake");
199
- commandsToSend.push({ keycode: keycodes.wakeup, reason: "wake device" });
200
- } else {
201
- this.emitLog("info", "✅ Device already awake", "ensureAwake");
202
- }
203
-
204
- if (powerState.mDisplayReady !== "true") {
205
- this.emitLog("info", `Display not ready (${powerState.mDisplayReady}), will send POWER keycode`, "ensureAwake");
206
- commandsToSend.push({ keycode: keycodes.power, reason: "ready display" });
207
- } else {
208
- this.emitLog("info", "✅ Display already ready", "ensureAwake");
209
- }
210
-
211
- // Always send HOME to ensure we're on home screen
212
- commandsToSend.push({ keycode: keycodes.home, reason: "ensure home screen" });
213
-
214
- // Execute all commands with delays between them
215
- if (commandsToSend.length > 0) {
216
- this.emitLog("info", `Sending ${commandsToSend.length} keycode(s)...`, "ensureAwake");
217
-
218
- for (let i = 0; i < commandsToSend.length; i++) {
219
- const cmd = commandsToSend[i];
220
- this.emitLog("info", `Sending keycode ${cmd.keycode} to ${cmd.reason}`, "ensureAwake");
221
- await this.remote.inputKeycode(cmd.keycode);
222
-
223
- // Add delay between commands (except after the last one)
224
- if (i < commandsToSend.length - 1) {
225
- await new Promise(resolve => setTimeout(resolve, 300));
226
- }
227
- }
228
-
229
- // Wait for commands to take effect
230
- this.emitLog("info", "Waiting for commands to take effect...", "ensureAwake");
231
- await new Promise(resolve => setTimeout(resolve, 800));
232
- }
233
-
234
- // Get final state and check results
235
- powerState = await getCurrentPowerState();
236
- emitPowerState(powerState, "Final");
237
-
238
- // Check final state and only report persistent issues
239
- const issues = [];
240
-
241
- if (powerState.mIsPowered !== "true") {
242
- issues.push(`Device still not powered: ${powerState.mIsPowered}`);
243
- }
244
-
245
- if (powerState.mWakefulness !== "Awake") {
246
- issues.push(`Device still not awake: ${powerState.mWakefulness}`);
247
- }
248
-
249
- if (powerState.mDisplayReady !== "true") {
250
- issues.push(`Display still not ready: ${powerState.mDisplayReady}`);
251
- }
252
-
253
- // Report results
254
- if (issues.length === 0) {
255
- this.emitLog("info", "🎉 ensureAwake completed successfully - device is fully ready", "ensureAwake");
256
- } else {
257
- // Log individual issues as warnings first
258
- issues.forEach(issue => {
259
- this.emitLog("warn", issue, "ensureAwake");
260
- });
261
-
262
- // Then emit a single error for the overall failure
263
- this.emitError(
264
- new Error(`ensureAwake failed with ${issues.length} persistent issue(s): ${issues.join(', ')}`),
265
- "ensureAwake",
266
- "Device not in expected final state after commands"
267
- );
268
- }
269
-
270
- this.emitLog("info", "=== ensureAwake sequence complete ===", "ensureAwake");
271
- return powerState;
272
- }
273
-
274
- /**
275
- * Parses the output of 'dumpsys power' to extract power, wake, and display state.
276
- * @param {string} output - The full output string from 'dumpsys power'.
277
- * @returns {{ mIsPowered: string, mWakefulness: string, mDisplayReady: string }}
278
- */
279
- parsePowerState(output) {
280
- const mIsPoweredMatch = output.match(/^\s*mIsPowered=([a-zA-Z0-9]+)/m);
281
- const mWakefulnessMatch = output.match(/^\s*mWakefulness=([a-zA-Z0-9]+)/m);
282
- const mDisplayReadyMatch = output.match(/^\s*mDisplayReady=([a-zA-Z0-9]+)/m);
283
- return {
284
- mIsPowered: mIsPoweredMatch ? mIsPoweredMatch[1] : "unknown",
285
- mWakefulness: mWakefulnessMatch ? mWakefulnessMatch[1] : "unknown",
286
- mDisplayReady: mDisplayReadyMatch ? mDisplayReadyMatch[1] : "unknown"
287
- };
288
- }
289
- }
290
-
291
- export default AndroidTVSetup;
@@ -1,87 +0,0 @@
1
- /**
2
- * @Project: @cldmv/node-android-tv-remote
3
- * @Filename: /test/android-tv-remote.test.mjs
4
- * @Date: 2025-10-15 10:19:05 -07:00 (1760548745)
5
- * @Author: Nate Hyson <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Hyson <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2025-10-15 10:57:20 -07:00 (1760551040)
10
- * -----
11
- * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- import Remote from "../src/lib/android-tv-remote.mjs";
15
-
16
- // Usage: Set ANDROID_TV_IP and ANDROID_TV_PORT env vars before running Jest
17
- const TEST_IP = process.env.ANDROID_TV_IP || "192.168.1.100";
18
- const TEST_PORT = process.env.ANDROID_TV_PORT ? parseInt(process.env.ANDROID_TV_PORT, 10) : 5555;
19
-
20
- /** @type {import('../src/lib/android-tv-remote').RemoteConfig} */
21
- const config = {
22
- ip: TEST_IP,
23
- port: TEST_PORT,
24
- quiet: true,
25
- autoConnect: true,
26
- autoDisconnect: true,
27
- disconnectTimeout: 5
28
- };
29
-
30
- const remote = Remote(config);
31
-
32
- describe("android-tv-remote", () => {
33
- jest.setTimeout(20000); // ADB/network can be slow
34
-
35
- test("should connect and disconnect without error (promise)", async () => {
36
- await remote.connect();
37
- await remote.disconnect();
38
- });
39
-
40
- test("should connect and disconnect without error (callback)", (done) => {
41
- remote.connect((err) => {
42
- expect(err).toBeFalsy();
43
- remote.disconnect((err2) => {
44
- expect(err2).toBeFalsy();
45
- done();
46
- });
47
- });
48
- });
49
-
50
- test("should send a keycode (HOME)", async () => {
51
- await remote.connect();
52
- await remote.inputKeycode(3); // 3 = KEYCODE_HOME
53
- await remote.disconnect();
54
- });
55
-
56
- test("should send text input", async () => {
57
- await remote.connect();
58
- await remote.keyboard.text("test");
59
- await remote.disconnect();
60
- });
61
-
62
- test("should call press.home()", async () => {
63
- await remote.connect();
64
- await remote.press.home();
65
- await remote.disconnect();
66
- });
67
-
68
- test("should call keyboard.key.a()", async () => {
69
- await remote.connect();
70
- await remote.keyboard.key.a();
71
- await remote.disconnect();
72
- });
73
-
74
- test("should call keyboard.key.shift.a()", async () => {
75
- await remote.connect();
76
- await remote.keyboard.key.shift.a();
77
- await remote.disconnect();
78
- });
79
-
80
- test("should handle settings get", async () => {
81
- await remote.handleSettings("get", true);
82
- });
83
-
84
- test("should handle settings set", async () => {
85
- await remote.handleSettings("set", true);
86
- });
87
- });
@@ -1,63 +0,0 @@
1
- /**
2
- * @Project: @cldmv/node-android-tv-remote
3
- * @Filename: /test/api-surface.test.mjs
4
- * @Date: 2025-10-15 10:19:05 -07:00 (1760548745)
5
- * @Author: Nate Hyson <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Hyson <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2025-10-15 10:56:52 -07:00 (1760551012)
10
- * -----
11
- * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- /**
15
- * Test for getKeyboardKeys and getPressCommands methods of the android-tv-remote module.
16
- *
17
- * Usage: Run with `node test/api-surface.test.mjs`
18
- */
19
-
20
- import assert from "assert";
21
- import createRemote from "../src/lib/android-tv-remote.mjs";
22
-
23
- // Minimal config for instantiation (no real device needed for API surface test)
24
- const remote = createRemote({ ip: "127.0.0.1", autoConnect: false, maintainConnection: false, quiet: true });
25
-
26
- /**
27
- * Test getKeyboardKeys returns all top-level function keys from keyboard.key
28
- */
29
- function testGetKeyboardKeys() {
30
- const keys = remote.getKeyboardKeys();
31
- console.log("getKeyboardKeys:", keys);
32
- assert(Array.isArray(keys), "getKeyboardKeys should return an array");
33
- assert(keys.length > 0, "getKeyboardKeys should return at least one key");
34
- // Spot check for some expected keys
35
- ["a", "enter", "space"].forEach((k) => {
36
- assert(keys.includes(k), `getKeyboardKeys should include '${k}'`);
37
- });
38
- // Should not include 'shift' or 'keycode' (sub-objects)
39
- assert(!keys.includes("shift"), "getKeyboardKeys should not include shift");
40
- assert(!keys.includes("keycode"), "getKeyboardKeys should not include keycode");
41
- }
42
-
43
- /**
44
- * Test getPressCommands returns all top-level function keys from press
45
- */
46
- function testGetPressCommands() {
47
- const keys = remote.getPressCommands();
48
- console.log("getPressCommands:", keys);
49
- assert(Array.isArray(keys), "getPressCommands should return an array");
50
- assert(keys.length > 0, "getPressCommands should return at least one key");
51
- // Spot check for some expected keys (may vary by remote-keys.json)
52
- ["home", "back", "ok", "up", "down", "left", "right"].forEach((k) => {
53
- assert(keys.includes(k), `getPressCommands should include '${k}'`);
54
- });
55
- // Should not include 'long' (sub-object)
56
- assert(!keys.includes("long"), "getPressCommands should not include long");
57
- }
58
-
59
- console.log("Testing getKeyboardKeys...");
60
- testGetKeyboardKeys();
61
- console.log("Testing getPressCommands...");
62
- testGetPressCommands();
63
- console.log("All API surface tests passed.");