# XrViews

Class · extends [`EventHandler`](https://api.playcanvas.com/engine/classes/EventHandler.md) · category: XR

Source: https://github.com/playcanvas/engine/blob/f059dc005842f76e052cdf44d8370c8c7ec475ac/src/framework/xr/xr-views.js#L17

Provides access to list of [XrView](https://api.playcanvas.com/engine/classes/XrView.md)s and information about their capabilities, such as
support and availability of view's camera color texture, depth texture and other parameters.

## Accessors

### availableColor

```ts
get availableColor(): boolean
```

Check if Camera Color is available. This information becomes available only after
session has started.

### availableDepth

```ts
get availableDepth(): boolean
```

Check if Camera Depth is available. This information becomes available only after
session has started.

### depthGpuOptimized

```ts
get depthGpuOptimized(): boolean
```

Whether the depth sensing is GPU optimized.

### depthPixelFormat

```ts
get depthPixelFormat(): 2 | 15 | null
```

The depth sensing pixel format. Can be:

- `PIXELFORMAT_LA8`
- [PIXELFORMAT_R32F](https://api.playcanvas.com/engine/variables/PIXELFORMAT_R32F.md)

### list

```ts
get list(): XrView[]
```

An array of [XrView](https://api.playcanvas.com/engine/classes/XrView.md)s of this session. Views are not available straight away on
session start, and can be added/removed mid-session. So use of `add`/`remove` events is
required for accessing views.

### supportedColor

```ts
get supportedColor(): boolean
```

Check if Camera Color is supported. It might be still unavailable even if requested,
based on hardware capabilities and granted permissions.

### supportedDepth

```ts
get supportedDepth(): boolean
```

Check if Camera Depth is supported. It might be still unavailable even if requested,
based on hardware capabilities and granted permissions.

## Methods

### get

```ts
get(eye: string): XrView | null
```

Get an [XrView](https://api.playcanvas.com/engine/classes/XrView.md) by its associated eye constant.

**Parameters**

- `eye` (`string`): An XREYE_* view is associated with. Can be 'none' for monoscope views.

**Returns** [`XrView`](https://api.playcanvas.com/engine/classes/XrView.md) `| null`: View or null if view of such eye is not available.

## Events

### EVENT_ADD

```ts
static EVENT_ADD: string = 'add'
```

Fired when a view has been added. Views are not available straight away on session start and
are added mid-session. They can be added/removed mid session by the underlying system. The
handler is passed the [XrView](https://api.playcanvas.com/engine/classes/XrView.md) that has been added.

**Example**

```ts
xr.views.on('add', (view) => {
    console.log('View added');
});
```

### EVENT_REMOVE

```ts
static EVENT_REMOVE: string = 'remove'
```

Fired when a view has been removed. They can be added/removed mid session by the underlying
system. The handler is passed the [XrView](https://api.playcanvas.com/engine/classes/XrView.md) that has been removed.

**Example**

```ts
xr.views.on('remove', (view) => {
    console.log('View removed');
});
```

## Inherited from [EventHandler](https://api.playcanvas.com/engine/classes/EventHandler.md)

- `fire(name: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any, arg7?: any, arg8?: any): EventHandler`
- `hasEvent(name: string): boolean`
- `off(name?: string, callback?: HandleEventCallback, scope?: any): EventHandler`
- `on(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
- `once(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
