# Public methods ArcwarePixelStreaming

This page documents the public methods exposed by:

* `ArcwarePixelStreaming`

It focuses on methods provided by the Arcware SDK layer. Methods inherited from Epic’s underlying Pixel Streaming libraries are not exhaustively listed here, with one important exception: `emitUIInteraction()`, because it is central to most integrations.

***

## ArcwarePixelStreaming

`ArcwarePixelStreaming` is the core streaming class used by both:

* `ArcwareInit`
* `CoreSetup`

It is the main place for:

* stream control
* messaging
* analytics
* file transfer
* audio and microphone control
* connection lifecycle

***

### emitUIInteraction

Although this method is inherited from the underlying Pixel Streaming implementation, it is one of the most important methods available on `ArcwarePixelStreaming` and is the recommended way to send messages from the web application to Unreal Engine.

```typescript
PixelStreaming.emitUIInteraction(descriptor: object | string): void
```

#### Parameters

| Parameter    | Type               | Description                   |
| ------------ | ------------------ | ----------------------------- |
| `descriptor` | `object \| string` | Message sent to Unreal Engine |

#### Example

```typescript
PixelStreaming.emitUIInteraction({
  action: "Jump"
});
```

```typescript
PixelStreaming.emitUIInteraction("openMenu");
```

This method should be used by both:

* UI integrations
* Core / headless integrations

***

### reconnect

Reconnects the stream.

```typescript
PixelStreaming.reconnect(): void
```

This method reuses the existing stream object and reinitializes internal readiness tracking.

#### Example

```typescript
PixelStreaming.reconnect();
```

Typical use cases:

* reconnect button
* manual retry after connection loss
* refreshing the current connection without rebuilding the SDK objects

***

### removePlayer

Stops the stream and removes internal transport and rendering hooks.

```typescript
PixelStreaming.removePlayer(): void
```

This method performs cleanup and disconnects the stream.

#### Example

```typescript
PixelStreaming.removePlayer();
```

Typical use cases:

* component unmount cleanup
* fully leaving a stream
* destroying a stream before creating a new one

***

### send

Sends a message to the backend signalling pipeline.

```typescript
PixelStreaming.send(type: string, payload?: Record<string, unknown>): void
```

```typescript
PixelStreaming.send(message: { type: string } & Record<string, unknown>): void
```

#### Parameters

| Parameter | Type                                         | Description             |
| --------- | -------------------------------------------- | ----------------------- |
| `type`    | `string`                                     | Message type            |
| `payload` | `Record<string, unknown>`                    | Optional payload object |
| `message` | `{ type: string } & Record<string, unknown>` | Full message object     |

#### Examples

```typescript
PixelStreaming.send("render");
```

```typescript
PixelStreaming.send("customType", {
  value: 123
});
```

```typescript
PixelStreaming.send({
  type: "version"
});
```

This is a lower-level method and is mainly useful when working with the Arcware signalling protocol directly.

For Unreal Engine UI interaction, use `emitUIInteraction()` instead.

***

### sendAnalyticsEvent

Sends an analytics event and also emits it through the local analytics handler.

```typescript
PixelStreaming.sendAnalyticsEvent(event: AnalyticsEvent): void
```

#### Parameters

| Parameter | Type             | Description             |
| --------- | ---------------- | ----------------------- |
| `event`   | `AnalyticsEvent` | Analytics event payload |

#### Example

```typescript
PixelStreaming.sendAnalyticsEvent({
  type: "event",
  customName: "button_clicked",
  payload: JSON.stringify({ id: 42 })
});
```

Use this when frontend interactions should be tracked consistently with Unreal-originated analytics events.

***

### getIncomingFile

Returns the most recently received file sent from Unreal Engine.

```typescript
PixelStreaming.getIncomingFile(): FileTemplate
```

#### Example

```typescript
const file = PixelStreaming.getIncomingFile();
console.log(file?.mimetype);
```

This method is typically used together with `fileTransferHandler`.

***

### fileDownload

Triggers a browser download for the most recently received file.

```typescript
PixelStreaming.fileDownload(filename?: string): void
```

#### Parameters

| Parameter  | Type                  | Description                                |
| ---------- | --------------------- | ------------------------------------------ |
| `filename` | `string \| undefined` | Optional custom filename without extension |

#### Example

```typescript
PixelStreaming.fileTransferHandler.add(() => {
  PixelStreaming.fileDownload();
});
```

```typescript
PixelStreaming.fileTransferHandler.add(() => {
  PixelStreaming.fileDownload("my-export");
});
```

This is the easiest way for Core users to replicate the default UI file download behavior.

***

### setAudioEnabled

Enables or disables audio playback.

```typescript
PixelStreaming.setAudioEnabled(enabled: boolean): void
```

#### Parameters

| Parameter | Type      | Description                                  |
| --------- | --------- | -------------------------------------------- |
| `enabled` | `boolean` | `true` enables audio, `false` disables audio |

#### Example

```typescript
PixelStreaming.setAudioEnabled(true);
```

This method uses a direct enabled/disabled semantic.

***

### toggleAudio

Toggles audio muting on the current video and audio elements.

```typescript
PixelStreaming.toggleAudio(videoElement: HTMLVideoElement, enabled: boolean): void
```

#### Parameters

| Parameter      | Type               | Description                                      |
| -------------- | ------------------ | ------------------------------------------------ |
| `videoElement` | `HTMLVideoElement` | Video element associated with the stream         |
| `enabled`      | `boolean`          | Mute state as used by the current implementation |

#### Example

```typescript
const video = document.querySelector("video");
if (video) {
  PixelStreaming.toggleAudio(video, false);
}
```

`setAudioEnabled()` is usually easier to use in application code.

***

### toggleMic

Enables or disables microphone usage.

```typescript
PixelStreaming.toggleMic(enable: boolean, isDefault: boolean): void
```

#### Parameters

| Parameter   | Type      | Description                                                  |
| ----------- | --------- | ------------------------------------------------------------ |
| `enable`    | `boolean` | Enables or disables microphone input                         |
| `isDefault` | `boolean` | If `false`, the stream reconnects so the change takes effect |

#### Example

```typescript
PixelStreaming.toggleMic(true, false);
```

When microphone state is changed manually, the stream reconnects to apply the new configuration.

***

### onStreamingStateChange

Registers a callback that reacts to streaming state changes.

```typescript
PixelStreaming.onStreamingStateChange(
  callback: (isStreaming: boolean) => void
): void
```

#### Parameters

| Parameter  | Type                             | Description                             |
| ---------- | -------------------------------- | --------------------------------------- |
| `callback` | `(isStreaming: boolean) => void` | Called with the current streaming state |

#### Example

```typescript
PixelStreaming.onStreamingStateChange((isStreaming) => {
  console.log("Streaming:", isStreaming);
});
```

This callback is triggered on events such as:

* video play
* video pause
* video end
* transport open
* transport close

***

### clearSessionId

Clears the stored session identifier from local storage.

```typescript
ArcwarePixelStreaming.clearSessionId(): void
```

#### Example

```typescript
ArcwarePixelStreaming.clearSessionId();
```

Typical use cases:

* forcing a clean new session
* logout / reset flows
* debugging reconnect behavior
