diff --git a/real-voice-call.js b/real-voice-call.js index 6f3676b..e204f1d 100644 --- a/real-voice-call.js +++ b/real-voice-call.js @@ -58,10 +58,10 @@ export function startRealVoiceCall(initiator = 'user', contactIndex = currentCha return; } - // 检查浏览器是否支持录音 - if (!AudioRecorder.isSupported()) { - alert('您的浏览器不支持录音功能'); - return; + // 检查浏览器是否支持录音(不阻止进入,可以用文字输入) + const supportsRecording = AudioRecorder.isSupported(); + if (!supportsRecording) { + console.log('[可乐] 浏览器不支持录音,将使用文字输入模式'); } callState.contactName = contact.name; @@ -152,7 +152,17 @@ function showCallPage() { // 语音按钮:只有支持录音时显示 if (talkBtn) talkBtn.style.display = supportsRecording ? 'flex' : 'none'; - if (talkHint) talkHint.style.display = supportsRecording ? 'block' : 'none'; + if (talkHint) { + if (supportsRecording) { + talkHint.style.display = 'block'; + talkHint.textContent = '点击开始说话,再次点击发送'; + } else { + // 显示不支持的原因 + talkHint.style.display = 'block'; + talkHint.textContent = '💡 ' + AudioRecorder.getUnsupportedReason(); + talkHint.style.color = '#ff9800'; + } + } // 文字输入:始终显示,方便用户选择打字或语音 if (textInputArea) textInputArea.style.display = 'flex'; diff --git a/voice-api.js b/voice-api.js index 845db80..0aada1e 100644 --- a/voice-api.js +++ b/voice-api.js @@ -609,7 +609,35 @@ export class AudioRecorder { * @returns {boolean} */ static isSupported() { - return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia); + const hasGetUserMedia = !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia); + const hasMediaRecorder = typeof MediaRecorder !== 'undefined'; + const isSecureContext = window.isSecureContext; + + console.log('[可乐] 录音支持检测:', { + getUserMedia: hasGetUserMedia, + MediaRecorder: hasMediaRecorder, + isSecureContext: isSecureContext, + protocol: location.protocol + }); + + return hasGetUserMedia && hasMediaRecorder; + } + + /** + * 获取不支持录音的原因 + * @returns {string} + */ + static getUnsupportedReason() { + if (!window.isSecureContext) { + return '需要 HTTPS 安全连接才能使用录音功能'; + } + if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) { + return '浏览器不支持 getUserMedia API'; + } + if (typeof MediaRecorder === 'undefined') { + return '浏览器不支持 MediaRecorder API(iOS Safari 需要 iOS 14.3+)'; + } + return '未知原因'; } }