From 8829593b4380c85cfa33193a9e4e41dd3ffcaf8b Mon Sep 17 00:00:00 2001 From: "Daniel W. Steinbrook" Date: Mon, 8 Jul 2024 20:55:13 -0400 Subject: [PATCH] Really make device orientation request user-triggerd (#40) --- src/components/MainModeSelector.vue | 4 ++++ src/utils/tracker.js | 11 +---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/components/MainModeSelector.vue b/src/components/MainModeSelector.vue index e051d26..d7728a7 100644 --- a/src/components/MainModeSelector.vue +++ b/src/components/MainModeSelector.vue @@ -25,6 +25,8 @@ import mode_enter_wav from "/assets/sounds/mode_enter.wav"; import { inject, ref } from 'vue'; import { playSpatialSpeech } from '../utils/sound.js'; +import { startCompassListener } from "../utils/heading.js"; +import { myLocation } from '../store/location.js'; const props = defineProps({ tracker: Object, @@ -42,6 +44,8 @@ var wakeLock = null; async function toggleMode(newMode) { // required for iOS Safari: first speech must be directly triggered by user action playSpatialSpeech(" "); + // ...as well as device orientation tracking + startCompassListener((h) => myLocation.setHeading(h)); // Clear queued audio if (activeMode.value) { diff --git a/src/utils/tracker.js b/src/utils/tracker.js index 22ac57a..25ea1c0 100644 --- a/src/utils/tracker.js +++ b/src/utils/tracker.js @@ -1,4 +1,3 @@ -import { startCompassListener } from "./heading.js"; import { myLocation } from '../store/location.js'; /* @@ -11,29 +10,21 @@ Implementation of an interface for user position tracking: // Interfaces with device geolocation/orientation sensors. export function realTracker() { let watchPositionHandler = null; - let headingHandler = (heading) => { - myLocation.setHeading(heading); - }; return { start() { - startCompassListener(headingHandler); watchPositionHandler = watchLocation((latitude, longitude) => { myLocation.setLocation(latitude, longitude); - }); + }); }, stop() { if (watchPositionHandler) { navigator.geolocation.clearWatch(watchPositionHandler); - window.removeEventListener("deviceorientation", headingHandler); watchPositionHandler = null; } }, async current() { - // Need compass for positional audio regardless of location tracking - startCompassListener(headingHandler); - return new Promise((resolve, reject) => { getLocation() .then((coords) => {