@cldmv/node-android-tv-remote 1.2.0 → 1.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cldmv/node-android-tv-remote",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
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": {
@@ -41,5 +41,38 @@
41
41
  "number6",
42
42
  "number7",
43
43
  "number8",
44
- "number9"
44
+ "number9",
45
+ "numpad0",
46
+ "numpad1",
47
+ "numpad2",
48
+ "numpad3",
49
+ "numpad4",
50
+ "numpad5",
51
+ "numpad6",
52
+ "numpad7",
53
+ "numpad8",
54
+ "numpad9",
55
+ "numpadDivide",
56
+ "numpadMultiply",
57
+ "numpadSubtract",
58
+ "numpadAdd",
59
+ "numpadDot",
60
+ "numpadComma",
61
+ "numpadEnter",
62
+ "numpadEquals",
63
+ "numpadLeftParen",
64
+ "numpadRightParen",
65
+ "pageUp",
66
+ "pageDown",
67
+ "mediaPlay",
68
+ "mediaPause",
69
+ "mediaClose",
70
+ "mediaEject",
71
+ "mediaRecord",
72
+ "mediaSkipForward",
73
+ "mediaSkipBackward",
74
+ "mediaStepForward",
75
+ "mediaStepBackward",
76
+ "mediaAudioTrack",
77
+ "mediaTopMenu"
45
78
  ]
@@ -142,6 +142,22 @@ const remoteKeys = require("../data/remote-keys.json");
142
142
  * @returns {Remote}
143
143
  */
144
144
  module.exports = function (config) {
145
+ /**
146
+ * On initialization, check if already connected to the device and set internal state.
147
+ * This ensures the internal state is correct if the device is already connected.
148
+ */
149
+ (async () => {
150
+ try {
151
+ const status = await getConnectionStatus(true);
152
+ if (status === "connected") {
153
+ connected = true;
154
+ if (!quiet) logWithTime("Already connected to " + host + " (on init)");
155
+ startHeartbeat();
156
+ }
157
+ } catch (e) {
158
+ // Ignore errors on init
159
+ }
160
+ })();
145
161
  /**
146
162
  * @type {RemoteConfig}
147
163
  */
@@ -250,12 +266,17 @@ module.exports = function (config) {
250
266
  }
251
267
 
252
268
  /**
253
- * Connects to the ADB device and starts heartbeat/connection check.
254
- * Handles already-connected state gracefully.
255
- * @internal
269
+ * Connects to the ADB device if not already connected.
270
+ * Checks the internal connection state before connecting.
256
271
  * @returns {Promise<void>}
272
+ * @example
273
+ * await remote.connect(); // Only connects if not already connected
257
274
  */
258
275
  function connect() {
276
+ if (connected) {
277
+ if (!quiet) logWithTime("Already connected to " + host);
278
+ return Promise.resolve();
279
+ }
259
280
  return client
260
281
  .connect(ip, port)
261
282
  .then(function () {
@@ -16,18 +16,27 @@ async function main() {
16
16
 
17
17
  if (!quiet) console.log(`Running in ${mode} mode on ${ip}:${port}`);
18
18
 
19
- const setup = new AndroidTVSetup({ ip, port, quiet });
20
- try {
21
- await setup.connect();
22
- if (mode === "set") {
23
- await setup.setSettings();
24
- }
25
- await setup.ensureAwake();
26
- await setup.disconnect();
27
- } catch (err) {
28
- setup.errorWithTime("Error:", err.message || err);
29
- process.exit(1);
30
- }
19
+ const setup = new AndroidTVSetup({ ip, port, quiet });
20
+ try {
21
+ /**
22
+ * Check if already connected to the device. If not, connect.
23
+ * @returns {Promise<void>}
24
+ */
25
+ const isConnected = typeof setup.isConnected === 'function' ? await setup.isConnected() : false;
26
+ if (!isConnected) {
27
+ await setup.connect();
28
+ } else if (!quiet) {
29
+ console.log(`Already connected to ${ip}:${port}`);
30
+ }
31
+ if (mode === "set") {
32
+ await setup.setSettings();
33
+ }
34
+ await setup.ensureAwake();
35
+ await setup.disconnect();
36
+ } catch (err) {
37
+ setup.errorWithTime("Error:", err.message || err);
38
+ process.exit(1);
39
+ }
31
40
 
32
41
  if (!quiet) console.log(`Ran in ${mode} mode on ${ip}:${port}`);
33
42
  }