@cldmv/node-android-tv-remote 1.5.4 → 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 +1 -1
- package/src/lib/android-tv-remote.js +33 -1
package/package.json
CHANGED
|
@@ -167,7 +167,23 @@ module.exports = function (config) {
|
|
|
167
167
|
/**
|
|
168
168
|
* On initialization, check if already connected to the device and set internal state.
|
|
169
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.
|
|
170
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
|
+
});
|
|
171
187
|
(async () => {
|
|
172
188
|
try {
|
|
173
189
|
const status = await getConnectionStatus(true);
|
|
@@ -175,9 +191,18 @@ module.exports = function (config) {
|
|
|
175
191
|
connected = true;
|
|
176
192
|
if (!quiet) logWithTime("Already connected to " + host + " (on init)");
|
|
177
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
|
+
}
|
|
178
203
|
}
|
|
179
204
|
} catch (e) {
|
|
180
|
-
|
|
205
|
+
initPromiseReject(e);
|
|
181
206
|
}
|
|
182
207
|
})();
|
|
183
208
|
|
|
@@ -469,6 +494,13 @@ module.exports = function (config) {
|
|
|
469
494
|
}
|
|
470
495
|
|
|
471
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,
|
|
472
504
|
/**
|
|
473
505
|
* Returns the current connection status as tracked by the module, or does a live check if requested.
|
|
474
506
|
* @function
|