XRSessionEvent

WebXR 设备 API 's XRSessionEvent interface describes an event which indicates the change of the state of an XRSession . These events occur, for example, when the session ends or the visibility of its context changes.

构造函数

XRSessionEvent()
Creates and returns a new XRSessionEvent object configured using the specified XRSessionEventInit object's values as available.

特性

In addition to properties inherited from its parent interface, Event , XRSessionEvent provides the folllowing:

session 只读
XRSession to which the event refers.

方法

While XRSessionEvent defines no methods, it inherits methods from its parent interface, Event .

Session event types

The following events are represented using the XRSessionEvent interface, and are permitted values for its type 特性。

end
Fired at the session when it has ended, after being terminated by the application or the user agent .
visibilitychange
Fired at the session whenever its visibility state changes.

范例

This example creates a listiener that watches for the visibility state of the session to change. It reacts by calling a function mySessionVisible() with a Boolean indicating whether or not the session is visible; this function might, for instance, spin up or reconfigure a worker that handles rendering the scene.

xrSession.addEventListener("visibilitystate", e => {
  switch(e.session.visibilitystate) {
    case "visible":
    case "visible-blurred":
      mySessionVisible(true);
      break;
    case "hidden":
      mySessionVisible(false);
      break;
  }
});
					

规范

规范 状态 Comment
WebXR 设备 API
The definition of 'XRSessionEvent' in that specification.
工作草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
XRSessionEvent Chrome 79 Edge 79 Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 79 Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 11.2
XRSessionEvent() 构造函数 Chrome 79 Edge 79 Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 79 Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 11.2
session Chrome 79 Edge 79 Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 79 Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 11.2

图例

完整支持
完整支持
不支持
不支持