mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 17:43:55 +08:00
Merge pull request #2868 from xinnan-tech/fix-digital-human
fix: 修复未绑定设备时状态处理
This commit is contained in:
@@ -17,6 +17,7 @@ export class WebSocketHandler {
|
|||||||
this.onChatMessage = null; // 新增:聊天消息回调
|
this.onChatMessage = null; // 新增:聊天消息回调
|
||||||
this.currentSessionId = null;
|
this.currentSessionId = null;
|
||||||
this.isRemoteSpeaking = false;
|
this.isRemoteSpeaking = false;
|
||||||
|
this.isEstablishConnection = false; // 新增:是否已建立连接
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送hello握手消息
|
// 发送hello握手消息
|
||||||
@@ -73,6 +74,7 @@ export class WebSocketHandler {
|
|||||||
handleTextMessage(message) {
|
handleTextMessage(message) {
|
||||||
if (message.type === 'hello') {
|
if (message.type === 'hello') {
|
||||||
log(`服务器回应:${JSON.stringify(message, null, 2)}`, 'success');
|
log(`服务器回应:${JSON.stringify(message, null, 2)}`, 'success');
|
||||||
|
this.isEstablishConnection = true;
|
||||||
} else if (message.type === 'tts') {
|
} else if (message.type === 'tts') {
|
||||||
this.handleTTSMessage(message);
|
this.handleTTSMessage(message);
|
||||||
} else if (message.type === 'audio') {
|
} else if (message.type === 'audio') {
|
||||||
|
|||||||
@@ -347,6 +347,14 @@ class UIController {
|
|||||||
this.addChatMessage('配置已保存', false);
|
this.addChatMessage('配置已保存', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理未绑定设备事件
|
||||||
|
handleUnboundDevice() {
|
||||||
|
const dialBtn = document.getElementById('dialBtn');
|
||||||
|
if (dialBtn) {
|
||||||
|
dialBtn.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 拨号成功后直接开始录音
|
// 拨号成功后直接开始录音
|
||||||
dialAndRecord() {
|
dialAndRecord() {
|
||||||
const recordBtn = document.getElementById('recordBtn');
|
const recordBtn = document.getElementById('recordBtn');
|
||||||
@@ -355,7 +363,11 @@ class UIController {
|
|||||||
if (wsHandler.isConnected() && wsHandler.websocket.onopen) {
|
if (wsHandler.isConnected() && wsHandler.websocket.onopen) {
|
||||||
clearInterval(this.wsTimer);
|
clearInterval(this.wsTimer);
|
||||||
this.wsTimer = null;
|
this.wsTimer = null;
|
||||||
recordBtn.click();
|
if (wsHandler.isEstablishConnection) {
|
||||||
|
recordBtn.click();
|
||||||
|
} else {
|
||||||
|
this.handleUnboundDevice();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
@@ -451,7 +463,7 @@ class UIController {
|
|||||||
dialBtn.querySelector('.btn-text').textContent = '挂断';
|
dialBtn.querySelector('.btn-text').textContent = '挂断';
|
||||||
dialBtn.classList.add('dial-active');
|
dialBtn.classList.add('dial-active');
|
||||||
|
|
||||||
this.dialAndRecord();
|
this.dialAndRecord();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hideModal('settingsModal');
|
this.hideModal('settingsModal');
|
||||||
|
|||||||
Reference in New Issue
Block a user