# StreamPixelApplication

## Signature

{% code lineNumbers="true" %}

```javascript
async function StreamPixelApplication(settings) => {
  pixelStreaming, appStream, queueHandler, UIControl, reconnectStream
}
```

{% endcode %}

## Parameters

The `settings` object accepts the following properties:

| Parameter               | Type      | Default                   | Description                                                                        |
| ----------------------- | --------- | ------------------------- | ---------------------------------------------------------------------------------- |
| `appId`                 | `string`  | **Required**              | Project ID from Streampixel dashboard                                              |
| `afktimeout`            | `number`  | `120`                     | Idle timeout in seconds (1–7200)                                                   |
| `AutoConnect`           | `boolean` | `false`                   | Auto-connect on initialization                                                     |
| `fallBackCodec`         | `string`  | Dashboard value           | Fallback video codec (`"H264"`, `"VP8"`, `"VP9"`, `"AV1"`)                         |
| `fakeMouseWithTouches`  | `boolean` | `false`                   | Convert touch events to mouse events                                               |
| `forceTurn`             | `boolean` | `true`                    | Force TURN relay for NAT traversal                                                 |
| `gamepadInput`          | `boolean` | `true`                    | Enable gamepad/controller input                                                    |
| `hoverMouse`            | `boolean` | `true`                    | Send mouse hover/move events to UE                                                 |
| `keyBoardInput`         | `boolean` | `true`                    | Enable keyboard input                                                              |
| `maxBitrate`            | `number`  | `100`                     | Maximum bitrate in Mbps                                                            |
| `maxQP`                 | `number`  | `-1`                      | Maximum quantization parameter (-1 = no limit)                                     |
| `maxStreamQuality`      | `string`  | `"1080p (1920x1080)"`     | Maximum allowed resolution preset                                                  |
| `minBitrate`            | `number`  | `1`                       | Minimum bitrate in Mbps                                                            |
| `minQP`                 | `number`  | `20`                      | Minimum quantization parameter (1–51)                                              |
| `mouseInput`            | `boolean` | `true`                    | Enable mouse input                                                                 |
| `primaryCodec`          | `string`  | Dashboard value           | Preferred video codec (`"H264"`, `"VP8"`, `"VP9"`, `"AV1"`)                        |
| `resolutionMode`        | `string`  | `"Fixed Resolution Mode"` | `"Fixed Resolution Mode"`, `"Dynamic Resolution Mode"`, or `"Crop on Resize Mode"` |
| `sfuHost`               | `string`  | `"false"`                 | Set to `"true"` for SFU host mode                                                  |
| `sfuPlayer`             | `string`  | `"false"`                 | Set to `"true"` for SFU viewer mode                                                |
| `showResolution`        | `boolean` | Dashboard value           | Enable resolution UI control                                                       |
| `startResolution`       | `string`  | `"1080p (1920x1080)"`     | Starting resolution for desktop                                                    |
| `startResolutionMobile` | `string`  | `"480p (854x480)"`        | Starting resolution for mobile                                                     |
| `startResolutionTab`    | `string`  | `"720p (1280x720)"`       | Starting resolution for tablet                                                     |
| `streamerId`            | `string`  | Auto-generated UUID       | Target specific streamer instance                                                  |
| `touchInput`            | `boolean` | `true`                    | Enable touch input                                                                 |
| `useCamera`             | `boolean` | `true`                    | Enable camera input to UE                                                          |
| `useMic`                | `boolean` | `true`                    | Enable microphone input to UE                                                      |
| `xrInput`               | `boolean` | `true`                    | Enable WebXR (VR/AR) input                                                         |

## Return Value

Returns an object with five properties:

```javascript
{
  pixelStreaming,    // PixelStreaming — core streaming instance
  appStream,         // CustomApplication — DOM wrapper and lifecycle
  queueHandler,      // Function — register queue position callbacks
  UIControl,         // UIControllerNew — audio, resolution, stats helpers
  reconnectStream    // EventEmitter — reconnection state events
}
```

Returns `null` if the project's URL validation fails (when the current origin is not in the project's allowed URLs list).

Returns `{}` if called more than once (singleton guard).

## Singleton Behavior

{% hint style="danger" %}
`StreamPixelApplication` can only be initialized once per page. Calling it a second time logs a warning and returns an empty object (`{}`). Reload the page to reinitialize.
{% endhint %}

## URL Validation

{% hint style="info" %}
The SDK checks `window.location.origin` against the project's `validPathUrl` list configured in the dashboard. If the origin doesn't match, `null` is returned. `localhost` is always allowed for development.
{% endhint %}
