# Tecton TV — TizenBrew Module

Watch movies and TV shows on your Samsung Smart TV using [TizenBrew](https://github.com/reisxd/TizenBrew).

## Setup

### 1. Install TizenBrew on your Samsung TV

Follow the [TizenBrew installation guide](https://github.com/reisxd/TizenBrew) to set up TizenBrew on your Samsung Smart TV.

### 2. Deploy your Tecton instance

You need a running Tecton instance accessible from your TV. Deploy it to Vercel, Cloudflare, or run it on your local network.

### 3. Configure the module URL

Edit `tizenbrew/app/index.html` and replace `__TECTON_URL__` with your deployed URL:

```javascript
var TECTON_URL = 'https://your-tecton-instance.vercel.app';
```

Or, if you leave the placeholder, the TV will prompt you to enter the URL on first launch (it's saved in localStorage).

### 4. Publish the module

The TizenBrew module files need to be hosted somewhere accessible. You can:

**Option A: GitHub (recommended)**
1. Push this `tizenbrew/` directory to a GitHub repo
2. Users add the module via TizenBrew's Module Manager using the npm package name

**Option B: npm**
```bash
cd tizenbrew
npm publish
```

**Option C: Local development**
Run a local server in the `tizenbrew/` directory:
```bash
cd tizenbrew
npx serve .
```
Then point TizenBrew to your local server URL.

## Remote Key Mapping

| Samsung Remote Key | Action |
|---|---|
| **D-pad (↑↓←→)** | Navigate / Seek ±5s (in player) |
| **Enter/OK** | Select / Play/Pause |
| **Back** | Go back / Close overlay |
| **🔴 Red** | Toggle captions |
| **🟢 Green** | Toggle fullscreen |
| **🟡 Yellow** | Toggle mute |
| **🔵 Blue** | Toggle native subtitles |
| **▲ Channel Up** | Next episode |
| **▼ Channel Down** | Previous episode |
| **⏸ Media Play/Pause** | Play/Pause |
| **⏪ Media Rewind** | Seek backward 1s |
| **⏩ Media Fast Forward** | Seek forward 1s |
| **⏭ Media Track Next** | Next episode |
| **⏮ Media Track Previous** | Previous episode |
| **0–9 Number keys** | Jump to 0%–90% of video |
| **Vol Up/Down** | Volume up/down |
| **Mute** | Toggle mute |
| **Search** | Search (opens search overlay) |
| **Info** | Show info |

## Architecture

```
tizenbrew/
├── package.json          # TizenBrew module metadata & key registration
├── service.js            # NodeJS service (Tizen TVInputDevice API)
├── app/
│   └── index.html        # TV-optimized entry point
└── README.md
```

- **package.json**: Declares the module type (`app`), remote keys to register, and entry point
- **service.js**: Registers all Samsung TV remote keys via `tizen.tvinputdevice.registerKey()` so the app receives keydown events
- **app/index.html**: Loads the deployed Tecton instance in an iframe with:
  - Spatial navigation for D-pad focus management
  - TV-optimized CSS (larger text, focus indicators, hidden cursors)
  - Remote key → keyboard shortcut forwarding
  - Loading/error screens
  - Key HUD overlay showing available controls

## Customization

### Change the Tecton URL at runtime
The URL is saved in the TV's localStorage. To change it, clear storage or the TV will prompt again on next launch if the URL fails.

### Add custom key mappings
Edit the `keyMap` object in `tizenbrew/app/index.html` to remap keys. The values correspond to keyboard shortcuts defined in `src/utils/keyboardShortcuts.ts`.

## Troubleshooting

- **Blank screen**: Make sure your Tecton instance is accessible from the TV's network
- **Keys not working**: Ensure TizenBrew registered the keys (check console for `[TectonTV] Registered key:` logs)
- **CORS errors**: Your Tecton deployment needs to allow being loaded in an iframe (`X-Frame-Options` should not be `DENY`)
- **Loading timeout**: Default timeout is 30 seconds. Increase `LOAD_TIMEOUT` in `index.html` for slow connections
