OptionalonInvoked when streaming connects successfully.
Called when the session transitions to the Connected state and streaming is ready to begin. At this point, the session is ready for rendering and all WebGL resources have been initialized.
OptionalonInvoked when streaming stops (either by client or server).
Called when the session stops streaming, either due to a normal disconnection or an error condition. Check the error parameter to determine the reason for the stop.
Optionalerror: ErrorOptional error object if streaming stopped due to an error. If undefined, the stop was intentional (e.g., disconnect() called).
OptionalonInvoked before the session changes any WebGL state.
Called before the session modifies WebGL state during rendering operations. Use this to save the current WebGL state if needed for your application's rendering pipeline.
OptionalonInvoked after the session changes any WebGL state.
Called after the session has completed its WebGL state modifications during rendering operations. Use this to restore any WebGL state that your application needs.
OptionalonInvoked when a server message is received through any opaque data channel.
Raw message data from the server
onServerMessageReceived: (messageData) => {
const messageString = new TextDecoder().decode(messageData);
console.log('Received message:', messageString);
// Parse JSON if expected
try {
const message = JSON.parse(messageString);
console.log('Parsed message:', message);
} catch (error) {
console.log('Raw binary data:', messageData);
}
}
Defines callbacks for CloudXR session events.
Applications implement these callbacks to receive notifications about session lifecycle events and WebGL state changes. All callbacks are optional.
Example