@cldmv/node-android-tv-remote 1.5.0 → 1.5.1
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
package/src/data/keycodes.json
CHANGED
|
@@ -266,5 +266,10 @@
|
|
|
266
266
|
"systemNavigationUp": 280,
|
|
267
267
|
"systemNavigationDown": 281,
|
|
268
268
|
"systemNavigationLeft": 282,
|
|
269
|
-
"systemNavigationRight": 283
|
|
269
|
+
"systemNavigationRight": 283,
|
|
270
|
+
"azmNetflix": 290,
|
|
271
|
+
"azmPrime": 291,
|
|
272
|
+
"azmDirecttv": 292,
|
|
273
|
+
"azmPeacock": 296,
|
|
274
|
+
"azmGuide": 297
|
|
270
275
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"home",
|
|
3
3
|
"wakeup",
|
|
4
4
|
"back",
|
|
5
|
+
"recall",
|
|
5
6
|
"menu",
|
|
6
7
|
"ok",
|
|
7
8
|
"select",
|
|
@@ -76,5 +77,10 @@
|
|
|
76
77
|
"mediaStepForward",
|
|
77
78
|
"mediaStepBackward",
|
|
78
79
|
"mediaAudioTrack",
|
|
79
|
-
"mediaTopMenu"
|
|
80
|
+
"mediaTopMenu",
|
|
81
|
+
"azmNetflix",
|
|
82
|
+
"azmPrime",
|
|
83
|
+
"azmDirecttv",
|
|
84
|
+
"azmPeacock",
|
|
85
|
+
"azmGuide"
|
|
80
86
|
]
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* Android TV Remote module.
|
|
3
4
|
* @module android-tv-remote
|
|
@@ -137,36 +138,13 @@ const remoteKeys = require("../data/remote-keys.json");
|
|
|
137
138
|
* @function
|
|
138
139
|
* @public
|
|
139
140
|
* @param {RemoteConfig} config - Configuration for the remote.
|
|
140
|
-
* @param {boolean} [config.maintainConnection=true] - Whether to maintain the ADB connection with a heartbeat.
|
|
141
|
-
* @param {number} [config.heartbeatInterval=30000] - Heartbeat interval in ms (default 30s).
|
|
142
141
|
* @returns {Remote}
|
|
143
142
|
*/
|
|
144
143
|
module.exports = function (config) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
})();
|
|
161
|
-
/**
|
|
162
|
-
* @type {RemoteConfig}
|
|
163
|
-
*/
|
|
164
|
-
/**
|
|
165
|
-
* Initializes and configures the Android TV Remote instance.
|
|
166
|
-
* Handles connection, persistent heartbeat, and auto-reconnect logic.
|
|
167
|
-
* @returns {Remote}
|
|
168
|
-
*/
|
|
169
|
-
config = config || {};
|
|
144
|
+
// Ensure config is an object and has the required 'ip' property
|
|
145
|
+
if (!config || typeof config !== "object" || !config.ip) {
|
|
146
|
+
throw new Error("Missing required 'ip' property in RemoteConfig.");
|
|
147
|
+
}
|
|
170
148
|
const ip = config.ip;
|
|
171
149
|
const port = config.port || 5555;
|
|
172
150
|
const inputDevice = config.inputDevice || "/dev/input/event0";
|
|
@@ -184,6 +162,23 @@ module.exports = function (config) {
|
|
|
184
162
|
const heartbeatInterval = typeof config.heartbeatInterval === "number" ? config.heartbeatInterval : 30000;
|
|
185
163
|
let heartbeatTimer = null;
|
|
186
164
|
|
|
165
|
+
/**
|
|
166
|
+
* On initialization, check if already connected to the device and set internal state.
|
|
167
|
+
* This ensures the internal state is correct if the device is already connected.
|
|
168
|
+
*/
|
|
169
|
+
(async () => {
|
|
170
|
+
try {
|
|
171
|
+
const status = await getConnectionStatus(true);
|
|
172
|
+
if (status === "connected") {
|
|
173
|
+
connected = true;
|
|
174
|
+
if (!quiet) logWithTime("Already connected to " + host + " (on init)");
|
|
175
|
+
startHeartbeat();
|
|
176
|
+
}
|
|
177
|
+
} catch (e) {
|
|
178
|
+
// Ignore errors on init
|
|
179
|
+
}
|
|
180
|
+
})();
|
|
181
|
+
|
|
187
182
|
/**
|
|
188
183
|
* Resets the disconnect timer if autoDisconnect is enabled.
|
|
189
184
|
* Disconnects after inactivity if enabled.
|
|
@@ -503,7 +498,7 @@ module.exports = function (config) {
|
|
|
503
498
|
* @example
|
|
504
499
|
* if (remote.isConnected) { ... }
|
|
505
500
|
*/
|
|
506
|
-
isConnected,
|
|
501
|
+
isConnected: isConnected(),
|
|
507
502
|
/**
|
|
508
503
|
* Get or set Android settings via ADB.
|
|
509
504
|
* @public
|
|
@@ -567,16 +562,26 @@ module.exports = function (config) {
|
|
|
567
562
|
* @public
|
|
568
563
|
* @param {function(Error=, any=)=} [cb]
|
|
569
564
|
* @returns {Promise|undefined}
|
|
565
|
+
* @example
|
|
566
|
+
* await remote.connect();
|
|
567
|
+
* remote.connect((err) => { ... });
|
|
570
568
|
*/
|
|
571
|
-
connect:
|
|
569
|
+
connect: /**
|
|
570
|
+
* @type {(cb?: (err?: Error, result?: any) => any) => Promise<any> | undefined}
|
|
571
|
+
*/ (connectWrapped),
|
|
572
572
|
|
|
573
573
|
/**
|
|
574
574
|
* Disconnect from the device. Supports both promise and callback styles.
|
|
575
575
|
* @public
|
|
576
576
|
* @param {function(Error=, any=)=} [cb]
|
|
577
577
|
* @returns {Promise|undefined}
|
|
578
|
+
* @example
|
|
579
|
+
* await remote.disconnect();
|
|
580
|
+
* remote.disconnect((err) => { ... });
|
|
578
581
|
*/
|
|
579
|
-
disconnect:
|
|
582
|
+
disconnect: /**
|
|
583
|
+
* @type {(cb?: (err?: Error, result?: any) => any) => Promise<any> | undefined}
|
|
584
|
+
*/ (disconnectWrapped),
|
|
580
585
|
|
|
581
586
|
/**
|
|
582
587
|
* Send a keycode. Supports both promise and callback styles.
|
|
@@ -584,8 +589,13 @@ module.exports = function (config) {
|
|
|
584
589
|
* @param {number} code
|
|
585
590
|
* @param {function(Error=, any=)=} [cb]
|
|
586
591
|
* @returns {Promise|undefined}
|
|
592
|
+
* @example
|
|
593
|
+
* await remote.inputKeycode(23);
|
|
594
|
+
* remote.inputKeycode(23, (err) => { ... });
|
|
587
595
|
*/
|
|
588
|
-
inputKeycode:
|
|
596
|
+
inputKeycode: /**
|
|
597
|
+
* @type {(code: number, cb?: (err?: Error, result?: any) => any) => Promise<any> | undefined}
|
|
598
|
+
*/ (inputKeycodeWrapped),
|
|
589
599
|
|
|
590
600
|
/**
|
|
591
601
|
* All remote key functions support both promise and callback styles.
|
|
@@ -4,6 +4,7 @@ const Remote = require("../src/lib/android-tv-remote");
|
|
|
4
4
|
const TEST_IP = process.env.ANDROID_TV_IP || "192.168.1.100";
|
|
5
5
|
const TEST_PORT = process.env.ANDROID_TV_PORT ? parseInt(process.env.ANDROID_TV_PORT, 10) : 5555;
|
|
6
6
|
|
|
7
|
+
/** @type {import('../src/lib/android-tv-remote').RemoteConfig} */
|
|
7
8
|
const config = {
|
|
8
9
|
ip: TEST_IP,
|
|
9
10
|
port: TEST_PORT,
|
package/test/connect-readall.js
CHANGED
|
@@ -16,27 +16,18 @@ async function main() {
|
|
|
16
16
|
|
|
17
17
|
if (!quiet) console.log(`Running in ${mode} mode on ${ip}:${port}`);
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
}
|
|
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
|
+
}
|
|
40
31
|
|
|
41
32
|
if (!quiet) console.log(`Ran in ${mode} mode on ${ip}:${port}`);
|
|
42
33
|
}
|