Configuration options for the session. Must include all required parameters such as serverAddress, serverPort, gl context, and per-eye dimensions.
Optionaldelegates: SessionDelegatesOptional delegate object to receive essential session events such as onStreamStarted, onStreamStopped, and WebGL state change notifications.
A Session object ready to connect to the CloudXR Runtime
// Basic session creation
const session = createSession({
serverAddress: '192.168.1.100',
serverPort: 49100,
useSecureConnection: false,
gl: webglContext,
perEyeWidth: 2048,
perEyeHeight: 1792,
referenceSpace: xrReferenceSpace
});
// With event delegates
const session = createSession(sessionOptions, {
onStreamStarted: () => {
console.info('CloudXR streaming started');
},
onStreamStopped: (error) => {
if (error) {
console.error('Streaming error:', error);
} else {
console.info('Streaming stopped normally');
}
}
});
// Connect to CloudXR Runtime
if (session.connect()) {
console.info('Connection initiated');
}
// Complete WebXR integration example
async function setupCloudXR() {
// Request WebXR session
const xrSession = await navigator.xr.requestSession('immersive-vr', {
requiredFeatures: ['local-floor']
});
// Get WebGL context and reference space
const gl = xrSession.renderState.baseLayer.context;
const referenceSpace = await xrSession.requestReferenceSpace('local-floor');
// Create CloudXR streaming session
const session = createSession({
serverAddress: 'your-server-ip',
serverPort: 49100,
useSecureConnection: false,
gl: gl,
perEyeWidth: 2048,
perEyeHeight: 1792,
referenceSpace: referenceSpace,
deviceFrameRate: 90,
maxStreamingBitrateKbps: 150000
}, {
onStreamStarted: () => console.info('Ready to render'),
onStreamStopped: (error) => console.info('Streaming stopped', error)
});
// Connect and start rendering
if (session.connect()) {
function renderFrame(time, frame) {
session.sendTrackingStateToServer(time, frame);
session.render(time, frame, xrSession.renderState.baseLayer);
xrSession.requestAnimationFrame(renderFrame);
}
xrSession.requestAnimationFrame(renderFrame);
}
}
Creates a new CloudXR streaming session with the provided configuration.
This is the primary entry point for creating CloudXR streaming sessions. The returned session is ready to be connected to the CloudXR Runtime using the connect() method.