File size: 1,652 Bytes
ec50620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, { useState } from 'react';
import './IOSModal.scss';

interface IOSModalProps {
  isOpen: boolean;
  onClose: () => void;
}

export const IOSModal: React.FC<IOSModalProps> = ({ isOpen, onClose }) => {
  const [error, setError] = useState<string | null>(null);

  const handleMicPermission = async () => {
    try {
      console.log('🎤 Requesting iOS microphone permission from modal...');
      const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
      console.log('✅ iOS microphone permission granted from modal!');
      // Stop the stream since we don't need it yet - we'll request it again when recording starts
      stream.getTracks().forEach(track => track.stop());
      setError(null);
      onClose();
    } catch (err) {
      console.error('❌ iOS microphone permission denied from modal:', err);
      setError(err instanceof Error ? err.message : 'Failed to access microphone');
    }
  };

  if (!isOpen) return null;

  return (
    <div className="ios-modal-overlay">
      <div className="ios-modal">
        <h2>Microphone Access Required</h2>
        <p>
          To use this app on iOS, we need permission to access your microphone.
          Please tap "Allow" when prompted.
        </p>
        <p>
          If you've denied permission, you'll need to enable it in your device settings.
        </p>
        {error && (
          <p className="error-message">
            Error: {error}
          </p>
        )}
        <button onClick={handleMicPermission} className="ios-modal-button">
          {error ? 'Try Again' : 'Got it'}
        </button>
      </div>
    </div>
  );
};