Table of Contents

Class XRSession

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll
NOTE
Experimental
The XRSession interface of the WebXR Device API represents an ongoing XR session, providing methods and properties used to interact with and control the session. To open a WebXR session, use the XRSystem interface's RequestSession(XRSessionMode, XRSessionInit) method.
[Value("XRSession")]
public class XRSession : EventTarget
Inheritance
XRSession
Inherited Members

Remarks

With XRSession methods, you can poll the viewer's position and orientation (the XRViewerPose), gather information about the user's environment, and present imagery to the user. XRSession supports both inline and immersive virtual and augmented reality modes.

See also on MDN

Constructors

XRSession()

public XRSession()

Properties

DepthDataFormat

NOTE
Experimental
The read-only depthDataFormat property of an immersive-ar
XRSession describes which depth sensing data format is used.
[Value("depthDataFormat")]
public XRDepthDataFormat DepthDataFormat { get; }

Property Value

XRDepthDataFormat

This property can return the following values:

Remarks

DepthUsage

NOTE
Experimental
The read-only depthUsage property of an immersive-ar
XRSession describes which depth-sensing usage is used.
[Value("depthUsage")]
public XRDepthUsage DepthUsage { get; }

Property Value

XRDepthUsage

This property can return the following values:

Remarks

DomOverlayState

NOTE
Experimental
The read-only domOverlayState property of an immersive-ar
XRSession provides information about the DOM overlay, if the feature is enabled.
[Value("domOverlayState")]
public XRDOMOverlayState? DomOverlayState { get; }

Property Value

XRDOMOverlayState

Returns null if the DOM overlay feature is not supported or not enabled or an object containing information about the DOM overlay state with the following properties:

Remarks

-Element.Beforexrselect

See also on MDN

EnabledFeatures

NOTE
Experimental
The XRSession interface's read-only enabledFeatures property returns an array of features enabled (granted) for an XRSession. This contains all requiredFeatures and a subset of optionalFeatures that have been requested with RequestSession(XRSessionMode, XRSessionInit).
[Value("enabledFeatures")]
public string[] EnabledFeatures { get; }

Property Value

string[]

An Array of strings.

Remarks

EnvironmentBlendMode

NOTE
Experimental
The XRSession interface's read-only environmentBlendMode
property identifies if, and to what degree, the computer-generated imagery is overlaid atop the real world.
[Value("environmentBlendMode")]
public XREnvironmentBlendMode EnvironmentBlendMode { get; }

Property Value

XREnvironmentBlendMode

A string defining if and how virtual, rendered content is overlaid atop the image of the real world.Possible values are:

Remarks

This is used to differentiate between fully-immersive VR sessions and AR sessions which render
over a pass-through image of the real world, possibly partially transparently.

See also on MDN

FrameRate

[Value("frameRate")]
public Number? FrameRate { get; }

Property Value

Number

InputSources

NOTE
Experimental
The read-only inputSources property of the
XRSession interface returns an XRInputSourceArray object
which lists all controllers and input devices which are expressly associated with the
XR device and are currently available. These controllers may include handheld
controllers, XR-equipped gloves, optically tracked hands, and gaze-based input methods.
Keyboards, gamepads, and mice are not considered WebXR input sources.
[Value("inputSources")]
public XRInputSourceArray InputSources { get; }

Property Value

XRInputSourceArray

An XRInputSourceArray object listing all of the currently-connected
input controllers which are linked specifically to the XR device currently in use. The
returned object is live; as devices are connected to and removed from
the user's system, the list's contents update to reflect the changes.

Remarks

NOTE

Traditional gamepad controllers are supported using the Gamepad API.

-XRInputSource
-The XRSession.Inputsourceschange event
-Gamepad API

See also on MDN

InteractionMode

NOTE
Experimental
The XRSession interface's read-only interactionMode property
describes the best space (according to the user agent) for the application to draw an interactive UI for the current session.
[Value("interactionMode")]
public XRInteractionMode InteractionMode { get; }

Property Value

XRInteractionMode

A string describing the best space (according to the user agent) for the application to draw an interactive UI
for the current session.Possible values are:

Remarks

IsSystemKeyboardSupported

[Value("isSystemKeyboardSupported")]
public bool IsSystemKeyboardSupported { get; }

Property Value

bool

Onend

[Value("onend")]
public EventHandlerNonNull Onend { get; set; }

Property Value

EventHandlerNonNull

Onframeratechange

[Value("onframeratechange")]
public EventHandlerNonNull Onframeratechange { get; set; }

Property Value

EventHandlerNonNull

Oninputsourceschange

[Value("oninputsourceschange")]
public EventHandlerNonNull Oninputsourceschange { get; set; }

Property Value

