@cldmv/node-android-tv-remote 2.0.0 → 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/README.md CHANGED
@@ -18,16 +18,21 @@
18
18
 
19
19
  ## Overview
20
20
 
21
- A modern, **event-driven** Node.js module for controlling Android TV devices via ADB. Supports sending keycodes, keyboard input, and remote control commands. Designed for compatibility with a wide range of Android TV devices, including Fire TV, Chromecast with Google TV, and more.
21
+ A modern, **event-driven** Node.js module for controlling Android TV devices via ADB. Supports sending keycodes, comprehensive keyboard input (71 characters with smart shift detection), and remote control commands. Designed for compatibility with a wide range of Android TV devices, including Fire TV, Chromecast with Google TV, and more.
22
22
 
23
23
  ### Key Features
24
24
 
25
- - 🎯 **Event-driven architecture** - No console pollution, structured event data
25
+ - 🎯 **Event-driven architecture** - Comprehensive event system with structured data
26
+ - ⌨️ **Comprehensive keyboard input** - 71 characters with smart shift detection and special symbols
26
27
  - 🔄 **ESM & CommonJS support** - Works with both `import` and `require`
27
28
  - 🛡️ **Error resilience** - Errors emit events instead of crashing your app
28
29
  - 🔗 **Method chaining** - Fluent API for event listener management
29
30
  - 📊 **Structured logging** - Timestamped, categorized log events with source tracking
30
31
  - 🚀 **Promise-based** - Modern async/await support with callback compatibility
32
+ - 📸 **Advanced screencap** - High-performance PNG screenshots with resizing and thumbnails
33
+ - ⚡ **Performance optimized** - Direct PNG streaming with 20x speed improvements
34
+ - 🔄 **Device management** - Reboot, wake, settings configuration with event tracking
35
+ - 📱 **Universal compatibility** - Works with Fire TV, Chromecast, Shield, and more
31
36
 
32
37
  ## Installation
33
38
 
@@ -73,25 +78,27 @@ npm install android-tv-remote
73
78
  ### Basic Usage
74
79
 
75
80
  ```js
76
- // ESM
81
+ ```js
82
+ // ESM (Node.js with type: "module" in package.json)
77
83
  import createRemote from "android-tv-remote";
78
84
 
79
- // CJS
85
+ // CommonJS
80
86
  const createRemote = require("android-tv-remote");
81
87
 
82
- const remote = createRemote({ ip: "192.168.1.100" });
83
-
84
- // Connect
85
- await remote.connect();
88
+ // Create remote (async function)
89
+ const remote = await createRemote({ ip: "192.168.1.100" });
86
90
 
87
- // Press Home
91
+ // Use with async/await (recommended)
88
92
  await remote.press.home();
89
-
90
- // Type text
91
- await remote.keyboard.text("hello world");
92
-
93
- // Disconnect
94
- await remote.disconnect();
93
+ await remote.press.up();
94
+ await remote.press.ok();
95
+
96
+ // Or chain promises
97
+ createRemote({ ip: "192.168.1.100" })
98
+ .then(remote => remote.press.home())
99
+ .then(() => remote.press.up())
100
+ .then(() => remote.press.ok());
101
+ ```
95
102
  ```
96
103
 
97
104
  ### Event-Driven Usage (Recommended)
@@ -101,7 +108,7 @@ This module uses an **event-driven architecture** instead of console logging. Al
101
108
  ```js
102
109
  import createRemote from "android-tv-remote";
103
110
 
104
- const remote = createRemote({ ip: "192.168.1.100" });
111
+ const remote = await createRemote({ ip: "192.168.1.100" });
105
112
 
106
113
  // Listen for log events (info, warn, error, debug)
107
114
  remote.on("log", (data) => {
@@ -118,20 +125,163 @@ remote.on("error", (data) => {
118
125
  }
119
126
  });
120
127
 
128
+ // Listen for screenshot events
129
+ remote.on("screencap-complete", (data) => {
130
+ console.log(`Screenshot completed in ${data.timing.total}ms`);
131
+ });
132
+
121
133
  // Use the remote
122
134
  await remote.press.home();
135
+ await remote.screencap({ filepath: './screenshot.png' });
123
136
  ```
