Skip to content
Snippets Groups Projects
Unverified Commit 1368863b authored by Robert Long's avatar Robert Long Committed by GitHub
Browse files

Merge pull request #198 from mozilla/feature/exit-on-blur

Exit scene on blur with grace period
parents caddce90 b8275191
No related branches found
No related tags found
No related merge requests found
{ {
"en": "en": {
{
"entry.screen-prefix": "Enter on ", "entry.screen-prefix": "Enter on ",
"entry.desktop-screen": "Screen", "entry.desktop-screen": "Screen",
"entry.mobile-screen": "Phone", "entry.mobile-screen": "Phone",
...@@ -33,7 +32,7 @@ ...@@ -33,7 +32,7 @@
"audio.granted-title": "Mic permissions granted", "audio.granted-title": "Mic permissions granted",
"audio.granted-subtitle": "You can still mute yourself in-game", "audio.granted-subtitle": "You can still mute yourself in-game",
"audio.granted-next": "NEXT", "audio.granted-next": "NEXT",
"exit.subtitle": "Your session has ended.", "exit.subtitle": "Your session has ended. Refresh your browser to start a new one.",
"autoexit.title": "Auto-ending session in ", "autoexit.title": "Auto-ending session in ",
"autoexit.title_units": " seconds", "autoexit.title_units": " seconds",
"autoexit.subtitle": "You have started another session.", "autoexit.subtitle": "You have started another session.",
......
...@@ -58,6 +58,7 @@ import HubChannel from "./utils/hub-channel"; ...@@ -58,6 +58,7 @@ import HubChannel from "./utils/hub-channel";
import "./systems/personal-space-bubble"; import "./systems/personal-space-bubble";
import "./systems/app-mode"; import "./systems/app-mode";
import "./systems/exit-on-blur";
import "./gltf-component-mappings"; import "./gltf-component-mappings";
...@@ -124,6 +125,9 @@ if (!store.state.profile.has_changed_name) { ...@@ -124,6 +125,9 @@ if (!store.state.profile.has_changed_name) {
} }
async function exitScene() { async function exitScene() {
if (NAF.connection.adapter && NAF.connection.adapter.localMediaStream) {
NAF.connection.adapter.localMediaStream.getTracks().forEach(t => t.stop());
}
hubChannel.disconnect(); hubChannel.disconnect();
const scene = document.querySelector("a-scene"); const scene = document.querySelector("a-scene");
scene.renderer.animate(null); // Stop animation loop, TODO A-Frame should do this scene.renderer.animate(null); // Stop animation loop, TODO A-Frame should do this
......
...@@ -107,6 +107,12 @@ class UIRoot extends Component { ...@@ -107,6 +107,12 @@ class UIRoot extends Component {
this.props.scene.addEventListener("loaded", this.onSceneLoaded); this.props.scene.addEventListener("loaded", this.onSceneLoaded);
this.props.scene.addEventListener("stateadded", this.onAframeStateChanged); this.props.scene.addEventListener("stateadded", this.onAframeStateChanged);
this.props.scene.addEventListener("stateremoved", this.onAframeStateChanged); this.props.scene.addEventListener("stateremoved", this.onAframeStateChanged);
this.props.scene.addEventListener("exit", this.exit);
}
componentWillUnmount() {
this.props.scene.removeEventListener("loaded", this.onSceneLoaded);
this.props.scene.removeEventListener("exit", this.exit);
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
......
AFRAME.registerSystem("exit-on-blur", {
init() {
this.onBlur = this.onBlur.bind(this);
this.onFocus = this.onFocus.bind(this);
window.addEventListener("blur", this.onBlur);
window.addEventListener("focus", this.onFocus);
this.exitTimeout = null;
},
onBlur() {
if (this.el.isMobile) {
this.exitTimeout = setTimeout(() => {
this.el.dispatchEvent(new CustomEvent("exit"));
}, 10 * 1000);
}
},
onFocus() {
if (this.el.isMobile) {
clearTimeout(this.exitTimeout);
}
},
remove() {
clearTimeout(this.exitTimeout);
window.removeEventListener("blur", this.onBlur);
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment