Add files via upload

This commit is contained in:
Cola-Echo
2025-12-31 10:16:52 +08:00
committed by GitHub
parent f9b003e0dc
commit 40526f614d
2 changed files with 44 additions and 6 deletions

View File

@@ -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';

View File

@@ -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 APIiOS Safari 需要 iOS 14.3+';
}
return '未知原因';
}
}