Add a sessionavailable event that allows content to enter an XR session without a user gesture

This commit is contained in:
Alan Jeffrey 2020-07-10 14:09:18 -05:00
parent 714acb942c
commit 63663fada9
5 changed files with 39 additions and 1 deletions

View file

@ -7,6 +7,7 @@ use crate::dom::bindings::codegen::Bindings::XRSystemBinding::XRSessionInit;
use crate::dom::bindings::codegen::Bindings::XRSystemBinding::{XRSessionMode, XRSystemMethods};
use crate::dom::bindings::conversions::{ConversionResult, FromJSValConvertible};
use crate::dom::bindings::error::Error;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
@ -289,4 +290,26 @@ impl XRSystem {
// This must be called _after_ the promise is resolved
session.setup_initial_inputs();
}
// https://github.com/immersive-web/navigation/issues/10
pub fn dispatch_sessionavailable(&self) {
let xr = Trusted::new(self);
let global = self.global();
let window = global.as_window();
window
.task_manager()
.dom_manipulation_task_source()
.queue(
task!(fire_sessionavailable_event: move || {
// The sessionavailable event indicates user intent to enter an XR session
let xr = xr.root();
let interacting = ScriptThread::is_user_interacting();
ScriptThread::set_user_interacting(true);
xr.upcast::<EventTarget>().fire_bubbling_event(atom!("sessionavailable"));
ScriptThread::set_user_interacting(interacting);
}),
window.upcast(),
)
.unwrap();
}
}