124
137
 
125
- ### Static Create Method
138
+ ### Async Initialization
126
139
 
127
- For cleaner async initialization:
140
+ The createRemote function is async and returns a Promise:
128
141
 
129
142
  ```js
130
- import { createAndroidTVRemote } from "android-tv-remote";
143
+ import createRemote from "android-tv-remote";
131
144
 
132
- const remote = await createAndroidTVRemote({ ip: "192.168.1.100" });
145
+ // Async initialization with await
146
+ const remote = await createRemote({ ip: "192.168.1.100" });
133
147
  remote.on("log", console.log);
134
148
  await remote.press.play();
149
+
150
+ // Or use .then()
151
+ createRemote({ ip: "192.168.1.100" })
152
+ .then(remote => {
153
+ remote.on("log", console.log);
154
+ return remote.press.play();
155
+ });
156
+ ```
157
+
158
+ ### Screenshot Functionality
159
+
160
+ Advanced screencap with resizing, thumbnails, and file saving:
161
+
162
+ ```js
163
+ import createRemote from "android-tv-remote";
164
+
165
+ const remote = await createRemote({ ip: "192.168.1.100" });
166
+
167
+ // Basic screenshot (returns PNG stream)
168
+ const stream = await remote.screencap();
169
+
170
+ // Screenshot with resizing
171
+ const resizedStream = await remote.screencap({ width: 1280, height: 720 });
172
+
173
+ // Save screenshot to file (non-blocking)
174
+ await remote.screencap({ filepath: './screenshot.png' });
175
+
176
+ // Resized screenshot saved to file
177
+ await remote.screencap({
178
+ width: 640,
179
+ height: 360,
180
+ filepath: './thumbnail.png'
181
+ });
182
+
183
+ // Quick thumbnail (default 240px width)
184
+ const thumbStream = await remote.thumbnail();
185
+
186
+ // Custom thumbnail dimensions
187
+ const customThumb = await remote.thumbnail({
188
+ width: 320,
189
+ height: 180,
190
+ filepath: './thumb.png'
191
+ });
192
+
193
+ // Access last screenshot data
194
+ console.log('Last screenshot available:', !!remote.lastScreencapData);
195
+
196
+ // Listen for screenshot events
197
+ remote.on('screencap-complete', (data) => {
198
+ console.log(`Screenshot completed in ${data.timing.total}ms`);
199
+ });
200
+ ```
201
+
202
+ ### Device Management
203
+
204
+ Comprehensive device control with event tracking:
205
+
206
+ ```js
207
+ import createRemote from "android-tv-remote";
208
+
209
+ const remote = await createRemote({ ip: "192.168.1.100" });
210
+
211
+ // Reboot the device
212
+ await remote.reboot();
213
+
214
+ // Ensure device is awake and responsive
215
+ const isAwake = await remote.ensureAwake();
216
+
217
+ // Configure optimal settings for remote control
218
+ await remote.setSettings(); // Set optimal settings
219
+ await remote.setSettings('get'); // Get current settings
220
+
221
+ // Wait for device to finish booting (after reboot)
222
+ await remote.waitBootComplete(60000); // 60 second timeout
223
+
224
+ // Connection management
225
+ await remote.connect();
226
+ console.log('Connected:', remote.isConnected);
227
+ await remote.disconnect();
228
+
229
+ // Listen for device management events
230
+ remote.on('log', (data) => {
231
+ if (data.source === 'reboot') {
232
+ console.log(`Reboot: ${data.message}`);
233
+ }
234
+ if (data.source === 'ensureAwake') {
235
+ console.log(`Wake: ${data.message}`);
236
+ }
237
+ });
238
+ ```
239
+
240
+ ### Keyboard Input
241
+
242
+ Comprehensive text input with individual key support and smart shift detection:
243
+
244
+ ```js
245
+ import createRemote from "android-tv-remote";
246
+
247
+ const remote = await createRemote({ ip: "192.168.1.100" });
248
+
249
+ // Text input (recommended for typing sentences)
250
+ await remote.keyboard.text("Hello World!");
251
+ await remote.keyboard.text("user@example.com");
252
+
253
+ // Individual character input
254
+ await remote.keyboard.key.h(); // Types "h"
255
+ await remote.keyboard.key.e(); // Types "e"
256
+ await remote.keyboard.key.l(); // Types "l"
257
+ await remote.keyboard.key.l(); // Types "l"
258
+ await remote.keyboard.key.o(); // Types "o"
259
+
260
+ // Shifted characters (only available for keys that change when shifted)
261
+ await remote.keyboard.key.shift.h(); // Types "H"
262
+ await remote.keyboard.key.shift.one(); // Types "!"
263
+ await remote.keyboard.key.shift.semicolon(); // Types ":"
264
+
265
+ // Special characters and symbols
266
+ await remote.keyboard.key.space(); // Types " "
267
+ await remote.keyboard.key.exclamation(); // Types "!"
268
+ await remote.keyboard.key.at(); // Types "@"
269
+ await remote.keyboard.key.hash(); // Types "#"
270
+ await remote.keyboard.key.dollar(); // Types "$"
271
+
272
+ // Control keys
273
+ await remote.keyboard.key.tab(); // Tab character
274
+ await remote.keyboard.key.enter(); // Enter/Return
275
+ await remote.keyboard.key.backspace(); // Backspace
276
+
277
+ // Using keycode fallback (when available for regular keys)
278
+ await remote.keyboard.key.a.keycode(); // Sends keycode instead of character
279
+
280
+ // Note: Shift variants are only available for keys that actually change
281
+ // when shifted (letters, numbers, and some symbols). Special characters
282
+ // like @, #, !, etc. don't have shift variants since they're already
283
+ // the shifted form. Shift keys only support text input, not keycodes,
284
+ // since Android ADB doesn't support sending multiple keycodes simultaneously.
135
285
  ```
