UNPKG

react-audio-recorder-hook

Version:

A powerful TypeScript-based React hook that provides complete audio recording capabilities with pause/resume functionality, recording management, and audio processing

119 lines 3.57 kB
"use strict"; /** * Utility functions for browser compatibility detection */ Object.defineProperty(exports, "__esModule", { value: true }); exports.isMediaRecorderSupported = isMediaRecorderSupported; exports.isGetUserMediaSupported = isGetUserMediaSupported; exports.isAudioContextSupported = isAudioContextSupported; exports.isMimeTypeSupported = isMimeTypeSupported; exports.isIOS = isIOS; exports.getBestSupportedMimeType = getBestSupportedMimeType; exports.isAudioRecordingSupported = isAudioRecordingSupported; exports.isMobileBrowser = isMobileBrowser; /** * Check if MediaRecorder is supported in the current browser */ function isMediaRecorderSupported() { return typeof window !== 'undefined' && 'MediaRecorder' in window; } /** * Check if getUserMedia is supported in the current browser */ function isGetUserMediaSupported() { return (typeof navigator !== 'undefined' && 'mediaDevices' in navigator && 'getUserMedia' in navigator.mediaDevices); } /** * Check if the AudioContext API is supported */ function isAudioContextSupported() { return (typeof window !== 'undefined' && ('AudioContext' in window || 'webkitAudioContext' in window)); } /** * Check if the specified MIME type is supported for recording */ function isMimeTypeSupported(mimeType) { if (!isMediaRecorderSupported()) { return false; } return MediaRecorder.isTypeSupported(mimeType); } /** * Check if the current browser is iOS */ function isIOS() { if (typeof navigator === 'undefined') return false; return /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window); // Excludes IE11 } /** * Get the best supported MIME type for the current browser */ function getBestSupportedMimeType() { if (!isMediaRecorderSupported()) { return ''; } // iOS-optimized MIME types first if on iOS if (isIOS()) { const iOSMimeTypes = [ 'audio/mp4;codecs=mp4a', 'audio/mp4', 'audio/aac', 'audio/x-m4a', 'audio/mpeg', 'audio/3gpp', // Common on mobile 'audio/wav', 'audio/webm', // Last resort ]; for (const mimeType of iOSMimeTypes) { if (MediaRecorder.isTypeSupported(mimeType)) { return mimeType; } } } // Standard MIME types for other browsers (original list) const mimeTypes = [ 'audio/webm;codecs=opus', 'audio/webm', 'audio/ogg;codecs=opus', 'audio/ogg', 'audio/mp4', 'audio/wav', ]; for (const mimeType of mimeTypes) { if (MediaRecorder.isTypeSupported(mimeType)) { return mimeType; } } return 'audio/webm'; // Fallback } /** * Comprehensive check if audio recording is fully supported */ function isAudioRecordingSupported() { return (isMediaRecorderSupported() && isGetUserMediaSupported() && isAudioContextSupported() && getBestSupportedMimeType() !== ''); } /** * Check if the current browser is mobile */ function isMobileBrowser() { if (typeof navigator === 'undefined') return false; return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); } exports.default = { isMediaRecorderSupported, isGetUserMediaSupported, isAudioContextSupported, isMimeTypeSupported, getBestSupportedMimeType, isAudioRecordingSupported, isMobileBrowser, isIOS, }; //# sourceMappingURL=browserSupport.js.map