Skip to main content
Type definitions for detecting Smart TV platforms, handling remote control input, and querying device capabilities.

Platform

Supported Smart TV platforms and streaming devices.
enum Platform {
  WebOS = 'webos',
  Tizen = 'tizen',
  Vidaa = 'vidaa',
  WhaleOS = 'whaleos',
  FireTV = 'firetv',
  Roku = 'roku',
  Xbox = 'xbox',
  PlayStation = 'playstation',
  AndroidTV = 'androidtv',
  Vizio = 'vizio',
  Generic = 'generic'
}
WebOS
'webos'
LG Smart TVs running webOS.
Tizen
'tizen'
Samsung Smart TVs running Tizen OS.
Vidaa
'vidaa'
Hisense Smart TVs running VIDAA OS.
WhaleOS
'whaleos'
Smart TVs running WhaleOS (Whale browser-based platform).
FireTV
'firetv'
Amazon Fire TV and Fire TV Stick devices.
Roku
'roku'
Roku streaming devices and Roku TVs.
Xbox
'xbox'
Microsoft Xbox consoles.
PlayStation
'playstation'
Sony PlayStation consoles (PS4, PS5).
AndroidTV
'androidtv'
Android TV devices including Google TV, Chromecast, and various TV manufacturers.
Vizio
'vizio'
Vizio SmartCast TVs.
Generic
'generic'
Fallback for unknown or standard web platforms.

KeyAction

Remote control and gamepad key actions.
enum KeyAction {
  Enter = 'enter',
  Back = 'back',
  Left = 'left',
  Right = 'right',
  Up = 'up',
  Down = 'down',
  Play = 'play',
  Pause = 'pause',
  PlayPause = 'playPause',
  Stop = 'stop',
  FastForward = 'fastForward',
  Rewind = 'rewind',
  Menu = 'menu',
  Info = 'info',
  Red = 'red',
  Green = 'green',
  Yellow = 'yellow',
  Blue = 'blue',
  ChannelUp = 'channelUp',
  ChannelDown = 'channelDown',
  VolumeUp = 'volumeUp',
  VolumeDown = 'volumeDown',
  Mute = 'mute'
}
Normalized key actions for Smart TV remote controls and game controllers.

PlatformKeyMap

Mapping of platform-specific key codes to normalized key actions.
interface PlatformKeyMap {
  [keyCode: number]: KeyAction;
}
Maps raw numeric key codes to KeyAction enums. Each platform has different key code mappings.

Example

const tizenKeyMap: PlatformKeyMap = {
  13: KeyAction.Enter,
  10009: KeyAction.Back,
  37: KeyAction.Left,
  // ...
};

PlatformCapabilities

Device capability flags for feature detection.
interface PlatformCapabilities {
  sendBeacon: boolean;
  fetchKeepalive: boolean;
  mutedAutoplayRequired: boolean;
  fullscreen: boolean;
  hardwareDecodeInfo: boolean;
  hdr: boolean;
  hdr10Plus: boolean;
  dolbyVision: boolean;
  dolbyAtmos: boolean;
  hevc: boolean;
  vp9: boolean;
  av1: boolean;
  maxResolution: '4k' | '1080p' | '720p' | 'unknown';
  touch: boolean;
  voice: boolean;
}
sendBeacon
boolean
Whether navigator.sendBeacon() API is supported for analytics.
fetchKeepalive
boolean
Whether fetch() with keepalive option is supported.
mutedAutoplayRequired
boolean
Whether autoplay requires the video to be muted (browser policy).
fullscreen
boolean
Whether fullscreen API is supported.
hardwareDecodeInfo
boolean
Whether hardware video decode capabilities can be queried.
hdr
boolean
Whether HDR (High Dynamic Range) video is supported.
hdr10Plus
boolean
Whether HDR10+ is supported.
dolbyVision
boolean
Whether Dolby Vision HDR is supported.
dolbyAtmos
boolean
Whether Dolby Atmos audio is supported.
hevc
boolean
Whether HEVC/H.265 video codec is supported.
vp9
boolean
Whether VP9 video codec is supported.
av1
boolean
Whether AV1 video codec is supported.
maxResolution
'4k' | '1080p' | '720p' | 'unknown'
Maximum supported video resolution.
touch
boolean
Whether the device has touch input support.
voice
boolean
Whether the device has voice control capabilities.

DeviceInfo

Detailed device information.
interface DeviceInfo {
  platform: Platform;
  model?: string;
  manufacturer?: string;
  osVersion?: string;
  firmwareVersion?: string;
  screenWidth?: number;
  screenHeight?: number;
  devicePixelRatio?: number;
}
platform
Platform
Detected platform. See Platform enum.
model
string
Device model identifier (e.g., “OLED55C1PUB” for LG C1).
manufacturer
string
Device manufacturer (e.g., “LG”, “Samsung”, “Amazon”).
osVersion
string
Operating system version.
firmwareVersion
string
Device firmware version.
screenWidth
number
Screen width in pixels.
screenHeight
number
Screen height in pixels.
devicePixelRatio
number
Device pixel ratio (e.g., 1 for 1080p, 2 for 4K on 1080p logical screen).

IPlatformAdapter

Platform adapter interface for device abstraction.
interface IPlatformAdapter {
  readonly platform: Platform;
  readonly capabilities: PlatformCapabilities;
  readonly deviceInfo: DeviceInfo;
  
