@cldmv/node-android-tv-remote 1.5.2 → 1.5.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cldmv/node-android-tv-remote",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "A Node.js library for controlling Android TV devices via ADB keycodes and text input.",
5
5
  "main": "src/lib/android-tv-remote.js",
6
6
  "scripts": {
File without changes
@@ -103,6 +103,7 @@ function handleDisconnectError(err) {
103
103
  errorWithTime(
104
104
  "Tip: In Developer Options on your TV, try toggling 'ADB Debugging' off and then back on. This often resolves authentication issues."
105
105
  );
106
+ process.exit(1);
106
107
  }
107
108
  if (err.message && (err.message.includes("actively refused") || err.message.includes("No connection could be made"))) {
108
109
  errorWithTime("\nThe device refused the connection. To enable ADB, follow these steps on your Android TV or Fire TV:");
@@ -114,8 +115,9 @@ function handleDisconnectError(err) {
114
115
  errorWithTime("6. On your computer, run: adb connect <device-ip>:5555");
115
116
  errorWithTime("7. Accept the authorization prompt on your TV");
116
117
  errorWithTime("\nIf you do not see 'Developer Options', repeat step 2 until it appears.");
118
+ process.exit(1);
117
119
  }
118
- process.exit(1);
120
+ return err;
119
121
  }
120
122
 
121
123
  /**
@@ -284,9 +286,9 @@ module.exports = function (config) {
284
286
  if (!quiet) warnWithTime("Warning: Device already connected.");
285
287
  connected = true;
286
288
  startHeartbeat();
287
- return;
289
+ return true;
288
290
  }
289
- handleDisconnectError(err);
291
+ return handleDisconnectError(err);
290
292
  });
291
293
  }
292
294
  const connectWrapped = wrapAsync(connect);
@@ -308,14 +310,15 @@ module.exports = function (config) {
308
310
  .then(function () {
309
311
  connected = false;
310
312
  if (!quiet) logWithTime("Disconnected from " + host);
313
+ return true;
311
314
  })
312
315
  .catch(function (err) {
313
316
  if (err.message && err.message.includes("disconnected")) {
314
317
  if (!quiet) warnWithTime("Warning: Device already disconnected before explicit disconnect call.");
315
318
  connected = false;
316
- return;
319
+ return true;
317
320
  }
318
- handleDisconnectError(err);
321
+ return handleDisconnectError(err);
319
322
  });
320
323
  }
321
324
  const disconnectWrapped = wrapAsync(disconnect);
@@ -403,6 +406,7 @@ module.exports = function (config) {
403
406
  /**
404
407
  * Returns the current connection status as tracked by the module.
405
408
  * Optionally performs a live check against adb devices if requested.
409
+ * Also updates the internal connected state if a live check is performed.
406
410
  * @public
407
411
  * @param {boolean} [liveCheck=false] - If true, checks adb devices for actual connection.
408
412
  * @returns {Promise<"connected"|"disconnected"|"unknown">}
@@ -418,8 +422,10 @@ module.exports = function (config) {
418
422
  const devices = await client.listDevices();
419
423
  const deviceId = host;
420
424
  const found = devices.some((d) => d.id === deviceId);
425
+ connected = found; // Keep internal state in sync with live check
421
426
  return found ? "connected" : "disconnected";
422
427
  } catch {
428
+ connected = false;
423
429
  return "unknown";
424
430
  }
425
431
  }
@@ -554,7 +560,7 @@ module.exports = function (config) {
554
560
  if (err.message && err.message.includes("disconnected")) {
555
561
  if (!useQuiet) warnWithTime("Warning: Device already disconnected before explicit disconnect call.");
556
562
  } else {
557
- handleDisconnectError(err);
563
+ return handleDisconnectError(err);
558
564
  }
559
565
  });
560
566
  },
@@ -3,7 +3,7 @@
3
3
  // Usage: node test/interactive-remote.js
4
4
 
5
5
  const readline = require("readline");
6
- const remote = require("../src/lib/android-tv-remote");
6
+ const createRemote = require("../src/lib/android-tv-remote");
7
7
 
8
8
  /**
9
9
  * Prompts the user for input in the terminal.
@@ -36,7 +36,8 @@ async function main() {
36
36
  process.exit(1);
37
37
  }
38
38
  try {
39
- await remote.connect({ ip, port });
39
+ const remote = createRemote({ ip, port });
40
+ await remote.connect();
40
41
  console.log(`Connected to ${ip}:${port}`);
41
42
  // List of buttons to press (as method names on remote.press)
42
43
  const buttons = ["home", "up", "down", "left", "right", "ok", "back"];