Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/contracts/src/tv-remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ test('Android TV hardware buttons map to their KeyEvent codes', () => {
sleep: '223',
wake: '224',
'media-play-pause': '85',
'media-play': '126',
'media-pause': '127',
'media-stop': '86',
'media-next': '87',
'media-previous': '88',
'media-rewind': '89',
Expand All @@ -71,7 +74,7 @@ test('Android TV hardware buttons map to their KeyEvent codes', () => {
for (const [button, code] of Object.entries(expected)) {
assert.equal(toAndroidTvRemoteKeyevent(parseTvRemoteButton(button)), code);
}
assert.equal(TV_REMOTE_BUTTONS.length, 30);
assert.equal(TV_REMOTE_BUTTONS.length, 33);
});

test('raw Android codes and named TV buttons normalize before dispatch', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/contracts/src/tv-remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const TV_REMOTE_BUTTON_DEFINITIONS = {
sleep: { aliases: [], androidKeyevent: '223' },
wake: { aliases: [], androidKeyevent: '224' },
'media-play-pause': { aliases: [], androidKeyevent: '85' },
'media-play': { aliases: [], androidKeyevent: '126' },
'media-pause': { aliases: [], androidKeyevent: '127' },
'media-stop': { aliases: [], androidKeyevent: '86' },
'media-next': { aliases: [], androidKeyevent: '87' },
'media-previous': { aliases: [], androidKeyevent: '88' },
'media-rewind': { aliases: [], androidKeyevent: '89' },
Expand Down
13 changes: 7 additions & 6 deletions packages/provider-tizen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Drive web apps on Samsung Tizen TVs with [agent-device](https://agent-device.dev
debug-launches the app over `sdb`, forwards its DevTools port, and drives the page over the Chrome
DevTools Protocol: remote keys, pointer, text, snapshots, screenshots and console logs.

Status: experimental. Verified on a Samsung Smart Monitor M7 (Tizen 9.0, packaged build of a React
Native Web app): `connect`, `open`, `open --relaunch`, `snapshot -i`, `tv-remote` (directions,
select, back), `back`, `is focused`, `press`, `find ... click`, `hover`, `longpress`, `fill`,
`type`, `wait`, `scroll`, `screenshot`, `logs`, `apps`, `appstate`, `close`, `disconnect`.
Status: experimental. Verified on a Samsung Smart Monitor M7 (Tizen 9.0): `connect`, `open`,
`open --relaunch`, `snapshot -i`, `tv-remote` (directions, select, back and the media buttons),
`back`, `is focused`, `press`, `find ... click`, `hover`, `longpress`, `fill`, `type`, `wait`,
`scroll`, `screenshot`, `logs`, `apps`, `appstate`, `close`, `disconnect`.

## How it plugs in

Expand Down Expand Up @@ -77,6 +77,7 @@ The TV is a leased device, so every command from `connect` to `disconnect` names
| --- | --- |
| `open` / `close` | `sdb shell 0 was_kill`, `sdb shell 0 debug` (prints the DevTools port), `sdb forward`, then CDP / `sdb shell 0 was_kill` |
| `tv-remote press up/down/left/right/select/back`, `back` | `Input.dispatchKeyEvent` with the Samsung remote codes (Back = `XF86Back`, 10009) |
| `tv-remote press media-play/media-pause/media-play-pause/media-stop/media-next/media-previous/media-rewind/media-fast-forward` | `Input.dispatchKeyEvent` with the Samsung media key codes (`MediaPlay` = 415, `MediaPause` = 19, `MediaPlayPause` = 10252, `MediaStop` = 413, `MediaTrackNext` = 10233, `MediaTrackPrevious` = 10232, `MediaRewind` = 412, `MediaFastForward` = 417) |
| `appstate` | the attached app while its page is visible |
| `apps` | `sdb shell 0 vd_applist`: user-installed apps with their titles |
| `logs` | console calls, exceptions and browser log entries of the attached page, one line each |
Expand All @@ -87,8 +88,8 @@ The TV is a leased device, so every command from `connect` to `disconnect` names
| `type` | `Input.insertText` into the focused element |
| `scroll` | `mouseWheel` at the centre of the scroll container or viewport, by the requested distance |

Not yet: system buttons (`home`, menu, volume, channel and media keys), `network dump`, `perf`,
`install` and `uninstall`, recording, URLs and deep links in `open`, `power`.
Not yet: system buttons (`home`, menu, volume and channel), `network dump`, `perf`, `install` and
`uninstall`, recording, URLs and deep links in `open`, `power`.

## Known limitations

Expand Down
6 changes: 5 additions & 1 deletion packages/provider-tizen/src/keys.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { NAVIGATION_KEYS, type RemoteKeys } from '@agent-device/tv-cdp';
import { MEDIA_KEYS, NAVIGATION_KEYS, type RemoteKeys } from '@agent-device/tv-cdp';

export const TIZEN_REMOTE_KEYS: RemoteKeys = {
...NAVIGATION_KEYS,
back: { key: 'XF86Back', code: 'XF86Back', keyCode: 10009 },
'media-play-pause': { key: 'MediaPlayPause', code: 'MediaPlayPause', keyCode: 10252 },
'media-next': { key: 'MediaTrackNext', code: 'MediaTrackNext', keyCode: 10233 },
'media-previous': { key: 'MediaTrackPrevious', code: 'MediaTrackPrevious', keyCode: 10232 },
...MEDIA_KEYS,
};
29 changes: 29 additions & 0 deletions packages/provider-tizen/src/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,32 @@ test('close kills the app on the leased TV', async () => {

assert.equal(calls().at(-1), `-s 192.0.2.10:26101 shell 0 was_kill ${APP_ID}`);
});

test('a remote button Tizen lacks is refused, listing the navigation, back and media buttons it accepts', async () => {
const { runtime } = await tizenRuntime(['192.0.2.10:26101']);
const allocated = await runtime.leaseLifecycle.allocate(lease('one'));
assert.ok(allocated);

const press = runtime.getInteractor(allocated.device)!.tvRemote!('home');

await assert.rejects(press, (error: AppError) => {
assert.equal(error.code, 'UNSUPPORTED_OPERATION');
assert.deepEqual(error.details?.supported, [
'up',
'down',
'left',
'right',
'select',
'back',
'media-play-pause',
'media-next',
'media-previous',
'media-play',
'media-pause',
'media-stop',
'media-rewind',
'media-fast-forward',
]);
return true;
});
});
11 changes: 7 additions & 4 deletions packages/provider-webos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Drive web apps on LG webOS TVs with [agent-device](https://agent-device.dev). Th
the app with the webOS CLI, opens the `ares-inspect` tunnel, and drives the page over the Chrome
DevTools Protocol: remote keys, pointer, text, snapshots, screenshots and console logs.

Status: experimental. Verified on an LG 32LQ63006LA (webOS TV 22, dev build of a React Native Web
app): `connect`, `open`, `snapshot -i`, `snapshot -s`, `tv-remote` (directions, select, back),
Status: experimental. Verified on an LG 32LQ63006LA (webOS TV 22): `connect`, `open`,
`snapshot -i`, `snapshot -s`, `tv-remote` (directions, select, back and the media buttons),
`is focused`, `press @ref --settle`, `wait text`, `find`, `screenshot`, `logs`, `apps`,
`appstate`, `close`, `disconnect`.

Expand Down Expand Up @@ -72,6 +72,7 @@ The TV is a leased device, so every command from `connect` to `disconnect` names
| --- | --- |
| `open` / `close` | `ares-launch` / `ares-launch --close`, then the `ares-inspect` tunnel |
| `tv-remote press up/down/left/right/select/back`, `back` | `Input.dispatchKeyEvent` with the LG remote codes (Back = 461) |
| `tv-remote press media-play/media-pause/media-stop/media-rewind/media-fast-forward` | `Input.dispatchKeyEvent` with the LG media key codes (Play = 415, Pause = 19, Stop = 413, Rewind = 412, Fast-forward = 417) |
| `appstate` | the attached app while its page is visible |
| `apps` | `ares-install --listfull` |
| `logs` | console calls, exceptions and browser log entries of the attached page, one line each |
Expand All @@ -82,8 +83,10 @@ The TV is a leased device, so every command from `connect` to `disconnect` names
| `type` | `Input.insertText` into the focused element |
| `scroll` | `mouseWheel` at the centre of the scroll container or viewport, by the requested distance |

Not yet: system buttons (`home`, menu, volume, channel and media keys), `network dump`, `perf`,
`install` and `uninstall`, recording, URLs and deep links in `open`, `power`.
Not yet: system buttons (`home`, menu, volume and channel), `media-play-pause`, `media-next` and
`media-previous`, `network dump`, `perf`, `install` and `uninstall`, recording, URLs and deep links
in `open`, `power`. webOS has separate Play and Pause key codes and no play-pause toggle, so
`media-play-pause` is refused; use `media-play` or `media-pause`.

## Known limitations

Expand Down
3 changes: 2 additions & 1 deletion packages/provider-webos/src/keys.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NAVIGATION_KEYS, type RemoteKeys } from '@agent-device/tv-cdp';
import { MEDIA_KEYS, NAVIGATION_KEYS, type RemoteKeys } from '@agent-device/tv-cdp';

export const WEBOS_REMOTE_KEYS: RemoteKeys = {
...NAVIGATION_KEYS,
back: { key: 'GoBack', code: 'BrowserBack', keyCode: 461 },
...MEDIA_KEYS,
};
27 changes: 27 additions & 0 deletions packages/provider-webos/src/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,30 @@ test('close stops the app with ares-launch --close', async () => {

assert.deepEqual(recordedCalls(), [`ares-launch -d bedroom --close ${APP_ID}`]);
});

test('media-play-pause is refused because webOS has no play-pause key, listing the buttons it accepts', async () => {
const runtime = await webosRuntime();
const allocated = await runtime.leaseLifecycle.allocate(lease('lease-a'));
assert.ok(allocated);

const press = runtime.getInteractor(allocated.device)!.tvRemote!('media-play-pause');

await assert.rejects(press, (error: unknown) => {
assert.ok(error instanceof AppError);
assert.equal(error.code, 'UNSUPPORTED_OPERATION');
assert.deepEqual(error.details?.supported, [
'up',
'down',
'left',
'right',
'select',
'back',
'media-play',
'media-pause',
'media-stop',
'media-rewind',
'media-fast-forward',
]);
return true;
});
});
2 changes: 1 addition & 1 deletion packages/tv-cdp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { TvRuntimeHost } from './runtime.ts';
import type { TvPlatform } from './tv.ts';

export { listTargets, withTunnelRemoval } from './cdp.ts';
export { NAVIGATION_KEYS, type RemoteKeys } from './keys.ts';
export { MEDIA_KEYS, NAVIGATION_KEYS, type RemoteKeys } from './keys.ts';
export type { TvRuntimeHost } from './runtime.ts';
export type { PageTunnel, TvConnection } from './tv.ts';

Expand Down
19 changes: 18 additions & 1 deletion packages/tv-cdp/src/keys.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import { test } from 'vitest';

import { keyEvents, NAVIGATION_KEYS } from './keys.ts';
import { keyEvents, MEDIA_KEYS, NAVIGATION_KEYS } from './keys.ts';

test('select sends Enter with text so a focused button receives a click', () => {
const [down, up] = keyEvents(NAVIGATION_KEYS.select);
Expand All @@ -10,3 +10,20 @@ test('select sends Enter with text so a focused button receives a click', () =>
assert.equal(down!.text, '\r');
assert.equal(up!.type, 'keyUp');
});

test.each([
['media-play', 'MediaPlay', 415],
['media-pause', 'MediaPause', 19],
['media-stop', 'MediaStop', 413],
['media-rewind', 'MediaRewind', 412],
['media-fast-forward', 'MediaFastForward', 417],
] as const)('%s sends the TV media key %s with key code %d and no text', (button, key, keyCode) => {
const media = { key, code: key, windowsVirtualKeyCode: keyCode, nativeVirtualKeyCode: keyCode };

const events = keyEvents(MEDIA_KEYS[button]);

assert.deepEqual(events, [
{ ...media, type: 'keyDown' },
{ ...media, type: 'keyUp' },
]);
});
8 changes: 8 additions & 0 deletions packages/tv-cdp/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export const NAVIGATION_KEYS = {
select: { key: 'Enter', code: 'Enter', keyCode: 13, text: '\r' },
} as const satisfies RemoteKeys;

export const MEDIA_KEYS = {
'media-play': { key: 'MediaPlay', code: 'MediaPlay', keyCode: 415 },
'media-pause': { key: 'MediaPause', code: 'MediaPause', keyCode: 19 },
'media-stop': { key: 'MediaStop', code: 'MediaStop', keyCode: 413 },
'media-rewind': { key: 'MediaRewind', code: 'MediaRewind', keyCode: 412 },
'media-fast-forward': { key: 'MediaFastForward', code: 'MediaFastForward', keyCode: 417 },
} as const satisfies RemoteKeys;

export function supportedRemoteButtons(keys: RemoteKeys): readonly TvRemoteButton[] {
return Object.keys(keys) as TvRemoteButton[];
}
Expand Down
5 changes: 3 additions & 2 deletions src/commands/schema/cli-help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,10 @@ Vega OS:

Buttons:
Examples: tv-remote longpress select; tv-remote press select --duration-ms 500. Syntax: tv-remote [press|longpress] <button> [--duration-ms <ms>]
All TV backends: up, down, left, right, select, menu, home, back.
Android TV also accepts volume-up, volume-down, mute, power, sleep, wake, media-play-pause, media-next, media-previous, media-rewind, media-fast-forward, channel-up, channel-down, last-channel, guide, info, captions, tv-input, color-red, color-green, color-yellow, and color-blue.
Android TV, tvOS, and Vega OS: up, down, left, right, select, menu, home, back.
Android TV also accepts volume-up, volume-down, mute, power, sleep, wake, media-play-pause, media-play, media-pause, media-stop, media-next, media-previous, media-rewind, media-fast-forward, channel-up, channel-down, last-channel, guide, info, captions, tv-input, color-red, color-green, color-yellow, and color-blue.
android-keycode:<n> sends a raw Android TV keycode from 1 to 2147483647. tvOS and Vega OS refuse these additional buttons. Phones and WebDriver sessions refuse tv-remote. Power and sleep can turn the screen off; success confirms dispatch without waiting for an app or screen change.
The LG webOS and Samsung Tizen plugins accept up, down, left, right, select, back, media-play, media-pause, media-stop, media-rewind, and media-fast-forward; Tizen also accepts media-play-pause, media-next, and media-previous. They refuse every other button.
ok, center, and enter are input aliases for select; command output still reports button: "select".
longpress is CLI sugar for --duration-ms 500. --duration-ms overrides that preset.
--duration-ms holds a tvOS or Vega OS remote button for that exact duration. On Android TV, any positive duration maps to the ADB longpress form because Android input keyevent has no exact hold duration.
Expand Down
3 changes: 3 additions & 0 deletions src/mcp/__tests__/command-tools-system-schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ const NAVIGATION_DISPATCH_SHAPES: Readonly<
'sleep',
'wake',
'media-play-pause',
'media-play',
'media-pause',
'media-stop',
'media-next',
'media-previous',
'media-rewind',
Expand Down
2 changes: 1 addition & 1 deletion website/docs/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ vega virtual-device stop
- TV targets include Apple TV and Android TV simulators, emulators, and connected devices, plus Fire TV devices and emulators running Fire OS (Android-based). Vega OS support is limited to the Vega Virtual Device (VVD).
- TV targets are focus-first: move focus with `tv-remote` before selecting a control. Don't use raw `adb shell input keyevent` in command plans.
- `tv-remote` is TV-only. Android phones, iPhones, and WebDriver (Appium) sessions refuse it with `UNSUPPORTED_OPERATION`.
- All three TV backends support `up`, `down`, `left`, `right`, `select`, `menu`, `home`, and `back`. Android TV also accepts `volume-up`, `volume-down`, `mute`, `power`, `sleep`, `wake`, `media-play-pause`, `media-next`, `media-previous`, `media-rewind`, `media-fast-forward`, `channel-up`, `channel-down`, `last-channel`, `guide`, `info`, `captions`, `tv-input`, `color-red`, `color-green`, `color-yellow`, and `color-blue`. tvOS and Vega OS refuse the additional buttons before dispatch.
- All three TV backends support `up`, `down`, `left`, `right`, `select`, `menu`, `home`, and `back`. Android TV also accepts `volume-up`, `volume-down`, `mute`, `power`, `sleep`, `wake`, `media-play-pause`, `media-play`, `media-pause`, `media-stop`, `media-next`, `media-previous`, `media-rewind`, `media-fast-forward`, `channel-up`, `channel-down`, `last-channel`, `guide`, `info`, `captions`, `tv-input`, `color-red`, `color-green`, `color-yellow`, and `color-blue`. tvOS and Vega OS refuse the additional buttons before dispatch.
- For an Android TV remote button without a name, use `android-keycode:<n>` with a decimal code from 1 to 2147483647. Other TV backends refuse raw Android codes. An unknown name or invalid code fails with `INVALID_ARGS`.
- `power` and `sleep` can turn the screen off. A successful response confirms that the button was sent; it does not verify playback, volume, or display state, and it does not wait for the app to settle.
- Android TV: app listing reads `LEANBACK_LAUNCHER` and `LAUNCHER` activities together; app launch prefers `LEANBACK_LAUNCHER` and falls back to `LAUNCHER` when the app declares no leanback activity. `tv-remote` sends ADB keyevents; `longpress <button>` selects the long-press preset, and any positive `--duration-ms` uses Android's longpress keyevent, which has no exact hold time.
Expand Down
5 changes: 3 additions & 2 deletions website/docs/docs/tizen.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Every command on that device goes to the plugin, never to adb.
| --- | --- |
| `open` / `close` | `sdb shell 0 was_kill`, `sdb shell 0 debug`, and `sdb forward`, then CDP / `sdb shell 0 was_kill` |
| `tv-remote press up/down/left/right/select/back`, `back` | `Input.dispatchKeyEvent` with the Samsung remote codes |
| `tv-remote press media-play/media-pause/media-play-pause/media-stop/media-next/media-previous/media-rewind/media-fast-forward` | `Input.dispatchKeyEvent` with the Samsung media key codes |
| `appstate` | The attached app while its page is visible |
| `apps` | `sdb shell 0 vd_applist` |
| `logs` | Console calls, exceptions, and browser log entries of the attached page, one line each |
Expand All @@ -81,8 +82,8 @@ Every command on that device goes to the plugin, never to adb.
| `type` | `Input.insertText` into the focused element |
| `scroll` | `mouseWheel` at the centre of the scroll container or the viewport, by the requested distance |

Not supported yet: system buttons (`home`, menu, volume, channel, and media keys), `network dump`,
`perf`, `install` and `uninstall`, recording, URLs and deep links in `open`, and `power`.
Not supported yet: system buttons (`home`, menu, volume, and channel), `network dump`, `perf`,
`install` and `uninstall`, recording, URLs and deep links in `open`, and `power`.

## Known limitations

Expand Down
7 changes: 5 additions & 2 deletions website/docs/docs/webos.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ plugin, never to adb.
| --- | --- |
| `open` / `close` | `ares-launch` / `ares-launch --close`, then the `ares-inspect` tunnel |
| `tv-remote press up/down/left/right/select/back`, `back` | `Input.dispatchKeyEvent` with the LG remote codes |
| `tv-remote press media-play/media-pause/media-stop/media-rewind/media-fast-forward` | `Input.dispatchKeyEvent` with the LG media key codes |
| `appstate` | The attached app while its page is visible |
| `apps` | `ares-install --listfull` |
| `logs` | Console calls, exceptions, and browser log entries of the attached page, one line each |
Expand All @@ -81,8 +82,10 @@ plugin, never to adb.
| `type` | `Input.insertText` into the focused element |
| `scroll` | `mouseWheel` at the centre of the scroll container or the viewport, by the requested distance |

Not supported yet: system buttons (`home`, menu, volume, channel, and media keys), `network dump`,
`perf`, `install` and `uninstall`, recording, URLs and deep links in `open`, and `power`.
Not supported yet: system buttons (`home`, menu, volume, and channel), `media-play-pause`,
`media-next` and `media-previous`, `network dump`, `perf`, `install` and `uninstall`, recording,
URLs and deep links in `open`, and `power`. webOS has separate Play and Pause key codes and no
play-pause toggle, so `media-play-pause` is refused; use `media-play` or `media-pause`.

## Known limitations

Expand Down
Loading