From 9c69862a88b2b6fc7c821fc76df02af3314cc552 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Mon, 10 Jul 2017 21:46:41 -0700 Subject: [PATCH 1/2] Introduce concept of deferred session requests --- explainer.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/explainer.md b/explainer.md index e2c50201..561e2f01 100644 --- a/explainer.md +++ b/explainer.md @@ -749,6 +749,29 @@ xrSession.addEventListener('resetpose', xrSessionEvent => { }); ``` +### Page navigation + +WebXR applications can, like any web page, link to other pages. In the context of an exclusive `XRSession`, this is handled by setting `window.location` to the desired URL when the user performs some action. If the page being linked to is not XR-capable the user will either have to remove the XR device to view it or the page could be shown as a 2D page in a XR browser. + +If the page being navigated to is XR capable, however, it's frequently desirable to allow the developer to immediately create an exclusive `XRSession` for that page as well, so that the user feels as though they are navigating through a single continuous XR experience. To allow this the UA tracks when a page navigates without ending an active exclusive session first. This flags the newly loaded page as "XR navigable". + +In order to start presenting automatically when a page is XR navigable, pages can make a "deferred" session request. To request a deferred session the option `{ waitForNavigate: true }` is passed into the `requestSession` call. If the page is XR navigable, the request will be resolved when the page is ready to begin presenting. If the page is not XR navigable the request will reject immediately. + +Deferred sessions must be exclusive. If a non-exclusive deferred session is requested the promise will immediately be rejected. Deferred requests do not need to be made within a user gesture. Only one session request with the `waitForNavigate` option is allowed per page and subsequent requests using `waitForNavigate` will be rejected immediately. The page's XR navigable state must expire after all listeners for the `window`'s `load` event have fired. + +```js +window.addEventListener('load', () => { + // Requests that a session be created if this page was navigated to while the + // previous page was viewing WebXR content. + xrDevice.requestSession({ exclusive: true, waitForNavigate: true }).then(OnSessionStarted); +}); +``` + +> **Non-normative Notes:** +> - Pages should not rely exclusively on deferred sessions as a method for presenting XR content, since it is not guaranteed that they will be supported in all environments. An in-page button for starting XR should always be provided as a best practice. +> - UAs may place additional restrictions on what conditions are considered XR navigable, such as restricting it to only same-origin URLs. +> - The UA should provide a visual transition between the two pages. Additionally, if the UA cannot display pages in XR it is recommended that it should instruct the user to remove the headset once the UA switches to displaying a 2D page. + ## Appendix A: I don’t understand why this is a new API. Why can’t we use… ### `DeviceOrientation` Events @@ -810,6 +833,7 @@ partial interface Navigator { dictionary XRSessionCreationOptions { boolean exclusive = false; + boolean waitForNavigate = false; XRPresentationContext outputContext; }; From ebb744b9a4bd21ae01f7041f833c4a4a30b98ac9 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Tue, 3 Apr 2018 12:30:03 -0700 Subject: [PATCH 2/2] Partially addressing @ddorwin's comments. --- explainer.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/explainer.md b/explainer.md index 561e2f01..08d77bd3 100644 --- a/explainer.md +++ b/explainer.md @@ -753,11 +753,11 @@ xrSession.addEventListener('resetpose', xrSessionEvent => { WebXR applications can, like any web page, link to other pages. In the context of an exclusive `XRSession`, this is handled by setting `window.location` to the desired URL when the user performs some action. If the page being linked to is not XR-capable the user will either have to remove the XR device to view it or the page could be shown as a 2D page in a XR browser. -If the page being navigated to is XR capable, however, it's frequently desirable to allow the developer to immediately create an exclusive `XRSession` for that page as well, so that the user feels as though they are navigating through a single continuous XR experience. To allow this the UA tracks when a page navigates without ending an active exclusive session first. This flags the newly loaded page as "XR navigable". +If the page being navigated to is XR capable, however, it's frequently desirable to allow the developer to immediately create an exclusive `XRSession` for that page as well, so that the user feels as though they are navigating through a single continuous XR experience. This is triggered when a page initiates navigation without ending an active exclusive session first. When this happens, if the UA supports XR navigation and does not suppress the navigation for other reasons, the UA sets an internal "allow XR navigation" flag to true. -In order to start presenting automatically when a page is XR navigable, pages can make a "deferred" session request. To request a deferred session the option `{ waitForNavigate: true }` is passed into the `requestSession` call. If the page is XR navigable, the request will be resolved when the page is ready to begin presenting. If the page is not XR navigable the request will reject immediately. +In order for the next page to start presenting automatically when the UA allows XR navigation, pages can make a "deferred" session request. To create a deferred session request the option `{ waitForNavigate: true }` is passed into the `requestSession` call. If the UA's allow XR navigation flag is set, the request will be resolved when the page is ready to begin presenting. If the UA's allow XR navigation flag is not set, the request will reject immediately. -Deferred sessions must be exclusive. If a non-exclusive deferred session is requested the promise will immediately be rejected. Deferred requests do not need to be made within a user gesture. Only one session request with the `waitForNavigate` option is allowed per page and subsequent requests using `waitForNavigate` will be rejected immediately. The page's XR navigable state must expire after all listeners for the `window`'s `load` event have fired. +Deferred sessions requests must be exclusive. If a non-exclusive deferred session request is made, the promise will immediately be rejected. Deferred session requests do not need to be made within a user gesture. Only one session request with the `waitForNavigate` option is allowed per page and subsequent requests using `waitForNavigate` will be rejected immediately. The UA's allow XR navigation flag must revert to false after all listeners for the `window`'s `load` event have fired. ```js window.addEventListener('load', () => { @@ -768,7 +768,7 @@ window.addEventListener('load', () => { ``` > **Non-normative Notes:** -> - Pages should not rely exclusively on deferred sessions as a method for presenting XR content, since it is not guaranteed that they will be supported in all environments. An in-page button for starting XR should always be provided as a best practice. +> - Pages should not rely exclusively on deferred session requests as a method for presenting XR content, since it is not guaranteed that they will be supported in all environments. An in-page button for starting XR should always be provided as a best practice. > - UAs may place additional restrictions on what conditions are considered XR navigable, such as restricting it to only same-origin URLs. > - The UA should provide a visual transition between the two pages. Additionally, if the UA cannot display pages in XR it is recommended that it should instruct the user to remove the headset once the UA switches to displaying a 2D page.