@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.
@@ -1,74 +0,0 @@
1
- const Remote = require("../src/lib/android-tv-remote");
2
-
3
- // Usage: Set ANDROID_TV_IP and ANDROID_TV_PORT env vars before running Jest
4
- const TEST_IP = process.env.ANDROID_TV_IP || "192.168.1.100";
5
- const TEST_PORT = process.env.ANDROID_TV_PORT ? parseInt(process.env.ANDROID_TV_PORT, 10) : 5555;
6
-
7
- /** @type {import('../src/lib/android-tv-remote').RemoteConfig} */
8
- const config = {
9
- ip: TEST_IP,
10
- port: TEST_PORT,
11
- quiet: true,
12
- autoConnect: true,
13
- autoDisconnect: true,
14
- disconnectTimeout: 5
15
- };
16
-
17
- const remote = Remote(config);
18
-
19
- describe("android-tv-remote", () => {
20
- jest.setTimeout(20000); // ADB/network can be slow
21
-
22
- test("should connect and disconnect without error (promise)", async () => {
23
- await remote.connect();
24
- await remote.disconnect();
25
- });
26
-
27
- test("should connect and disconnect without error (callback)", (done) => {
28
- remote.connect((err) => {
29
- expect(err).toBeFalsy();
30
- remote.disconnect((err2) => {
31
- expect(err2).toBeFalsy();
32
- done();
33
- });
34
- });
35
- });
36
-
37
- test("should send a keycode (HOME)", async () => {
38
- await remote.connect();
39
- await remote.inputKeycode(3); // 3 = KEYCODE_HOME
40
- await remote.disconnect();
41
- });
42
-
43
- test("should send text input", async () => {
44
- await remote.connect();
45
- await remote.keyboard.text("test");
46
- await remote.disconnect();
47
- });
48
-
49
- test("should call press.home()", async () => {
50
- await remote.connect();
51
- await remote.press.home();
52
- await remote.disconnect();
53
- });
54
-
55
- test("should call keyboard.key.a()", async () => {
56
- await remote.connect();
57
- await remote.keyboard.key.a();
58
- await remote.disconnect();
59
- });
60
-
61
- test("should call keyboard.key.shift.a()", async () => {
62
- await remote.connect();
63
- await remote.keyboard.key.shift.a();
64
- await remote.disconnect();
65
- });
66
-
67
- test("should handle settings get", async () => {
68
- await remote.handleSettings("get", true);
69
- });
70
-
71
- test("should handle settings set", async () => {
72
- await remote.handleSettings("set", true);
73
- });
74
- });
@@ -1,50 +0,0 @@
1
- /**
2
- * Test for getKeyboardKeys and getPressCommands methods of the android-tv-remote module.
3
- *
4
- * Usage: Run with `node test/api-surface.test.js`
5
- */
6
-
7
- const assert = require("assert");
8
- const createRemote = require("../src/lib/android-tv-remote");
9
-
10
- // Minimal config for instantiation (no real device needed for API surface test)
11
- const remote = createRemote({ ip: "127.0.0.1", autoConnect: false, maintainConnection: false, quiet: true });
12
-
13
- /**
14
- * Test getKeyboardKeys returns all top-level function keys from keyboard.key
15
- */
16
- function testGetKeyboardKeys() {
17
- const keys = remote.getKeyboardKeys();
18
- console.log("getKeyboardKeys:", keys);
19
- assert(Array.isArray(keys), "getKeyboardKeys should return an array");
20
- assert(keys.length > 0, "getKeyboardKeys should return at least one key");
21
- // Spot check for some expected keys
22
- ["a", "enter", "space"].forEach((k) => {
23
- assert(keys.includes(k), `getKeyboardKeys should include '${k}'`);
24
- });
25
- // Should not include 'shift' or 'keycode' (sub-objects)
26
- assert(!keys.includes("shift"), "getKeyboardKeys should not include shift");
27
- assert(!keys.includes("keycode"), "getKeyboardKeys should not include keycode");
28
- }
29
-
30
- /**
31
- * Test getPressCommands returns all top-level function keys from press
32
- */
33
- function testGetPressCommands() {
34
- const keys = remote.getPressCommands();
35
- console.log("getPressCommands:", keys);
36
- assert(Array.isArray(keys), "getPressCommands should return an array");
37
- assert(keys.length > 0, "getPressCommands should return at least one key");
38
- // Spot check for some expected keys (may vary by remote-keys.json)
39
- ["home", "back", "ok", "up", "down", "left", "right"].forEach((k) => {
40
- assert(keys.includes(k), `getPressCommands should include '${k}'`);
41
- });
42
- // Should not include 'long' (sub-object)
43
- assert(!keys.includes("long"), "getPressCommands should not include long");
44
- }
45
-
46
- console.log("Testing getKeyboardKeys...");
47
- testGetKeyboardKeys();
48
- console.log("Testing getPressCommands...");
49
- testGetPressCommands();
50
- console.log("All API surface tests passed.");
@@ -1,35 +0,0 @@
1
- // Test script to connect to an ADB device and read settings.
2
- // Usage: node test/connect-readall.js <ip> [port] [get|set] [--quiet]
3
- const AndroidTVSetup = require("../src/lib/adb/setup");
4
- const readline = require("readline");
5
-
6
- async function main() {
7
- const ip = process.argv[2];
8
- const port = process.argv[3] ? parseInt(process.argv[3], 10) : 5555;
9
- const mode = process.argv[4] === "set" ? "set" : "get";
10
- const quiet = process.argv.includes("--quiet");
11
-
12
- if (!ip) {
13
- console.error("Usage: node test/connect-readall.js <ip> [port] [get|set] [--quiet]");
14
- process.exit(1);
15
- }
16
-
17
- if (!quiet) console.log(`Running in ${mode} mode on ${ip}:${port}`);
18
-
19
- const setup = new AndroidTVSetup({ ip, port, quiet });
20
- try {
21
- await setup.connect();
22
- if (mode === "set") {
23
- await setup.setSettings();
24
- }
25
- await setup.ensureAwake();
26
- await setup.disconnect();
27
- } catch (err) {
28
- setup.errorWithTime("Error:", err.message || err);
29
- process.exit(1);
30
- }
31
-
32
- if (!quiet) console.log(`Ran in ${mode} mode on ${ip}:${port}`);
33
- }
34
-
35
- main();
@@ -1,69 +0,0 @@
1
- // Interactive test script for Android TV Remote
2
- // Prompts for IP and port, connects, and sends button presses at intervals.
3
- // Usage: node test/interactive-remote.js
4
-
5
- const readline = require("readline");
6
- const createRemote = require("../src/lib/android-tv-remote");
7
-
8
- /**
9
- * Prompts the user for input in the terminal.
10
- * @param {string} query - The prompt message.
11
- * @returns {Promise<string>} The user's input.
12
- * @example
13
- * const ip = await prompt("Enter IP: ");
14
- */
15
- function prompt(query) {
16
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
17
- return new Promise((resolve) =>
18
- rl.question(query, (ans) => {
19
- rl.close();
20
- resolve(ans);
21
- })
22
- );
23
- }
24
-
25
- /**
26
- * Runs the interactive remote test using the main remote module.
27
- * Prompts for IP/port, connects, and sends button presses.
28
- * @returns {Promise<void>}
29
- */
30
- async function main() {
31
- const ip = (await prompt("Enter device IP: ")).trim();
32
- let portInput = await prompt("Enter port [5555]: ");
33
- const port = portInput.trim() ? parseInt(portInput.trim(), 10) : 5555;
34
- if (!ip) {
35
- console.error("IP address is required.");
36
- process.exit(1);
37
- }
38
- try {
39
- const remote = createRemote({ ip, port });
40
- await remote.connect();
41
- console.log(`Connected to ${ip}:${port}`);
42
- // List of buttons to press (as method names on remote.press)
43
- const buttons = ["home", "up", "down", "left", "right", "ok", "back"];
44
- for (let i = 0; i < buttons.length; i++) {
45
- const btn = buttons[i];
46
- if (remote.press && typeof remote.press[btn] === "function") {
47
- console.log(`Pressing: ${btn}`);
48
- await remote.press[btn]();
49
- } else {
50
- console.log(`Button '${btn}' not available.`);
51
- }
52
- if (btn === "home") {
53
- await new Promise((res) => setTimeout(res, 750)); // 750ms after home
54
- } else if (btn === "back") {
55
- await new Promise((res) => setTimeout(res, 2500)); // 2.5s for back
56
- } else {
57
- await new Promise((res) => setTimeout(res, 500));
58
- }
59
- }
60
- await remote.disconnect();
61
- console.log("Test complete. Disconnected.");
62
- } catch (err) {
63
- if (remote.errorWithTime) remote.errorWithTime("Error:", err.message || err);
64
- else console.error("Error:", err.message || err);
65
- process.exit(1);
66
- }
67
- }
68
-
69
- main();