38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
import type { RuntimePlatform } from './platform-detection.rules';
|
|
|
|
export type MobileMediaPermissionState = 'granted' | 'denied' | 'prompt' | string;
|
|
|
|
export interface MobileCapturePermissionResult {
|
|
microphone?: MobileMediaPermissionState;
|
|
camera?: MobileMediaPermissionState;
|
|
}
|
|
|
|
/** Whether a Capacitor permission alias was granted by the native shell. */
|
|
export function isMobileCapturePermissionGranted(state: MobileMediaPermissionState | undefined): boolean {
|
|
return state === 'granted';
|
|
}
|
|
|
|
/** Native Android/iOS shells need an explicit runtime grant before WebRTC capture works reliably. */
|
|
export function shouldPreflightMobileCapturePermissions(runtime: RuntimePlatform): boolean {
|
|
return runtime === 'capacitor';
|
|
}
|
|
|
|
/**
|
|
* Only an explicit native denial blocks capture. Any other state (granted, a
|
|
* dismissed prompt, or an unknown value) defers to the WebView getUserMedia
|
|
* permission flow, which re-prompts through Capacitor's WebChromeClient.
|
|
*/
|
|
function isCaptureBlockedByNativeDenial(state: MobileMediaPermissionState | undefined): boolean {
|
|
return state === 'denied';
|
|
}
|
|
|
|
/** Resolve whether voice capture can proceed after a native permission request. */
|
|
export function isVoiceCaptureAllowed(result: MobileCapturePermissionResult): boolean {
|
|
return !isCaptureBlockedByNativeDenial(result.microphone);
|
|
}
|
|
|
|
/** Resolve whether camera capture can proceed after a native permission request. */
|
|
export function isCameraCaptureAllowed(result: MobileCapturePermissionResult): boolean {
|
|
return !isCaptureBlockedByNativeDenial(result.camera);
|
|
}
|