This commit is contained in:
2025-09-05 20:43:27 +08:00
parent 0b4e6c5285
commit b6afe426d8

View File

@@ -151,7 +151,7 @@
// ==== 插入WebSocket认证代码 ==== // ==== 插入WebSocket认证代码 ====
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${wsProtocol}//${window.location.host}/ws/audio-evaluation?token=${getAuthToken()}`; const wsUrl = `${wsProtocol}//${window.location.host}/ws/audio-evaluation`;
const ws = new WebSocket(wsUrl); const ws = new WebSocket(wsUrl);
// WebSocket事件处理 // WebSocket事件处理
@@ -166,7 +166,6 @@
statusDiv.className = 'status error'; statusDiv.className = 'status error';
}; };
// ==== 插入结束 ==== // ==== 插入结束 ====
// 使用更明确的提示并添加详细的错误处理 // 使用更明确的提示并添加详细的错误处理
const stream = await navigator.mediaDevices.getUserMedia({ audio: true }) const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
.catch(err => { .catch(err => {
@@ -329,11 +328,6 @@
resultContent.innerHTML = html; resultContent.innerHTML = html;
} }
// 在<script>标签内添加getAuthToken实现
function getAuthToken() {
// 实际项目中应从Cookie、localStorage或后端API获取
return 'your_auth_token_here'; // 临时占位,需替换为真实认证逻辑
}
// 页面卸载时关闭连接 // 页面卸载时关闭连接
window.addEventListener('beforeunload', () => { window.addEventListener('beforeunload', () => {