Init
This commit is contained in:
1 parent
dd596f16b9
commit
3c052a8b43
25 files changed
+2252
-74
No files matched your search
@@ -0,0 +1,52 @@
|
||||
export type PermissionStateResult = 'granted' | 'prompt' | 'denied' | 'unsupported';
|
||||
|
||||
/**
|
||||
* Check GPS / Geolocation permission status
|
||||
*/
|
||||
export async function checkGpsPermission(): Promise<PermissionStateResult> {
|
||||
if (typeof window === 'undefined' || !('permissions' in navigator)) {
|
||||
return 'unsupported';
|
||||
}
|
||||
|
||||
try {
|
||||
const status = await navigator.permissions.query({ name: 'geolocation' });
|
||||
return status.state; // 'granted' | 'prompt' | 'denied'
|
||||
} catch {
|
||||
return 'unsupported';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Camera permission status with fallback
|
||||
*/
|
||||
export async function checkCameraPermission(): Promise<PermissionStateResult> {
|
||||
if (typeof window === 'undefined') return 'unsupported';
|
||||
|
||||
// 1. Try modern Permissions API query
|
||||
if ('permissions' in navigator) {
|
||||
try {
|
||||
const status = await navigator.permissions.query({ name: 'camera' as PermissionName });
|
||||
return status.state;
|
||||
} catch {
|
||||
// Browser doesn't support 'camera' in permissions.query (e.g., Safari)
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fallback: Inspect mediaDevice device labels
|
||||
if ('mediaDevices' in navigator && 'enumerateDevices' in navigator.mediaDevices) {
|
||||
try {
|
||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
||||
const videoInputs = devices.filter((device) => device.kind === 'videoinput');
|
||||
|
||||
// If camera label is not empty, permission has already been granted
|
||||
if (videoInputs.some((device) => device.label !== '')) {
|
||||
return 'granted';
|
||||
}
|
||||
return 'prompt';
|
||||
} catch {
|
||||
return 'unsupported';
|
||||
}
|
||||
}
|
||||
|
||||
return 'unsupported';
|
||||
}
|
||||
Reference in new issue
Block a user