# UIControl

The `UIControl` object provides helper methods for common UI operations.

## Methods

### `toggleAudio()`

Toggles the stream audio element between muted and unmuted.

```javascript
UIControl.toggleAudio();
```

{% hint style="warning" %}
This toggles only the audio element. For complete mute control (both video and audio elements), manage both elements directly. See [Audio and Media Input](https://docs.streampixel.io/resources/getting-started/features/audio-media-input).
{% endhint %}

### `handleResMax(value)`

Set the maximum resolution for the stream.

| Parameter | Type     | Description                                                 |
| --------- | -------- | ----------------------------------------------------------- |
| `value`   | `string` | Resolution in `"WIDTHxHEIGHT"` format (e.g., `"1920x1080"`) |

```javascript
UIControl.handleResMax('1920x1080');
UIControl.handleResMax('1280x720');
```

{% hint style="info" %}
Behavior depends on the resolution mode: in **Fixed Resolution Mode**, this sends an `r.SetRes` console command to UE. In **Dynamic** or **Crop on Resize Mode**, it updates the maximum dimensions and recalculates based on the viewport.
{% endhint %}

### `toggleHoveringMouse(value)`

Enable or disable hover mouse mode.

| Parameter | Type      | Description                          |
| --------- | --------- | ------------------------------------ |
| `value`   | `boolean` | `true` to enable, `false` to disable |

```javascript
UIControl.toggleHoveringMouse(true);
UIControl.toggleHoveringMouse(false);
```

When enabled, mouse movement events are sent to UE even without a button press.

### `getStreamStats()`

Collects and returns current stream statistics as a parsed object.

```javascript
const stats = UIControl.getStreamStats();
// {
//   "Framerate": 60,
//   "Net RTT (ms)": 12,
//   "Video resolution": "1920x1080",
//   "Video Bitrate (kbps)": 8500,
//   ...
// }
```

Returns an object with string keys and parsed values (numbers, booleans, or strings).

### `getResolution()`

Returns the available resolution options if resolution control is enabled for the project.

```javascript
const resolutions = UIControl.getResolution();
// ["360p (640x360)", "480p (854x480)", "720p (1280x720)", "1080p (1920x1080)"]
```

Returns `undefined` if resolution control is not enabled in the dashboard.
