# Spaceship Call / Video Call / GIF Setup Notes

## What was changed in this build

1. Added an encrypted in-call chat panel inside the call/video-call overlay.
   - Users can type while the call is still connecting.
   - Messages use the existing encrypted message system.

2. Added a Speaker button.
   - On browsers that support `HTMLMediaElement.setSinkId()`, the button attempts to switch between the default speaker output and normal communication output.
   - Some mobile browsers do not allow web pages to force speaker/earpiece routing. If blocked, use the phone/device audio controls.

3. Added a Share Screen button.
   - Uses `navigator.mediaDevices.getDisplayMedia()`.
   - Works best on desktop Chrome/Edge/Firefox/Safari over HTTPS or localhost.
   - Many mobile browsers/iOS browsers do not expose full screen sharing to normal web apps.

4. Improved call connection status messages.
   - If WebRTC cannot connect due to NAT/firewall/TURN issues, the overlay now makes this clearer instead of staying only on “Connecting…”.

5. Incoming call cleanup was improved.
   - The receiver now polls the ringing call status, so the overlay can close if the caller ends before the receiver accepts.

## Required for audio/video to work reliably

WebRTC calls need all of the following:

1. HTTPS or localhost
   - `https://your-domain/...` works.
   - `http://localhost/...` works for local testing.
   - `http://192.168.x.x/...` usually fails on mobile because the browser blocks camera/microphone access.

2. Camera/microphone permission
   - Both users must allow camera/microphone permissions.

3. TURN relay for different networks
   - STUN-only can work on the same Wi-Fi, but often fails across mobile data, carrier NAT, or strict home routers.
   - Add TURN credentials in `js/app.js` under `ICE_SERVERS`, or set `METERED_TURN_API_URL` for dynamic TURN credentials.

Example static TURN entries in `js/app.js`:

```js
const ICE_SERVERS = [
  { urls:'stun:stun.l.google.com:19302' },
  { urls:'stun:stun1.l.google.com:19302' },
  { urls:'turn:turn.example.com:3478', username:'YOUR_USER', credential:'YOUR_PASS' },
  { urls:'turns:turn.example.com:5349', username:'YOUR_USER', credential:'YOUR_PASS' }
];
```

Without TURN, one or both users may remain stuck at “Connecting…” even though the code is correct.

## Photo 1: GIF search not configured

The GIF picker is working, but no GIF provider API key is configured yet. Edit `api/config.php`:

```php
define('GIF_PROVIDER', 'klipy');
define('GIF_API_KEY',  'PASTE_YOUR_KEY_HERE');
```

Supported providers in this build:

- `klipy` — recommended
- `tenor`
- `giphy`

After editing `api/config.php`, refresh the app and open the GIF picker again.
