diff --git a/packages/contracts/src/tv-remote.test.ts b/packages/contracts/src/tv-remote.test.ts index a1c5c8de27..3e62d91133 100644 --- a/packages/contracts/src/tv-remote.test.ts +++ b/packages/contracts/src/tv-remote.test.ts @@ -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', @@ -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', () => { diff --git a/packages/contracts/src/tv-remote.ts b/packages/contracts/src/tv-remote.ts index b3b6955b76..16acd31170 100644 --- a/packages/contracts/src/tv-remote.ts +++ b/packages/contracts/src/tv-remote.ts @@ -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' }, diff --git a/packages/provider-tizen/README.md b/packages/provider-tizen/README.md index 76feed07bb..8b6ccfdbb3 100644 --- a/packages/provider-tizen/README.md +++ b/packages/provider-tizen/README.md @@ -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 @@ -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 | @@ -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 diff --git a/packages/provider-tizen/src/keys.ts b/packages/provider-tizen/src/keys.ts index aa524b3f05..14145d6816 100644 --- a/packages/provider-tizen/src/keys.ts +++ b/packages/provider-tizen/src/keys.ts @@ -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, }; diff --git a/packages/provider-tizen/src/runtime.test.ts b/packages/provider-tizen/src/runtime.test.ts index 6008195822..6b57d968f2 100644 --- a/packages/provider-tizen/src/runtime.test.ts +++ b/packages/provider-tizen/src/runtime.test.ts @@ -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; + }); +}); diff --git a/packages/provider-webos/README.md b/packages/provider-webos/README.md index 2864e9963e..6774d901de 100644 --- a/packages/provider-webos/README.md +++ b/packages/provider-webos/README.md @@ -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`. @@ -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 | @@ -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 diff --git a/packages/provider-webos/src/keys.ts b/packages/provider-webos/src/keys.ts index 68004999e2..0408627ea1 100644 --- a/packages/provider-webos/src/keys.ts +++ b/packages/provider-webos/src/keys.ts @@ -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, }; diff --git a/packages/provider-webos/src/runtime.test.ts b/packages/provider-webos/src/runtime.test.ts index 521ee6c68e..5fb14b5cf5 100644 --- a/packages/provider-webos/src/runtime.test.ts +++ b/packages/provider-webos/src/runtime.test.ts @@ -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; + }); +}); diff --git a/packages/tv-cdp/src/index.ts b/packages/tv-cdp/src/index.ts index 68a60fc14b..b0480dbe36 100644 --- a/packages/tv-cdp/src/index.ts +++ b/packages/tv-cdp/src/index.ts @@ -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'; diff --git a/packages/tv-cdp/src/keys.test.ts b/packages/tv-cdp/src/keys.test.ts index f4c1cc44ef..56554bede4 100644 --- a/packages/tv-cdp/src/keys.test.ts +++ b/packages/tv-cdp/src/keys.test.ts @@ -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); @@ -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' }, + ]); +}); diff --git a/packages/tv-cdp/src/keys.ts b/packages/tv-cdp/src/keys.ts index 75e01b516e..2bd0aa51b2 100644 --- a/packages/tv-cdp/src/keys.ts +++ b/packages/tv-cdp/src/keys.ts @@ -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[]; } diff --git a/src/commands/schema/cli-help.ts b/src/commands/schema/cli-help.ts index c9b6fad1d1..cdc7071199 100644 --- a/src/commands/schema/cli-help.ts +++ b/src/commands/schema/cli-help.ts @@ -229,9 +229,10 @@ Vega OS: Buttons: Examples: tv-remote longpress select; tv-remote press select --duration-ms 500. Syntax: tv-remote [press|longpress]