# Queue System

When all Unreal Engine instances are busy, the SDK places users in a queue. The queue system notifies your application of the user's position so you can display appropriate UI.

{% hint style="info" %}
The queue system only activates when all available UE instances are busy. If an instance is free, the user connects immediately without entering the queue.
{% endhint %}

## Registering the Queue Callback

{% code lineNumbers="true" %}

```javascript
const { queueHandler } = await StreamPixelApplication({
  appId: 'your-project-id',
  AutoConnect: true,
});

queueHandler((msg) => {
  console.log(`Position: ${msg.position}`);
  console.log(`Message: ${msg.message}`);
});
```

{% endcode %}

## Callback Data

| Property       | Type     | Description                              |
| -------------- | -------- | ---------------------------------------- |
| `msg.position` | `number` | The user's current position in the queue |
| `msg.message`  | `string` | Status message from the server           |

## Queue Messages

The signaling server sends these messages:

| Message                   | Meaning                                   |
| ------------------------- | ----------------------------------------- |
| `"You are in Queue"`      | User is waiting for an available instance |
| `"Not Available"`         | No worker nodes are available             |
| `"Application Not Found"` | The project/application does not exist    |
| `"Application Error"`     | The UE application encountered an error   |

## Displaying Queue Position

```javascript
queueHandler((msg) => {
  if (msg.message === 'You are in Queue') {
    document.getElementById('queue-display').style.display = 'block';
    document.getElementById('queue-position').textContent = msg.position;
  }
});
```

The queue callback fires every time the server sends an update (e.g., when the user's position changes as others connect or disconnect).
