ReadonlystateCurrent state of the session.
This readonly property provides the current state of the session, which can be used to determine what operations are available and to monitor the session lifecycle.
Connect to the CloudXR server and start streaming.
Initiates connection to the CloudXR Runtime and transitions the session to SessionState.Connecting, then SessionState.Connected once streaming is active.
Disconnects from the CloudXR Runtime and terminates any streams.
Gracefully disconnects from the CloudXR Runtime and cleans up resources. The session transitions through the following states:
After disconnection, the session can be reconnected by calling connect() again.
Sends the view pose and input tracking data to the CloudXR Runtime.
Sends the current viewer pose (head position/orientation) and input tracking data (controllers, hand tracking) to the CloudXR Runtime. This data is essential for the Runtime to render the correct view and handle user input.
The current timestamp (DOMHighResTimeStamp) from the XR frame
The XR frame containing tracking data to send to the Runtime
True if the tracking data was sent successfully, false otherwise. Returns false if the session is not in Connected state.
// In your WebXR render loop
function renderFrame(time, frame) {
try {
// Send tracking data first
if (!session.sendTrackingStateToServer(time, frame)) {
console.warn('Failed to send tracking state');
return;
}
// Then render the frame
session.render(time, frame, xrWebGLLayer);
} catch (error) {
console.error('Error in render frame:', error);
}
}
// Start the render loop
xrSession.requestAnimationFrame(renderFrame);
Renders a frame from CloudXR.
Renders the current frame received from the CloudXR Runtime into the specified WebXR layer. Call this method every frame in your WebXR render loop after sending tracking data.
The current timestamp (DOMHighResTimeStamp) from the XR frame
The XR frame to render
The WebXR layer to render into (typically xrSession.renderState.baseLayer)
// Complete render loop
function renderFrame(time, frame) {
try {
// Send tracking data
session.sendTrackingStateToServer(time, frame);
// Render CloudXR content
session.render(time, frame, xrSession.renderState.baseLayer);
} catch (error) {
console.error('Error in render frame:', error);
}
// Continue the loop
xrSession.requestAnimationFrame(renderFrame);
}
// Start rendering
xrSession.requestAnimationFrame(renderFrame);
Send a custom message to the CloudXR server.
Sends a custom JSON message to the server through the CloudXR protocol. The message is serialized and sent via the streaming connection.
The message object to send to the server (must be a valid JSON object)
Defines the interface for CloudXR streaming sessions.
Provides the core functionality for managing CloudXR streaming sessions, including connection management, rendering, and communication with the CloudXR Runtime.
Example