diff --git a/src/components/EngineStream.tsx b/src/components/EngineStream.tsx index 0c61f63f7..3b6a1154a 100644 --- a/src/components/EngineStream.tsx +++ b/src/components/EngineStream.tsx @@ -406,11 +406,17 @@ export const EngineStream = (props: { // On various inputs save the camera state, in case we get disconnected. useEffect(() => { + // Only start saving after we are playing the stream (which means + // the scene is ready.) + // Also prevents us from stepping on the toes of the camera restoration. + if (engineStreamState.value !== EngineStreamState.Playing) return + const onInput = () => { // Save the remote camera state to restore on stream restore. // Fire-and-forget because we don't know when a camera movement is // completed on the engine side (there are no responses to data channel // mouse movements.) + sceneInfra.camControls.saveRemoteCameraState().catch(trap) } @@ -426,7 +432,7 @@ export const EngineStream = (props: { window.document.removeEventListener('scroll', onInput) window.document.removeEventListener('touchend', onInput) } - }, []) + }, [engineStreamState.value]) const isNetworkOkay = overallState === NetworkHealthState.Ok ||