@cldmv/node-android-tv-remote 2.1.0 → 2.1.8
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/LICENSE +202 -0
- package/README.md +188 -88
- package/index.cjs +20 -8
- package/index.mjs +7 -5
- package/package.json +31 -9
- package/scripts/postinstall.mjs +51 -36
- package/scripts/setup-device.mjs +62 -16
- package/scripts/wake-tv.mjs +45 -29
- package/src/lib/android-tv-remote.mjs +349 -258
package/index.cjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
+
*
|
|
2
3
|
* @Project: @cldmv/node-android-tv-remote
|
|
3
4
|
* @Filename: /index.cjs
|
|
4
|
-
* @Date: 2025-10-
|
|
5
|
-
* @Author: Nate
|
|
5
|
+
* @Date: 2025-10-15T10:29:19-07:00 (1760549359)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
6
7
|
* @Email: <Shinrai@users.noreply.github.com>
|
|
7
8
|
* -----
|
|
8
|
-
* @Last modified by: Nate
|
|
9
|
-
* @Last modified time:
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-02T12:16:13-07:00 (1790968573)
|
|
10
11
|
* -----
|
|
11
|
-
* @Copyright: Copyright (c) 2013-
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -19,12 +21,22 @@
|
|
|
19
21
|
*
|
|
20
22
|
* @module @cldmv/node-android-tv-remote/cjs
|
|
21
23
|
*/
|
|
24
|
+
"use strict";
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
// index.cjs is a thin wrapper: it loads index.mjs through Node's synchronous require(esm).
|
|
27
|
+
// Node.js versions without require(esm) would fail with a bare ERR_REQUIRE_ESM, so fail
|
|
28
|
+
// early with a message that says what to do instead.
|
|
29
|
+
if (!process.features?.require_module) {
|
|
30
|
+
const error = new Error(
|
|
31
|
+
`@cldmv/node-android-tv-remote: require() needs Node.js ^20.19.0 or >=22.12.0 (this is ${process.version}). On older Node.js, load the package with import() instead.`
|
|
32
|
+
);
|
|
33
|
+
error.code = "ERR_REQUIRE_ESM";
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
25
36
|
|
|
26
|
-
const { default: createRemote } =
|
|
37
|
+
const { default: createRemote, createAndroidTVRemote } = require("./index.mjs");
|
|
27
38
|
|
|
28
39
|
module.exports = createRemote;
|
|
29
40
|
module.exports.createRemote = createRemote;
|
|
41
|
+
module.exports.createAndroidTVRemote = createAndroidTVRemote;
|
|
30
42
|
module.exports.default = createRemote;
|
package/index.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
+
*
|
|
2
3
|
* @Project: @cldmv/node-android-tv-remote
|
|
3
4
|
* @Filename: /index.mjs
|
|
4
|
-
* @Date: 2025-10-
|
|
5
|
-
* @Author: Nate
|
|
5
|
+
* @Date: 2025-10-15T10:29:19-07:00 (1760549359)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
6
7
|
* @Email: <Shinrai@users.noreply.github.com>
|
|
7
8
|
* -----
|
|
8
|
-
* @Last modified by: Nate
|
|
9
|
-
* @Last modified time:
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-02T12:16:14-07:00 (1790968574)
|
|
10
11
|
* -----
|
|
11
|
-
* @Copyright: Copyright (c) 2013-
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/node-android-tv-remote",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.8",
|
|
4
4
|
"description": "A Node.js library for controlling Android TV devices via ADB keycodes and text input.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -10,9 +10,20 @@
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"test": "jest",
|
|
14
13
|
"postinstall": "node scripts/postinstall.mjs",
|
|
15
|
-
"setup-device": "node scripts/setup-device.mjs"
|
|
14
|
+
"setup-device": "node scripts/setup-device.mjs",
|
|
15
|
+
"build": "echo '✓ no build step'",
|
|
16
|
+
"build:ci": "echo '✓ no build step'",
|
|
17
|
+
"test": "node tests/run-vitest.mjs && npm run test:cjs",
|
|
18
|
+
"test:cjs": "node --test tests/cjs/entry.test.cjs",
|
|
19
|
+
"test:watch": "vitest --config .configs/vitest.config.mjs",
|
|
20
|
+
"coverage": "node tests/run-vitest.mjs --coverage-quiet && npm run test:cjs",
|
|
21
|
+
"ci:coverage": "npm run coverage",
|
|
22
|
+
"lint": "eslint --config eslint.config.mjs .",
|
|
23
|
+
"lint:fix": "eslint --config eslint.config.mjs . --fix",
|
|
24
|
+
"format": "prettier --config .prettierrc --write .",
|
|
25
|
+
"format:check": "prettier --config .prettierrc --check .",
|
|
26
|
+
"fix:headers": "fix-headers --config .configs/fix-headers.json"
|
|
16
27
|
},
|
|
17
28
|
"keywords": [
|
|
18
29
|
"android",
|
|
@@ -41,7 +52,7 @@
|
|
|
41
52
|
"url": "https://github.com/CLDMV/node-android-tv-remote/issues"
|
|
42
53
|
},
|
|
43
54
|
"homepage": "https://github.com/CLDMV/node-android-tv-remote#readme",
|
|
44
|
-
"license": "
|
|
55
|
+
"license": "Apache-2.0",
|
|
45
56
|
"files": [
|
|
46
57
|
"src/",
|
|
47
58
|
"scripts/",
|
|
@@ -52,15 +63,26 @@
|
|
|
52
63
|
],
|
|
53
64
|
"dependencies": {
|
|
54
65
|
"@devicefarmer/adbkit": "^3.3.8",
|
|
55
|
-
"sharp": "^0.
|
|
56
|
-
},
|
|
57
|
-
"devDependencies": {
|
|
58
|
-
"jest": "^30.0.5"
|
|
66
|
+
"sharp": "^0.35.3"
|
|
59
67
|
},
|
|
60
68
|
"publishConfig": {
|
|
61
69
|
"access": "public"
|
|
62
70
|
},
|
|
63
71
|
"engines": {
|
|
64
|
-
"node": "
|
|
72
|
+
"node": ">=20.9.0"
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@cldmv/configs": "^1.2.4",
|
|
76
|
+
"@cldmv/fix-headers": "^2.2.0",
|
|
77
|
+
"@cldmv/vitest-runner": "^1.2.0",
|
|
78
|
+
"@eslint/css": "^2.0.0",
|
|
79
|
+
"@eslint/js": "^10.0.1",
|
|
80
|
+
"@eslint/json": "^2.0.1",
|
|
81
|
+
"@eslint/markdown": "^8.0.3",
|
|
82
|
+
"@vitest/coverage-v8": "^5.0.0",
|
|
83
|
+
"eslint": "^10.8.0",
|
|
84
|
+
"globals": "^17.9.0",
|
|
85
|
+
"prettier": "^3.9.6",
|
|
86
|
+
"vitest": "^5.0.0"
|
|
65
87
|
}
|
|
66
88
|
}
|
package/scripts/postinstall.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
+
*
|
|
2
3
|
* @Project: @cldmv/node-android-tv-remote
|
|
3
4
|
* @Filename: /scripts/postinstall.mjs
|
|
4
|
-
* @Date: 2025-10-
|
|
5
|
-
* @Author: Nate
|
|
5
|
+
* @Date: 2025-10-15T10:19:05-07:00 (1760548745)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
6
7
|
* @Email: <Shinrai@users.noreply.github.com>
|
|
7
8
|
* -----
|
|
8
|
-
* @Last modified by: Nate
|
|
9
|
-
* @Last modified time:
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-02T12:16:14-07:00 (1790968574)
|
|
10
11
|
* -----
|
|
11
|
-
* @Copyright: Copyright (c) 2013-
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -16,46 +18,59 @@
|
|
|
16
18
|
*/
|
|
17
19
|
import { execSync } from "child_process";
|
|
18
20
|
import os from "os";
|
|
21
|
+
import { realpathSync } from "node:fs";
|
|
22
|
+
import { fileURLToPath } from "node:url";
|
|
19
23
|
|
|
20
24
|
function hasAdb() {
|
|
21
25
|
try {
|
|
22
26
|
execSync("adb version", { stdio: "ignore" });
|
|
23
27
|
return true;
|
|
24
|
-
} catch (
|
|
28
|
+
} catch (_) {
|
|
25
29
|
return false;
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Print whether adb is available, with install instructions when it isn't.
|
|
35
|
+
* @returns {void}
|
|
36
|
+
*/
|
|
37
|
+
export function main() {
|
|
38
|
+
if (hasAdb()) {
|
|
39
|
+
console.log("ADB is installed and available in your PATH.");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
33
42
|
|
|
34
|
-
console.log("\nADB is not installed or not in your PATH.");
|
|
35
|
-
console.log("Follow these instructions to install ADB:");
|
|
43
|
+
console.log("\nADB is not installed or not in your PATH.");
|
|
44
|
+
console.log("Follow these instructions to install ADB:");
|
|
45
|
+
|
|
46
|
+
const platform = os.platform();
|
|
47
|
+
if (platform === "win32") {
|
|
48
|
+
console.log("\nWindows:");
|
|
49
|
+
console.log("1. Download the SDK Platform Tools for Windows: https://developer.android.com/studio/releases/platform-tools");
|
|
50
|
+
console.log("2. Extract the ZIP file.");
|
|
51
|
+
console.log("3. Add the extracted folder to your system PATH.");
|
|
52
|
+
console.log('4. Test by running "adb version" in Command Prompt.');
|
|
53
|
+
} else if (platform === "darwin") {
|
|
54
|
+
console.log("\nmacOS:");
|
|
55
|
+
console.log("1. Download the SDK Platform Tools for Mac: https://developer.android.com/studio/releases/platform-tools");
|
|
56
|
+
console.log("2. Extract the ZIP file.");
|
|
57
|
+
console.log("3. Move the extracted folder to /usr/local/bin or add it to your PATH.");
|
|
58
|
+
console.log('4. Test by running "adb version" in Terminal.');
|
|
59
|
+
} else if (platform === "linux") {
|
|
60
|
+
console.log("\nLinux:");
|
|
61
|
+
console.log("1. Download the SDK Platform Tools for Linux: https://developer.android.com/studio/releases/platform-tools");
|
|
62
|
+
console.log("2. Extract the ZIP file.");
|
|
63
|
+
console.log("3. Move the extracted folder to /usr/local/bin or add it to your PATH.");
|
|
64
|
+
console.log("4. Or install via your package manager:");
|
|
65
|
+
console.log(" - Ubuntu/Debian: sudo apt-get install android-tools-adb");
|
|
66
|
+
console.log(" - Fedora/Red Hat: sudo dnf install android-tools");
|
|
67
|
+
console.log(" - CentOS/yum: sudo yum install android-tools");
|
|
68
|
+
console.log('5. Test by running "adb version" in your shell.');
|
|
69
|
+
}
|
|
70
|
+
console.log("\nYou must accept the ADB authorization prompt on your Android TV device the first time you connect.");
|
|
71
|
+
}
|
|
36
72
|
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
console.log("1. Download the SDK Platform Tools for Windows: https://developer.android.com/studio/releases/platform-tools");
|
|
41
|
-
console.log("2. Extract the ZIP file.");
|
|
42
|
-
console.log("3. Add the extracted folder to your system PATH.");
|
|
43
|
-
console.log('4. Test by running "adb version" in Command Prompt.');
|
|
44
|
-
} else if (platform === "darwin") {
|
|
45
|
-
console.log("\nmacOS:");
|
|
46
|
-
console.log("1. Download the SDK Platform Tools for Mac: https://developer.android.com/studio/releases/platform-tools");
|
|
47
|
-
console.log("2. Extract the ZIP file.");
|
|
48
|
-
console.log("3. Move the extracted folder to /usr/local/bin or add it to your PATH.");
|
|
49
|
-
console.log('4. Test by running "adb version" in Terminal.');
|
|
50
|
-
} else if (platform === "linux") {
|
|
51
|
-
console.log("\nLinux:");
|
|
52
|
-
console.log("1. Download the SDK Platform Tools for Linux: https://developer.android.com/studio/releases/platform-tools");
|
|
53
|
-
console.log("2. Extract the ZIP file.");
|
|
54
|
-
console.log("3. Move the extracted folder to /usr/local/bin or add it to your PATH.");
|
|
55
|
-
console.log("4. Or install via your package manager:");
|
|
56
|
-
console.log(" - Ubuntu/Debian: sudo apt-get install android-tools-adb");
|
|
57
|
-
console.log(" - Fedora/Red Hat: sudo dnf install android-tools");
|
|
58
|
-
console.log(" - CentOS/yum: sudo yum install android-tools");
|
|
59
|
-
console.log('5. Test by running "adb version" in your shell.');
|
|
73
|
+
// Run only when executed directly (npm postinstall), not when imported.
|
|
74
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
75
|
+
main();
|
|
60
76
|
}
|
|
61
|
-
console.log("\nYou must accept the ADB authorization prompt on your Android TV device the first time you connect.");
|
package/scripts/setup-device.mjs
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
+
*
|
|
2
3
|
* @Project: @cldmv/node-android-tv-remote
|
|
3
4
|
* @Filename: /scripts/setup-device.mjs
|
|
4
|
-
* @Date: 2025-10-
|
|
5
|
-
* @Author: Nate
|
|
5
|
+
* @Date: 2025-10-15T10:19:05-07:00 (1760548745)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
6
7
|
* @Email: <Shinrai@users.noreply.github.com>
|
|
7
8
|
* -----
|
|
8
|
-
* @Last modified by: Nate
|
|
9
|
-
* @Last modified time:
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-02T12:16:14-07:00 (1790968574)
|
|
10
11
|
* -----
|
|
11
|
-
* @Copyright: Copyright (c) 2013-
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
12
14
|
*/
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
+
|
|
16
|
+
import readline from "node:readline";
|
|
17
|
+
import { realpathSync } from "node:fs";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
import createRemote from "../src/lib/android-tv-remote.mjs";
|
|
15
20
|
|
|
16
21
|
/**
|
|
17
22
|
* Interactive CLI for setting up a new Android TV device.
|
|
18
|
-
* Prompts for IP and port, then
|
|
23
|
+
* Prompts for IP and port, then applies the keep-awake settings, wakes the
|
|
24
|
+
* device and returns it to the home screen, using the v2 remote API.
|
|
25
|
+
*
|
|
26
|
+
* Usage: npm run setup-device
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Ask a question on the terminal.
|
|
31
|
+
* @param {string} question - Prompt text.
|
|
32
|
+
* @param {string} [defaultValue] - Value used when the answer is empty.
|
|
33
|
+
* @returns {Promise<string>} The answer, or the default.
|
|
19
34
|
*/
|
|
20
35
|
async function prompt(question, defaultValue) {
|
|
21
36
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -27,20 +42,48 @@ async function prompt(question, defaultValue) {
|
|
|
27
42
|
});
|
|
28
43
|
}
|
|
29
44
|
|
|
30
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Connect to a device and prepare it for remote control: apply the keep-awake
|
|
47
|
+
* settings, make sure it is awake, return to the home screen, then disconnect.
|
|
48
|
+
* @param {object} options - Setup options.
|
|
49
|
+
* @param {string} options.ip - Device IP address.
|
|
50
|
+
* @param {number} [options.port=5555] - ADB port.
|
|
51
|
+
* @param {boolean} [options.quiet=false] - Suppress progress logs.
|
|
52
|
+
* @param {Function} [options.create=createRemote] - Remote factory (injectable for tests).
|
|
53
|
+
* @param {Function} [options.log=console.log] - Log sink for progress and error events.
|
|
54
|
+
* @returns {Promise<void>} Resolves once setup is complete; rejects on failure.
|
|
55
|
+
*/
|
|
56
|
+
export async function setupDevice({ ip, port = 5555, quiet = false, create = createRemote, log = console.log }) {
|
|
57
|
+
const remote = await create({ ip, port, quiet, autoConnect: false, maintainConnection: false });
|
|
58
|
+
remote.on("log", (data) => log(`[${data.level}] ${data.message}`));
|
|
59
|
+
remote.on("error", (data) => log(`[error] ${data.message}`));
|
|
60
|
+
|
|
61
|
+
const result = await remote.connect();
|
|
62
|
+
if (!remote.isConnected) {
|
|
63
|
+
throw result instanceof Error ? result : new Error(`Could not connect to ${ip}:${port}`);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
await remote.setSettings();
|
|
67
|
+
await remote.ensureAwake();
|
|
68
|
+
await remote.press.home();
|
|
69
|
+
} finally {
|
|
70
|
+
await remote.disconnect();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* CLI entry: prompt for the device address and run the setup.
|
|
76
|
+
* @returns {Promise<void>}
|
|
77
|
+
*/
|
|
78
|
+
export async function main() {
|
|
31
79
|
const ip = await prompt("Enter device IP address");
|
|
32
80
|
if (!ip) {
|
|
33
81
|
console.error("IP address is required.");
|
|
34
82
|
process.exit(1);
|
|
35
83
|
}
|
|
36
84
|
const port = parseInt(await prompt("Enter device port", "5555"), 10) || 5555;
|
|
37
|
-
const quiet = false;
|
|
38
|
-
const setup = new AndroidTVSetup({ ip, port, quiet });
|
|
39
85
|
try {
|
|
40
|
-
await
|
|
41
|
-
await setup.setSettings();
|
|
42
|
-
await setup.ensureAwake();
|
|
43
|
-
await setup.disconnect();
|
|
86
|
+
await setupDevice({ ip, port });
|
|
44
87
|
console.log("\nSetup complete!");
|
|
45
88
|
} catch (err) {
|
|
46
89
|
console.error("Error:", err.message || err);
|
|
@@ -48,4 +91,7 @@ async function main() {
|
|
|
48
91
|
}
|
|
49
92
|
}
|
|
50
93
|
|
|
51
|
-
|
|
94
|
+
// Run only when executed directly (`npm run setup-device`), not when imported.
|
|
95
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
96
|
+
await main();
|
|
97
|
+
}
|
package/scripts/wake-tv.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
+
*
|
|
2
3
|
* @Project: @cldmv/node-android-tv-remote
|
|
3
4
|
* @Filename: /scripts/wake-tv.mjs
|
|
4
|
-
* @Date: 2025-10-
|
|
5
|
-
* @Author: Nate
|
|
5
|
+
* @Date: 2025-10-15T20:44:49-07:00 (1760586289)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
6
7
|
* @Email: <Shinrai@users.noreply.github.com>
|
|
7
8
|
* -----
|
|
8
|
-
* @Last modified by: Nate
|
|
9
|
-
* @Last modified time:
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-02T12:16:14-07:00 (1790968574)
|
|
10
11
|
* -----
|
|
11
|
-
* @Copyright: Copyright (c) 2013-
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -16,36 +18,50 @@
|
|
|
16
18
|
* Usage: node wake-tv.mjs <ip_address>
|
|
17
19
|
*/
|
|
18
20
|
|
|
21
|
+
import { realpathSync } from "node:fs";
|
|
22
|
+
import { fileURLToPath } from "node:url";
|
|
19
23
|
import createRemote from "../src/lib/android-tv-remote.mjs";
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
/**
|
|
26
|
+
* CLI entry: wake the device whose IP is given on the command line.
|
|
27
|
+
* @param {string[]} [argv=process.argv.slice(2)] - CLI arguments.
|
|
28
|
+
* @returns {Promise<void>}
|
|
29
|
+
*/
|
|
30
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
31
|
+
// Get IP address from command line arguments
|
|
32
|
+
const ip = argv[0];
|
|
23
33
|
|
|
24
|
-
if (!ip) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
34
|
+
if (!ip) {
|
|
35
|
+
console.error("❌ Usage: node wake-tv.mjs <ip_address>");
|
|
36
|
+
console.error(" Example: node wake-tv.mjs 10.6.0.133");
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
29
39
|
|
|
30
|
-
console.log(`🔌 Waking up TV at ${ip}...`);
|
|
40
|
+
console.log(`🔌 Waking up TV at ${ip}...`);
|
|
31
41
|
|
|
32
|
-
try {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
try {
|
|
43
|
+
const remote = await createRemote({
|
|
44
|
+
ip: ip,
|
|
45
|
+
autoConnect: true,
|
|
46
|
+
quiet: false
|
|
47
|
+
});
|
|
38
48
|
|
|
39
|
-
|
|
49
|
+
console.log("✅ Connected to device");
|
|
40
50
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
// Wake up the device
|
|
52
|
+
await remote.ensureAwake();
|
|
53
|
+
console.log("🎉 TV should now be awake and ready!");
|
|
54
|
+
|
|
55
|
+
// Disconnect
|
|
56
|
+
await remote.disconnect();
|
|
57
|
+
console.log("✅ Disconnected from device");
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error("❌ Failed to wake up TV:", error.message);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
44
63
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error("❌ Failed to wake up TV:", error.message);
|
|
50
|
-
process.exit(1);
|
|
64
|
+
// Run only when executed directly, not when imported.
|
|
65
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
66
|
+
await main();
|
|
51
67
|
}
|