136
286
 
137
287
  ### Event Data Structure
@@ -142,7 +292,7 @@ await remote.press.play();
142
292
  {
143
293
  level: 'info' | 'warn' | 'error' | 'debug',
144
294
  message: 'Human readable message',
145
- source: 'connect' | 'disconnect' | 'handleSettings' | etc,
295
+ source: 'connect' | 'disconnect' | 'screencap' | 'reboot' | 'ensureAwake' | etc,
146
296
  timestamp: '2025-10-15T18:37:44.854Z',
147
297
  data?: any // Optional additional data
148
298
  }
@@ -153,12 +303,30 @@ await remote.press.play();
153
303
  ```js
154
304
  {
155
305
  error: Error, // The actual error object
156
- source: 'connect' | 'adb' | 'keyboard.key' | etc,
306
+ source: 'connect' | 'adb' | 'screencap' | 'reboot' | etc,
157
307
  message: 'Human readable error message',
158
308
  timestamp: '2025-10-15T18:37:44.854Z'
159
309
  }
160
310
  ```
161
311
 
312
+ **Screenshot Events:**
313
+
314
+ ```js
315
+ // screencap-complete event
316
+ {
317
+ timestamp: '2025-10-15T18:37:44.854Z',
318
+ filepath?: './screenshot.png', // If saved to file
319
+ processed: true, // Whether Sharp processing was used
320
+ width?: 1280,
321
+ height?: 720,
322
+ timing: {
323
+ capture: 25.4, // ADB capture time in ms
324
+ sharpProcess?: 1.2, // Sharp processing time in ms
325
+ total: 26.6 // Total operation time in ms
326
+ }
327
+ }
328
+ ```
329
+
162
330
  ## API
163
331
 
164
332
  ### Main Methods
@@ -166,10 +334,15 @@ await remote.press.play();
166
334
  - `connect()` / `disconnect()` - Device connection management
167
335
  - `press.<key>()` / `press.long.<key>()` - Remote control buttons
168
336
  - `keyboard.text(text)` - Text input
169
- - `keyboard.key.<key>()` / `keyboard.key.<key>.keycode()` - Individual keys
170
- - `keyboard.key.shift.<key>()` / `keyboard.key.shift.<key>.keycode()` - Shifted keys
337
+ - `keyboard.key.<key>()` / `keyboard.key.<key>.keycode()` - Individual keys (71 available)
338
+ - `keyboard.key.shift.<key>()` - Shifted keys (47 available, text input only)
171
339
  - `inputKeycode(code)` - Raw Android keycodes
