@cldmv/node-android-tv-remote 1.4.0 → 1.5.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
|
@@ -441,7 +441,33 @@ module.exports = function (config) {
|
|
|
441
441
|
return !!connected;
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
-
|
|
444
|
+
/**
|
|
445
|
+
* Returns a list of all available keyboard key function names on the live API (keyboard.key).
|
|
446
|
+
* This inspects the actual keyboard.key object, so it always matches the real API surface, including all aliases and dynamic keys.
|
|
447
|
+
* @returns {string[]}
|
|
448
|
+
* @example
|
|
449
|
+
* remote.getKeyboardKeys();
|
|
450
|
+
*/
|
|
451
|
+
function getKeyboardKeys() {
|
|
452
|
+
// 'this' is not bound, so we must access the constructed keyboard.key object
|
|
453
|
+
// Only return the top-level key names (not .keycode or .shift)
|
|
454
|
+
if (!this || !this.keyboard || !this.keyboard.key) return [];
|
|
455
|
+
return Object.keys(this.keyboard.key).filter((k) => typeof this.keyboard.key[k] === "function");
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Returns a list of all available press command names on the live API (press object), including aliases and dynamic keys.
|
|
460
|
+
* This inspects the actual press object, so it always matches the real API surface.
|
|
461
|
+
* @returns {string[]}
|
|
462
|
+
* @example
|
|
463
|
+
* remote.getPressCommands();
|
|
464
|
+
*/
|
|
465
|
+
function getPressCommands() {
|
|
466
|
+
if (!this || !this.press) return [];
|
|
467
|
+
return Object.keys(this.press).filter((k) => k !== "long" && typeof this.press[k] === "function");
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const remoteApi = {
|
|
445
471
|
/**
|
|
446
472
|
* Returns the current connection status as tracked by the module, or does a live check if requested.
|
|
447
473
|
* @function
|
|
@@ -452,6 +478,24 @@ module.exports = function (config) {
|
|
|
452
478
|
* await remote.getConnectionStatus(true); // live check
|
|
453
479
|
*/
|
|
454
480
|
getConnectionStatus,
|
|
481
|
+
/**
|
|
482
|
+
* Returns a list of all available keyboard key function names on the live API (keyboard.key).
|
|
483
|
+
* @returns {string[]}
|
|
484
|
+
* @example
|
|
485
|
+
* remote.getKeyboardKeys();
|
|
486
|
+
*/
|
|
487
|
+
getKeyboardKeys: function () {
|
|
488
|
+
return getKeyboardKeys.call(remoteApi);
|
|
489
|
+
},
|
|
490
|
+
/**
|
|
491
|
+
* Returns a list of all available press command names on the live API (press object), including aliases and dynamic keys.
|
|
492
|
+
* @returns {string[]}
|
|
493
|
+
* @example
|
|
494
|
+
* remote.getPressCommands();
|
|
495
|
+
*/
|
|
496
|
+
getPressCommands: function () {
|
|
497
|
+
return getPressCommands.call(remoteApi);
|
|
498
|
+
},
|
|
455
499
|
/**
|
|
456
500
|
* Returns true if the module believes it is connected to the device.
|
|
457
501
|
* @readonly
|
|
@@ -761,4 +805,5 @@ module.exports = function (config) {
|
|
|
761
805
|
)
|
|
762
806
|
}
|
|
763
807
|
};
|
|
808
|
+
return remoteApi;
|
|
764
809
|
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test for getKeyboardKeys and getPressCommands methods of the android-tv-remote module.
|
|
3
|
+
*
|
|
4
|
+
* Usage: Run with `node test/api-surface.test.js`
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const assert = require("assert");
|
|
8
|
+
const createRemote = require("../src/lib/android-tv-remote");
|
|
9
|
+
|
|
10
|
+
// Minimal config for instantiation (no real device needed for API surface test)
|
|
11
|
+
const remote = createRemote({ ip: "127.0.0.1", autoConnect: false, maintainConnection: false, quiet: true });
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Test getKeyboardKeys returns all top-level function keys from keyboard.key
|
|
15
|
+
*/
|
|
16
|
+
function testGetKeyboardKeys() {
|
|
17
|
+
const keys = remote.getKeyboardKeys();
|
|
18
|
+
console.log("getKeyboardKeys:", keys);
|
|
19
|
+
assert(Array.isArray(keys), "getKeyboardKeys should return an array");
|
|
20
|
+
assert(keys.length > 0, "getKeyboardKeys should return at least one key");
|
|
21
|
+
// Spot check for some expected keys
|
|
22
|
+
["a", "enter", "space"].forEach((k) => {
|
|
23
|
+
assert(keys.includes(k), `getKeyboardKeys should include '${k}'`);
|
|
24
|
+
});
|
|
25
|
+
// Should not include 'shift' or 'keycode' (sub-objects)
|
|
26
|
+
assert(!keys.includes("shift"), "getKeyboardKeys should not include shift");
|
|
27
|
+
assert(!keys.includes("keycode"), "getKeyboardKeys should not include keycode");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Test getPressCommands returns all top-level function keys from press
|
|
32
|
+
*/
|
|
33
|
+
function testGetPressCommands() {
|
|
34
|
+
const keys = remote.getPressCommands();
|
|
35
|
+
console.log("getPressCommands:", keys);
|
|
36
|
+
assert(Array.isArray(keys), "getPressCommands should return an array");
|
|
37
|
+
assert(keys.length > 0, "getPressCommands should return at least one key");
|
|
38
|
+
// Spot check for some expected keys (may vary by remote-keys.json)
|
|
39
|
+
["home", "back", "ok", "up", "down", "left", "right"].forEach((k) => {
|
|
40
|
+
assert(keys.includes(k), `getPressCommands should include '${k}'`);
|
|
41
|
+
});
|
|
42
|
+
// Should not include 'long' (sub-object)
|
|
43
|
+
assert(!keys.includes("long"), "getPressCommands should not include long");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
console.log("Testing getKeyboardKeys...");
|
|
47
|
+
testGetKeyboardKeys();
|
|
48
|
+
console.log("Testing getPressCommands...");
|
|
49
|
+
testGetPressCommands();
|
|
50
|
+
console.log("All API surface tests passed.");
|