# WebOS TV Deployment Guide

This guide explains how to deploy your Trip App to LG WebOS TV.

## Prerequisites

### 1. LG WebOS TV SDK

Download and install the LG WebOS TV SDK from:
- [LG Developer Portal](https://webostv.developer.lge.com/)
- Choose the appropriate version for your WebOS TV

### 2. Developer Account

1. Create a developer account at [LG Developer](https://webostv.developer.lge.com/)
2. Register your TV model for development
3. Enable Developer Mode on your TV

### 3. TV Setup

1. **Enable Developer Mode**:
   - Install "Developer Mode" app from LG Content Store
   - Connect to your developer account
   - Enable Developer Mode

2. **Connect TV to Network**:
   - Ensure TV is connected to the same network as your development machine
   - Note the TV's IP address

## Development Setup

### 1. Install WebOS CLI

```bash
# Install WebOS CLI tools
npm install -g @webosose/ares-cli

# Verify installation
ares-setup-device
```

### 2. Configure Development Device

```bash
# Add your TV as a development device
ares-setup-device --add your-tv-name --host [TV_IP_ADDRESS] --port 22

# Verify connection
ares-device-info -d your-tv-name
```

## Building and Deployment

### 1. Package the App

```bash
# Navigate to your app directory
cd webos-trip-app

# Create IPK package
ares-package .

# This creates: com.android.trip.webos_1.0.0_all.ipk
```

### 2. Install on TV

```bash
# Install the app
ares-install com.android.trip.webos_1.0.0_all.ipk -d your-tv-name

# Launch the app
ares-launch com.android.trip.webos -d your-tv-name
```

### 3. Debug and Monitor

```bash
# View app logs
ares-log -d your-tv-name

# Monitor app performance
ares-inspect -d your-tv-name

# Uninstall app
ares-uninstall com.android.trip.webos -d your-tv-name
```

## Testing

### 1. Local Testing

Before deploying to TV, test locally:

```bash
# Start development server
npm start

# Open in browser
open http://localhost:8080
```

### 2. TV Testing

1. **Install and launch** the app on your TV
2. **Test functionality**:
   - Login with Block ID
   - Verify API connectivity
   - Test video playback
   - Test audio announcements
   - Test TV remote navigation

### 3. Remote Control Testing

Test all remote control functions:
- **Arrow keys**: Navigation
- **Enter/OK**: Selection
- **Back**: Navigation back
- **Home**: Return to TV home
- **Menu**: App menu access

## Troubleshooting

### Common Issues

1. **App won't install**:
   - Check TV IP address
   - Verify Developer Mode is enabled
   - Check network connectivity

2. **App crashes on launch**:
   - Check app logs: `ares-log -d your-tv-name`
   - Verify all required files are included
   - Check JavaScript console for errors

3. **Video/audio not playing**:
   - Verify media files are accessible
   - Check file formats and codecs
   - Test media files in browser first

4. **API calls failing**:
   - Check network connectivity
   - Verify API endpoints are accessible
   - Check CORS settings if testing locally

### Debug Commands

```bash
# View detailed logs
ares-log -d your-tv-name -f

# Check device status
ares-device-info -d your-tv-name

# Restart app
ares-launch com.android.trip.webos -d your-tv-name

# Clear app data
ares-uninstall com.android.trip.webos -d your-tv-name
ares-install com.android.trip.webos_1.0.0_all.ipk -d your-tv-name
```

## Production Deployment

### 1. App Store Submission

For production deployment:

1. **Prepare app package**:
   - Ensure all features work correctly
   - Test on multiple TV models
   - Optimize performance and file sizes

2. **Submit to LG Content Store**:
   - Follow LG's submission guidelines
   - Provide app screenshots and descriptions
   - Complete certification process

### 2. Enterprise Deployment

For enterprise/internal deployment:

1. **Create signed package**:
   ```bash
   ares-package . --sign
   ```

2. **Distribute IPK file**:
   - Share IPK file with target TVs
   - Install using `ares-install` command
   - Configure app settings as needed

## Performance Optimization

### 1. File Size Optimization

- **Compress videos**: Use efficient codecs
- **Optimize images**: Use WebP format when possible
- **Minify JavaScript**: Remove unnecessary code
- **Compress audio**: Use appropriate bitrates

### 2. Memory Management

- **Monitor memory usage**: Use WebOS debugging tools
- **Clean up resources**: Properly dispose of media players
- **Limit cache sizes**: Prevent memory leaks

### 3. Network Optimization

- **Cache API responses**: Reduce network requests
- **Compress data**: Use efficient data formats
- **Handle offline mode**: Graceful degradation

## Security Considerations

### 1. API Security

- **Use HTTPS**: Secure API communications
- **Validate inputs**: Prevent injection attacks
- **Handle errors**: Don't expose sensitive information

### 2. App Security

- **Validate data**: Check all user inputs
- **Secure storage**: Use WebOS secure storage APIs
- **Update regularly**: Keep app and dependencies updated

## Maintenance

### 1. Regular Updates

- **Monitor API changes**: Update API endpoints as needed
- **Update dependencies**: Keep libraries current
- **Test on new TV models**: Ensure compatibility

### 2. Monitoring

- **Track app usage**: Monitor performance metrics
- **Collect feedback**: Gather user feedback
- **Fix issues**: Address bugs and performance problems

## Support Resources

- **LG Developer Documentation**: [webostv.developer.lge.com](https://webostv.developer.lge.com/)
- **WebOS TV Forums**: Community support
- **LG Developer Support**: Official support channels
- **GitHub Issues**: Report bugs and feature requests