172
- - `handleSettings(mode, [overrideQuiet])` - Android settings management
340
+ - `reboot()` - Reboot the Android TV device
341
+ - `ensureAwake()` - Ensure device is awake and responsive
342
+ - `setSettings(mode)` - Configure optimal Android TV settings
343
+ - `waitBootComplete(timeout)` - Wait for device boot completion
344
+ - `screencap(options)` - Take PNG screenshots with optional resizing and file saving
345
+ - `thumbnail(options)` - Take thumbnail screenshots (default 240px width)
173
346
 
174
347
  ### Event Methods
175
348
 
@@ -182,11 +355,18 @@ await remote.press.play();
182
355
 
183
356
  - `log` - Emitted for all operations (info, warn, error, debug levels)
184
357
  - `error` - Emitted when errors occur (structured error data)
358
+ - `screencap-start` - Emitted when screenshot capture begins
359
+ - `screencap-captured` - Emitted when raw screenshot is captured
360
+ - `screencap-processing` - Emitted when image processing begins
361
+ - `screencap-ready` - Emitted when processed stream is ready
362
+ - `screencap-saved` - Emitted when screenshot is saved to file
363
+ - `screencap-complete` - Emitted when entire screenshot operation completes
185
364
 
186
365
  ### Properties
187
366
 
188
367
  - `isConnected` - Boolean indicating connection status
189
368
  - `initPromise` - Promise that resolves when initialization completes
369
+ - `lastScreencapData` - Buffer/Stream containing the last captured screenshot data
190
370
 
191
371
  See JSDoc comments in source code for full API documentation.
192
372
 
package/index.cjs CHANGED
@@ -23,9 +23,8 @@
23
23
  const { createRequire } = require("module");
24
24
  const requireESM = createRequire(__filename);
25
25
 
26
- const { default: createRemote, AndroidTVSetup } = requireESM("./index.mjs");
26
+ const { default: createRemote } = requireESM("./index.mjs");
27
27
 
28
28
  module.exports = createRemote;
29
29
  module.exports.createRemote = createRemote;
30
- module.exports.AndroidTVSetup = AndroidTVSetup;
31
30
  module.exports.default = createRemote;
package/index.mjs CHANGED
@@ -22,4 +22,3 @@
22
22
 
23
23
  export { default } from "./src/lib/android-tv-remote.mjs";
24
24
  export { default as createRemote, createAndroidTVRemote } from "./src/lib/android-tv-remote.mjs";
25
- export { default as AndroidTVSetup } from "./src/lib/adb/setup.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cldmv/node-android-tv-remote",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
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": {
@@ -42,13 +42,25 @@
42
42
  },
43
43
  "homepage": "https://github.com/CLDMV/node-android-tv-remote#readme",
44
44
  "license": "MIT",
45
+ "files": [
46
+ "src/",
47
+ "scripts/",
48
+ "index.mjs",
49
+ "index.cjs",
50
+ "README.md",
51
+ "package.json"
52
+ ],
45
53
  "dependencies": {
46
- "@devicefarmer/adbkit": "^3.3.8"
54
+ "@devicefarmer/adbkit": "^3.3.8",
55
+ "sharp": "^0.34.4"
47
56
  },
48
57
  "devDependencies": {
49
58
  "jest": "^30.0.5"
50
59
  },
51
60
  "publishConfig": {
52
61
  "access": "public"
62
+ },
63
+ "engines": {
64
+ "node": "^18.17.0 || ^20.3.0 || >=21.0.0"
53
65
  }
54
66
  }
@@ -1,3 +1,16 @@
1
+ /**
2
+ * @Project: @cldmv/node-android-tv-remote
3
+ * @Filename: /scripts/postinstall.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-16 06:45:20 -07:00 (1760622320)
10
+ * -----
11
+ * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
+ */
13
+
1
14
  /**
2
15
  * Postinstall script to check for adb and print install instructions if missing.
3
16
  */