EventHandlerNonNull

Onselect

[Value("onselect")]
public EventHandlerNonNull Onselect { get; set; }

Property Value

EventHandlerNonNull

Onselectend

[Value("onselectend")]
public EventHandlerNonNull Onselectend { get; set; }

Property Value

EventHandlerNonNull

Onselectstart

[Value("onselectstart")]
public EventHandlerNonNull Onselectstart { get; set; }

Property Value

EventHandlerNonNull

Onsqueeze

[Value("onsqueeze")]
public EventHandlerNonNull Onsqueeze { get; set; }

Property Value

EventHandlerNonNull

Onsqueezeend

[Value("onsqueezeend")]
public EventHandlerNonNull Onsqueezeend { get; set; }

Property Value

EventHandlerNonNull

Onsqueezestart

[Value("onsqueezestart")]
public EventHandlerNonNull Onsqueezestart { get; set; }

Property Value

EventHandlerNonNull

Onvisibilitychange

[Value("onvisibilitychange")]
public EventHandlerNonNull Onvisibilitychange { get; set; }

Property Value

EventHandlerNonNull

PersistentAnchors

[Value("persistentAnchors")]
public string[] PersistentAnchors { get; }

Property Value

string[]

PreferredReflectionFormat

NOTE
Experimental
The read-only preferredReflectionFormat property of the XRSession interface returns this session's preferred reflection format used for lighting estimation texture data.
[Value("preferredReflectionFormat")]
public XRReflectionFormat PreferredReflectionFormat { get; }

Property Value

XRReflectionFormat

A string representing the reflection format. Possible values:

XRReflectionFormatWebGL FormatWebGL Internal FormatWebGPU FormatHDR
"srgba8"RGBASRGB8_ALPHA8"rgba8unorm-srgb"
"rgba16f"RGBARGBA16F"rgba16float"

Remarks

RenderState

NOTE
Experimental
The
read-only renderState property of an
XRSession object indicates the returns a XRRenderState
object describing how the user's environment which should be rendered. The
information provided covers the minimum and maximum distance at which to render objects,
the vertical field of view to use when rendering the in the inline session
mode, and the XRWebGLLayer to render into for inline composition.
[Value("renderState")]
public XRRenderState RenderState { get; }

Property Value

XRRenderState

An XRRenderState object describing how to render the scene.

Remarks

While this property is read only, you can call the XRSession method
UpdateRenderState(XRRenderStateInit) to make changes.

See also on MDN

SupportedFrameRates

[Value("supportedFrameRates")]
public Float32Array? SupportedFrameRates { get; }

Property Value

Float32Array

TrackedSources

[Value("trackedSources")]
public XRInputSourceArray TrackedSources { get; }

Property Value

XRInputSourceArray

VisibilityState

NOTE
Experimental
The read-only visibilityState property of the
XRSession interface is a string indicating whether the WebXR content is
currently visible to the user, and if it is, whether it's the primary focus.
[Value("visibilityState")]
public XRVisibilityState VisibilityState { get; }

Property Value

XRVisibilityState

A string indicating whether or not the XR content is
visible to the user and if it is, whether or not it's currently the primary focus.The possible values of visibilityState are:

Remarks

Every time the visibility state changes, a
XRSession.Visibilitychange event is fired on the
XRSession object.

-XRSession.Visibilitychange event

See also on MDN

Methods

CancelAnimationFrame(ulong)

NOTE
Experimental
The cancelAnimationFrame() method of
the XRSession interface cancels an animation frame which was previously
requested by calling RequestAnimationFrame(XRFrameRequestCallback).
[Value("cancelAnimationFrame")]
public GlobalObject.Undefined CancelAnimationFrame(ulong handle)

Parameters

handle ulong

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

DeletePersistentAnchor(string)

[Value("deletePersistentAnchor")]
public Task<GlobalObject.Undefined> DeletePersistentAnchor(string uuid)

Parameters

uuid string

Returns

Task<GlobalObject.Undefined>

End()

NOTE
Experimental
The end() method shuts down the
XRSession on which it's called, returning a promise which resolves once
the session has fully shut down.
[Value("end")]
public Task<GlobalObject.Undefined> End()

Returns

Task<GlobalObject.Undefined>

A Promise that resolves without a value after any platform-specific steps
related to shutting down the session have completed. You can use the promise to do
things like update UI elements to reflect the shut down connection, trigger application
shut down, or whatever else you might need to do.

Remarks

InitiateRoomCapture()

[Value("initiateRoomCapture")]
public Task<GlobalObject.Undefined> InitiateRoomCapture()

Returns

Task<GlobalObject.Undefined>

RequestAnimationFrame(XRFrameRequestCallback)

