@cldmv/node-android-tv-remote 1.5.3 → 1.5.5

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.3",
3
+ "version": "1.5.5",
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
  /**
@@ -165,7 +167,23 @@ module.exports = function (config) {
165
167
  /**
166
168
  * On initialization, check if already connected to the device and set internal state.
167
169
  * This ensures the internal state is correct if the device is already connected.
170
+ * Expose a promise (initPromise) that resolves or rejects based on the result.
168
171
  */
172
+ /**
173
+ * Internal resolve/reject for initPromise, always defined as functions.
174
+ */
175
+ let initPromiseResolve = (_v) => {};
176
+ let initPromiseReject = (_e) => {};
177
+ /**
178
+ * Promise that resolves if initial auto-connect succeeds, or rejects if it fails.
179
+ * @type {Promise<void>}
180
+ * @example
181
+ * remote.initPromise.then(() => { ... }).catch((err) => { ... });
182
+ */
183
+ const initPromise = new Promise((resolve, reject) => {
184
+ initPromiseResolve = resolve;
185
+ initPromiseReject = reject;
186
+ });
169
187
  (async () => {
170
188
  try {
171
189
  const status = await getConnectionStatus(true);
@@ -173,9 +191,18 @@ module.exports = function (config) {
173
191
  connected = true;
174
192
  if (!quiet) logWithTime("Already connected to " + host + " (on init)");
175
193
  startHeartbeat();
194
+ initPromiseResolve();
195
+ } else {
196
+ // Try to connect if not already connected
197
+ await connect();
198
+ if (connected) {
199
+ initPromiseResolve();
200
+ } else {
201
+ initPromiseReject(new Error("Failed to connect to device on initialization."));
202
+ }
176
203
  }
177
204
  } catch (e) {
178
- // Ignore errors on init
205
+ initPromiseReject(e);
179
206
  }
180
207
  })();
181
208
 
@@ -284,9 +311,9 @@ module.exports = function (config) {
284
311
  if (!quiet) warnWithTime("Warning: Device already connected.");
285
312
  connected = true;
286
313
  startHeartbeat();
287
- return;
314
+ return true;
288
315
  }
289
- handleDisconnectError(err);
316
+ return handleDisconnectError(err);
290
317
  });
291
318
  }
292
319
  const connectWrapped = wrapAsync(connect);
@@ -308,14 +335,15 @@ module.exports = function (config) {
308
335
  .then(function () {
309
336
  connected = false;
310
337
  if (!quiet) logWithTime("Disconnected from " + host);
338
+ return true;
311
339
  })
312
340
  .catch(function (err) {
313
341
  if (err.message && err.message.includes("disconnected")) {
314
342
  if (!quiet) warnWithTime("Warning: Device already disconnected before explicit disconnect call.");
315
343
  connected = false;
316
- return;
344
+ return true;
317
345
  }
318
- handleDisconnectError(err);
346
+ return handleDisconnectError(err);
319
347
  });
320
348
  }
321
349
  const disconnectWrapped = wrapAsync(disconnect);
@@ -466,6 +494,13 @@ module.exports = function (config) {
466
494
  }
467
495
 
468
496
  const remoteApi = {
497
+ /**
498
+ * Promise that resolves if initial auto-connect succeeds, or rejects if it fails.
499
+ * @type {Promise<void>}
500
+ * @example
501
+ * remote.initPromise.then(() => { ... }).catch((err) => { ... });
502
+ */
503
+ initPromise,
469
504
  /**
470
505
  * Returns the current connection status as tracked by the module, or does a live check if requested.
471
506
  * @function
@@ -557,7 +592,7 @@ module.exports = function (config) {
557
592
  if (err.message && err.message.includes("disconnected")) {
558
593
  if (!useQuiet) warnWithTime("Warning: Device already disconnected before explicit disconnect call.");
559
594
  } else {
560
- handleDisconnectError(err);
595
+ return handleDisconnectError(err);
561
596
  }
562
597
  });
563
598
  },