@@ -1,5 +1,15 @@
1
- #!/usr/bin/env node
2
-
1
+ /**
2
+ * @Project: @cldmv/node-android-tv-remote
3
+ * @Filename: /scripts/setup-device.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-16 06:45:06 -07:00 (1760622306)
10
+ * -----
11
+ * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
+ */
3
13
  import readline from "readline";
4
14
  import AndroidTVSetup from "../src/lib/adb/setup.mjs";
5
15
 
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @Project: @cldmv/node-android-tv-remote
3
+ * @Filename: /scripts/wake-tv.mjs
4
+ * @Date: 2025-10-15 20:44:49 -07:00 (1760586289)
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 20:46:13 -07:00 (1760586373)
10
+ * -----
11
+ * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
+ */
13
+
14
+ /**
15
+ * Wake up Android TV/Fire TV script
16
+ * Usage: node wake-tv.mjs <ip_address>
17
+ */
18
+
19
+ import createRemote from "../src/lib/android-tv-remote.mjs";
20
+
21
+ // Get IP address from command line arguments
22
+ const ip = process.argv[2];
23
+
24
+ if (!ip) {
25
+ console.error("❌ Usage: node wake-tv.mjs <ip_address>");
26
+ console.error(" Example: node wake-tv.mjs 10.6.0.133");
27
+ process.exit(1);
28
+ }
29
+
30
+ console.log(`🔌 Waking up TV at ${ip}...`);
31
+
32
+ try {
33
+ const remote = await createRemote({
34
+ ip: ip,
35
+ autoConnect: true,
36
+ quiet: false
37
+ });
38
+
39
+ console.log("✅ Connected to device");
40
+
41
+ // Wake up the device
42
+ await remote.ensureAwake();
43
+ console.log("🎉 TV should now be awake and ready!");
44
+
45
+ // Disconnect
46
+ await remote.disconnect();
47
+ console.log("✅ Disconnected from device");
48
+ } catch (error) {
49
+ console.error("❌ Failed to wake up TV:", error.message);
50
+ process.exit(1);
51
+ }
@@ -0,0 +1,73 @@
1
+ {
2
+ "a": "a",
3
+ "b": "b",
4
+ "c": "c",
5
+ "d": "d",
6
+ "e": "e",
7
+ "f": "f",
8
+ "g": "g",
9
+ "h": "h",
10
+ "i": "i",
11
+ "j": "j",
12
+ "k": "k",
13
+ "l": "l",
14
+ "m": "m",
15
+ "n": "n",
16
+ "o": "o",
17
+ "p": "p",
18
+ "q": "q",
19
+ "r": "r",
20
+ "s": "s",
21
+ "t": "t",
22
+ "u": "u",
23
+ "v": "v",
24
+ "w": "w",
25
+ "x": "x",
26
+ "y": "y",
27
+ "z": "z",
28
+ "0": "0",
29
+ "1": "1",
30
+ "2": "2",
31
+ "3": "3",
32
+ "4": "4",
33
+ "5": "5",
34
+ "6": "6",
35
+ "7": "7",
36
+ "8": "8",
37
+ "9": "9",
38
+ "space": " ",
39
+ "comma": ",",
40
+ "period": ".",
41
+ "semicolon": ";",
42
+ "apostrophe": "'",
43
+ "slash": "/",
44
+ "backslash": "\\",
45
+ "leftBracket": "[",
46
+ "rightBracket": "]",
47
+ "minus": "-",
48
+ "equals": "=",
49
+ "grave": "`",
50
+ "tab": "\t",
51
+ "enter": "\n",
52
+ "exclamation": "!",
53
+ "at": "@",
54
+ "hash": "#",
55
+ "dollar": "$",
56
+ "percent": "%",
57
+ "caret": "^",
58
+ "ampersand": "&",
59
+ "asterisk": "*",
60
+ "leftParen": "(",
61
+ "rightParen": ")",
62
+ "underscore": "_",
63
+ "plus": "+",
64
+ "leftBrace": "{",
65
+ "rightBrace": "}",
66
+ "pipe": "|",
67
+ "colon": ":",
68
+ "quote": "\"",
69
+ "lessThan": "<",
70
+ "greaterThan": ">",
71
+ "question": "?",
72
+ "tilde": "~"
73
+ }