Fix pausing when camera state command hangs (#7475)

This commit is contained in:
Zookeeper Lee
2025-06-16 09:43:33 -04:00
committed by GitHub
parent 3936017f10
commit 4159cc0047
2 changed files with 34 additions and 18 deletions

View File

@ -1049,23 +1049,35 @@ export class CameraControls {
})
}
async saveRemoteCameraState() {
const cameraViewStateResponse =
await this.engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: { type: 'default_camera_get_view' },
})
if (!cameraViewStateResponse) return
if (
'resp' in cameraViewStateResponse &&
'modeling_response' in cameraViewStateResponse.resp.data &&
'data' in cameraViewStateResponse.resp.data.modeling_response &&
'view' in cameraViewStateResponse.resp.data.modeling_response.data
) {
this.oldCameraState =
cameraViewStateResponse.resp.data.modeling_response.data.view
}
saveRemoteCameraState(): Promise<void> {
return new Promise((resolve, reject) => {
// It's possible we've hit a disconnection, but the browser or nothing
// indicates this, other than the amount of time between our request
// and its response. Typically round-trip time is < 30ms. It seems safe
// then to wait 1 magnitude of time before calling this request toasted.
const timeoutId = setTimeout(reject, 300)
;(async () => {
const cameraViewStateResponse =
await this.engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: { type: 'default_camera_get_view' },
})
if (!cameraViewStateResponse) return
if (
'resp' in cameraViewStateResponse &&
'modeling_response' in cameraViewStateResponse.resp.data &&
'data' in cameraViewStateResponse.resp.data.modeling_response &&
'view' in cameraViewStateResponse.resp.data.modeling_response.data
) {
this.oldCameraState =
cameraViewStateResponse.resp.data.modeling_response.data.view
}
clearTimeout(timeoutId)
resolve()
})().catch(reject)
})
}
async tweenCameraToQuaternion(

View File

@ -229,7 +229,11 @@ export const engineStreamMachine = setup({
}
}
await rootContext.sceneInfra.camControls.saveRemoteCameraState()
try {
await rootContext.sceneInfra.camControls.saveRemoteCameraState()
} catch (e) {
console.warn('Save remote camera state timed out', e)
}
// Make sure we're on the next frame for no flickering between canvas
// and the video elements.