  normalizeKeyCode(keyCode: number): KeyAction | null;
  getKeyCodesForAction(action: KeyAction): number[];
  isCodecSupported(codec: string): boolean;
  openExternalLink(url: string): void;
}
platform
Platform
Current detected platform.
capabilities
PlatformCapabilities
Platform capabilities. See PlatformCapabilities.
deviceInfo
DeviceInfo
Device information. See DeviceInfo.
normalizeKeyCode
(keyCode: number) => KeyAction | null
Normalize a raw key code to a KeyAction.Parameters:
  • keyCode - Raw keyboard/remote key code from KeyboardEvent
Returns:
getKeyCodesForAction
(action: KeyAction) => number[]
Get platform-specific key codes for a given action.Parameters:
  • action - The key action to look up
Returns:
  • Array of key codes that map to this action
isCodecSupported
(codec: string) => boolean
Check if a specific codec is supported on this platform.Parameters:
  • codec - MIME type with codec (e.g., video/mp4; codecs="hvc1")
Returns:
  • true if codec is supported, false otherwise
Open an external link in a new tab/window using platform-specific method.Parameters:
  • url - The URL to open

Example

const adapter: IPlatformAdapter = getPlatformAdapter();

// Normalize key codes
window.addEventListener('keydown', (e) => {
  const action = adapter.normalizeKeyCode(e.keyCode);
  if (action === KeyAction.Back) {
    // Handle back button
  }
});

// Check codec support
if (adapter.isCodecSupported('video/mp4; codecs="hvc1"')) {
  // Use HEVC media file
}

// Open external link
adapter.openExternalLink('https://advertiser.com');

DEFAULT_KEY_CODES

Default key code mappings for all supported platforms.
const DEFAULT_KEY_CODES: Record<Platform, PlatformKeyMap>;
Provides default key code mappings for each platform. Maps Platform enum values to PlatformKeyMap objects.

Example Structure

DEFAULT_KEY_CODES[Platform.Tizen] = {
  13: KeyAction.Enter,
  10009: KeyAction.Back,
  37: KeyAction.Left,
  38: KeyAction.Up,
  39: KeyAction.Right,
  40: KeyAction.Down,
  415: KeyAction.Play,
  // ...
};

Platform-Specific Key Codes

  • 461 - Back button (WebOS-specific)
  • 415 - Play
  • 19 - Pause
  • 413 - Stop
  • 417 - Fast Forward
  • 412 - Rewind
  • 457 - Info
  • 403-406 - Color buttons (Red, Green, Yellow, Blue)
  • 10009 - Back button (Tizen-specific)
  • 10252 - Play/Pause toggle
  • 427-428 - Channel Up/Down
  • 447-448 - Volume Up/Down
  • 449 - Mute
  • 4 - Android back button
  • 85 - Play/Pause
  • 126 - Play
  • 127 - Pause
  • 89 - Rewind
  • 90 - Fast Forward
  • 82 - Menu
  • 13 - A button (Enter)
  • 27 - B button (Back)
  • 195 - Menu button
  • 196 - View button
  • 13 - X button (Enter)
  • 27 - Circle button (Back)
  • D-pad: 37-40 (Left, Up, Right, Down)

PLATFORM_DETECTION_PATTERNS

Regex patterns for detecting platforms from User-Agent strings.
const PLATFORM_DETECTION_PATTERNS: Record<Platform, RegExp[]>;
Provides regex patterns to detect each platform from navigator.userAgent. Maps Platform enum values to arrays of RegExp patterns.

Example Structure

PLATFORM_DETECTION_PATTERNS[Platform.Tizen] = [
  /Tizen/i,
  /SMART-TV.*Samsung/i
];

PLATFORM_DETECTION_PATTERNS[Platform.WebOS] = [
  /Web0S/i,
  /WebOS/i,
  /LG.*NetCast/i,
  /LGE.*TV/i
];

Detection Patterns by Platform

Tizen
RegExp[]
  • /Tizen/i
  • /SMART-TV.*Samsung/i
WebOS
RegExp[]
  • /Web0S/i
  • /WebOS/i
  • /LG.*NetCast/i
  • /LGE.*TV/i
Vidaa
RegExp[]
  • /Vidaa/i
  • /VIDAA/i
  • /Hisense/i
WhaleOS
RegExp[]
  • /WhaleTV/i
  • /Whale/i
FireTV
RegExp[]
  • /AFT/i - Amazon Fire TV
  • /AFTS/i - Fire TV Stick
  • /AFTM/i - Fire TV models
  • /Amazon.*Fire/i
Roku
RegExp[]
  • /Roku/i
Xbox
RegExp[]
  • /Xbox/i
  • /Edge.*Xbox/i
PlayStation
RegExp[]
  • /PlayStation/i
  • /PS4/i
  • /PS5/i
AndroidTV
RegExp[]
  • /Android.*TV/i
  • /Chromecast/i
  • /BRAVIA/i - Sony TVs
  • /SHIELD/i - NVIDIA Shield
Vizio
RegExp[]
  • /VIZIO/i
  • /SmartCast/i
Generic
RegExp[]
Empty array - fallback for all other platforms

Usage Example

function detectPlatform(): Platform {
  const ua = navigator.userAgent;
  
  for (const [platform, patterns] of Object.entries(PLATFORM_DETECTION_PATTERNS)) {
    if (patterns.some(pattern => pattern.test(ua))) {
      return platform as Platform;
    }
  }
  
  return Platform.Generic;
}

Build docs developers (and LLMs) love