mirror of
https://github.com/Cola-Echo/Cola.git
synced 2026-06-06 03:35:50 +00:00
Add files via upload
This commit is contained in:
@@ -58,10 +58,10 @@ export function startRealVoiceCall(initiator = 'user', contactIndex = currentCha
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查浏览器是否支持录音
|
// 检查浏览器是否支持录音(不阻止进入,可以用文字输入)
|
||||||
if (!AudioRecorder.isSupported()) {
|
const supportsRecording = AudioRecorder.isSupported();
|
||||||
alert('您的浏览器不支持录音功能');
|
if (!supportsRecording) {
|
||||||
return;
|
console.log('[可乐] 浏览器不支持录音,将使用文字输入模式');
|
||||||
}
|
}
|
||||||
|
|
||||||
callState.contactName = contact.name;
|
callState.contactName = contact.name;
|
||||||
@@ -152,7 +152,17 @@ function showCallPage() {
|
|||||||
|
|
||||||
// 语音按钮:只有支持录音时显示
|
// 语音按钮:只有支持录音时显示
|
||||||
if (talkBtn) talkBtn.style.display = supportsRecording ? 'flex' : 'none';
|
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';
|
if (textInputArea) textInputArea.style.display = 'flex';
|
||||||
|
|
||||||
|
|||||||
30
voice-api.js
30
voice-api.js
@@ -609,7 +609,35 @@ export class AudioRecorder {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
static isSupported() {
|
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 '未知原因';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user