When entering an immersive-ar or immersive-vr session, there is a noticeable delay of a few seconds, which interrupts the user flow. While this is acceptable for most user experiences, it becomes cumbersome in live coding environments, where immediate feedback is crucial.
Current Problem
Typically, a new XR session is created at the start of every p5.js sketch. In live coding scenarios, like with P5LIVE (which runs p5 sketches in an iframe), the frequent session resets slow down the feedback loop. This results in a frustrating experience, as every time the sketch is restarted, the XR session also needs to be recreated.
Proposed Solution
The goal is to initiate the XRSession only once and reuse it throughout the live coding session, even when the sketch restarts. In P5LIVE, the sketch runs in an iframe, and code can be hoisted to the parent frame that contains both the editor and the sketch. Using this mechanism, we can maintain the XRSession even when the p5 session restarts.
Reuse of XRSession: If the p5 sketch is restarted (which may happen often in a live coding context), the XRSession can persist unless there is a specific need for new permissions (which is an edge case).
Checking for P5 Sessions: Some simple checks are implemented to ensure this method works primarily with P5LIVE. However, the same approach could theoretically be extended to other iframe-based use cases.
P5 Web Editor Compatibility: Although this method could potentially work with the p5 web editor in a similar live coding mode, the editor currently restarts the entire sketch, which introduces a lag. Future iterations may include optimizations for the p5 web editor as well.
Goal
For now, the solution will be focused on making it work with P5LIVE, as it has the structure (iframe hoisting) needed to reuse the XRSession effectively. Once the session is started, the user should be able to live code without ever having to manually press the Enter/Exit XR button again.
When entering an
immersive-ar
orimmersive-vr
session, there is a noticeable delay of a few seconds, which interrupts the user flow. While this is acceptable for most user experiences, it becomes cumbersome in live coding environments, where immediate feedback is crucial.Current Problem
Typically, a new XR session is created at the start of every p5.js sketch. In live coding scenarios, like with P5LIVE (which runs p5 sketches in an iframe), the frequent session resets slow down the feedback loop. This results in a frustrating experience, as every time the sketch is restarted, the XR session also needs to be recreated.
Proposed Solution
The goal is to initiate the XRSession only once and reuse it throughout the live coding session, even when the sketch restarts. In P5LIVE, the sketch runs in an iframe, and code can be hoisted to the parent frame that contains both the editor and the sketch. Using this mechanism, we can maintain the XRSession even when the p5 session restarts.
Goal
For now, the solution will be focused on making it work with P5LIVE, as it has the structure (iframe hoisting) needed to reuse the XRSession effectively. Once the session is started, the user should be able to live code without ever having to manually press the Enter/Exit XR button again.