Skip to content

Commit

Permalink
Really make device orientation request user-triggerd (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
steinbro committed Jul 9, 2024
1 parent 90c7b6f commit 8829593
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/components/MainModeSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
11 changes: 1 addition & 10 deletions src/utils/tracker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { startCompassListener } from "./heading.js";
import { myLocation } from '../store/location.js';

/*
Expand All @@ -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) => {
Expand Down

0 comments on commit 8829593

Please sign in to comment.