NOTE
Experimental
The XRSession
method requestAnimationFrame(), much like the
Window method of the same name, schedules a callback to be executed the
next time the browser is ready to paint the session&apos;s virtual environment to the XR
display. The specified callback is executed once before the next repaint; if
you wish for it to be executed for the following repaint, you must
call requestAnimationFrame() again. This can be done from within the
callback itself.
[Value("requestAnimationFrame")]
public ulong RequestAnimationFrame(XRFrameRequestCallback callback)

Parameters

callback XRFrameRequestCallback

Returns

ulong

An integer value which serves as a unique, non-zero ID or handle you may pass to
CancelAnimationFrame(ulong) if you need to
remove the pending animation frame request.

Remarks

The callback takes two parameters as inputs: an XRFrame describing the
state of all tracked objects for the session, and a timestamp you can use to compute
any animation updates needed.

You can cancel a previously scheduled animation by calling
CancelAnimationFrame(ulong).

NOTE

Despite the obvious similarities between these methods and the
global Window.RequestAnimationFrame function
provided by the Window interface, you must not treat these as
interchangeable. There is no guarantee that the latter will work at all while
an immersive XR session is underway.

-Window.RequestAnimationFrame
-CancelAnimationFrame(ulong)

See also on MDN

RequestHitTestSource(XRHitTestOptionsInit)

NOTE
Experimental
The requestHitTestSource() method of the
XRSession interface returns a {{jsxref("Promise")}} that resolves with an XRHitTestSource object that can be passed to GetHitTestResults(XRHitTestSource).
[Value("requestHitTestSource")]
public Task<XRHitTestSource> RequestHitTestSource(XRHitTestOptionsInit options)

Parameters

options XRHitTestOptionsInit

Returns

Task<XRHitTestSource>

A {{jsxref("Promise")}} that resolves with an XRHitTestSource object.

Remarks

RequestHitTestSourceForTransientInput(XRTransientInputHitTestOptionsInit)

NOTE
Experimental
The requestHitTestSourceForTransientInput() method of the
XRSession interface returns a {{jsxref("Promise")}} that resolves with an XRTransientInputHitTestSource object that can be passed to GetHitTestResultsForTransientInput(XRTransientInputHitTestSource).
[Value("requestHitTestSourceForTransientInput")]
public Task<XRTransientInputHitTestSource> RequestHitTestSourceForTransientInput(XRTransientInputHitTestOptionsInit options)

Parameters

options XRTransientInputHitTestOptionsInit

Returns

Task<XRTransientInputHitTestSource>

A {{jsxref("Promise")}} that resolves with an XRTransientInputHitTestSource object.

Remarks

RequestLightProbe(XRLightProbeInit)

NOTE
Experimental
The requestLightProbe() method of the
XRSession interface returns a {{jsxref("Promise")}} that resolves with an XRLightProbe object that estimates lighting information at a given point in the user's environment.
[Value("requestLightProbe")]
public Task<XRLightProbe> RequestLightProbe(XRLightProbeInit options = null)

Parameters

options XRLightProbeInit

Returns

Task<XRLightProbe>

A {{jsxref("Promise")}} that resolves with an XRLightProbe object.

Remarks

RequestReferenceSpace(XRReferenceSpaceType)

NOTE
Experimental
The requestReferenceSpace() method of the
XRSession interface returns a {{JSxRef("promise")}} that resolves with
an instance of either XRReferenceSpace
or XRBoundedReferenceSpace as appropriate given the type of reference
space requested.
[Value("requestReferenceSpace")]
public Task<XRReferenceSpace> RequestReferenceSpace(XRReferenceSpaceType type)

Parameters

type XRReferenceSpaceType

Returns

Task<XRReferenceSpace>

A {{JSxRef("Promise")}} that resolves with an XRReferenceSpace object.The types of reference space are listed below, with brief information about their use cases and which interface is used to implement them.

Remarks

RestorePersistentAnchor(string)

[Value("restorePersistentAnchor")]
public Task<XRAnchor> RestorePersistentAnchor(string uuid)

Parameters

uuid string

Returns

Task<XRAnchor>

UpdateRenderState(XRRenderStateInit)

NOTE
Experimental
The updateRenderState() method of the XRSession interface of the WebXR API schedules changes to be applied to the active render state (XRRenderState) prior to rendering of the next frame.
[Value("updateRenderState")]
public GlobalObject.Undefined UpdateRenderState(XRRenderStateInit state = null)

Parameters

state XRRenderStateInit

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

UpdateTargetFrameRate(Number)

[Value("updateTargetFrameRate")]
public Task<GlobalObject.Undefined> UpdateTargetFrameRate(Number rate)

Parameters

rate Number

Returns

Task<GlobalObject.Undefined>