@cldmv/node-android-tv-remote 1.5.0 → 1.5.2
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,9 @@ module.exports = function (config) {
|
|
|
503
498
|
* @example
|
|
504
499
|
* if (remote.isConnected) { ... }
|
|
505
500
|
*/
|
|
506
|
-
isConnected
|
|
501
|
+
get isConnected() {
|
|
502
|
+
return isConnected();
|
|
503
|
+
},
|
|
507
504
|
/**
|
|
508
505
|
* Get or set Android settings via ADB.
|
|
509
506
|
* @public
|
|
@@ -567,16 +564,26 @@ module.exports = function (config) {
|
|
|
567
564
|
* @public
|
|
568
565
|
* @param {function(Error=, any=)=} [cb]
|
|
569
566
|
* @returns {Promise|undefined}
|
|
567
|
+
* @example
|
|
568
|
+
* await remote.connect();
|
|
569
|
+
* remote.connect((err) => { ... });
|
|
570
570
|
*/
|
|
571
|
-
connect:
|
|
571
|
+
connect: /**
|
|
572
|
+
* @type {(cb?: (err?: Error, result?: any) => any) => Promise<any> | undefined}
|
|
573
|
+
*/ (connectWrapped),
|
|
572
574
|
|
|
573
575
|
/**
|
|
574
576
|
* Disconnect from the device. Supports both promise and callback styles.
|
|
575
577
|
* @public
|
|
576
578
|
* @param {function(Error=, any=)=} [cb]
|
|
577
579
|
* @returns {Promise|undefined}
|
|
580
|
+
* @example
|
|
581
|
+
* await remote.disconnect();
|
|
582
|
+
* remote.disconnect((err) => { ... });
|
|
578
583
|
*/
|
|
579
|
-
disconnect:
|
|
584
|
+
disconnect: /**
|
|
585
|
+
* @type {(cb?: (err?: Error, result?: any) => any) => Promise<any> | undefined}
|
|
586
|
+
*/ (disconnectWrapped),
|
|
580
587
|
|
|
581
588
|
/**
|
|
582
589
|
* Send a keycode. Supports both promise and callback styles.
|
|
@@ -584,8 +591,13 @@ module.exports = function (config) {
|
|
|
584
591
|
* @param {number} code
|
|
585
592
|
* @param {function(Error=, any=)=} [cb]
|
|
586
593
|
* @returns {Promise|undefined}
|
|
594
|
+
* @example
|
|
595
|
+
* await remote.inputKeycode(23);
|
|
596
|
+
* remote.inputKeycode(23, (err) => { ... });
|
|
587
597
|
*/
|
|
588
|
-
inputKeycode:
|
|
598
|
+
inputKeycode: /**
|
|
599
|
+
* @type {(code: number, cb?: (err?: Error, result?: any) => any) => Promise<any> | undefined}
|
|
600
|
+
*/ (inputKeycodeWrapped),
|
|
589
601
|
|
|
590
602
|
/**
|
|
591
603
|
* 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
|
}
|