-
-
Save leemartin/6f9bab074f36e74a1a6034f14697bb2c to your computer and use it in GitHub Desktop.
Device Orientation Composable for Nuxt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const useOrientation = () => { | |
// Start orientation | |
// ---------- | |
const start = async () => { | |
// Promise | |
return new Promise((resolve, revoke) => { | |
// If request permission exists | |
if (window.DeviceOrientationEvent && typeof window.DeviceOrientationEvent.requestPermission === 'function') { | |
// Request permission | |
window.DeviceOrientationEvent.requestPermission() | |
.then(response => { | |
// Log | |
console.log('orientation permission: ', response) | |
// If granted | |
if (response == "granted") { | |
// Resolve | |
resolve() | |
} else { | |
// Revoke | |
revoke() | |
} | |
}) | |
.catch(e => { | |
// Log | |
console.log('orientation error: ', e) | |
// Revoke | |
revoke("This experience requires access to your device's motion.") | |
}) | |
} else { | |
// Log | |
console.log('orientation does not exist') | |
// Resolve | |
resolve() | |
} | |
}) | |
} | |
// Return | |
return { | |
start | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment