mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-29 18:23:59 +08:00
fix:拨号按钮和摄像头按钮增加防抖机制
This commit is contained in:
@@ -99,8 +99,14 @@ class UIController {
|
|||||||
|
|
||||||
// Dial button
|
// Dial button
|
||||||
const dialBtn = document.getElementById('dialBtn');
|
const dialBtn = document.getElementById('dialBtn');
|
||||||
|
let dialTimer = null;
|
||||||
if (dialBtn) {
|
if (dialBtn) {
|
||||||
dialBtn.addEventListener('click', () => {
|
dialBtn.addEventListener('click', () => {
|
||||||
|
if (dialTimer) {
|
||||||
|
clearTimeout(dialTimer);
|
||||||
|
dialTimer = null;
|
||||||
|
}
|
||||||
|
dialTimer = setTimeout(() => {
|
||||||
const wsHandler = getWebSocketHandler();
|
const wsHandler = getWebSocketHandler();
|
||||||
const isConnected = wsHandler.isConnected();
|
const isConnected = wsHandler.isConnected();
|
||||||
|
|
||||||
@@ -122,13 +128,20 @@ class UIController {
|
|||||||
// Start connection process
|
// Start connection process
|
||||||
this.handleConnect();
|
this.handleConnect();
|
||||||
}
|
}
|
||||||
|
}, 300);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camera button
|
// Camera button
|
||||||
const cameraBtn = document.getElementById('cameraBtn');
|
const cameraBtn = document.getElementById('cameraBtn');
|
||||||
|
let cameraTimer = null;
|
||||||
if (cameraBtn) {
|
if (cameraBtn) {
|
||||||
cameraBtn.addEventListener('click', () => {
|
cameraBtn.addEventListener('click', () => {
|
||||||
|
if (cameraTimer) {
|
||||||
|
clearTimeout(cameraTimer);
|
||||||
|
cameraTimer = null;
|
||||||
|
}
|
||||||
|
cameraTimer = setTimeout(() => {
|
||||||
const cameraContainer = document.getElementById('cameraContainer');
|
const cameraContainer = document.getElementById('cameraContainer');
|
||||||
if (!cameraContainer) {
|
if (!cameraContainer) {
|
||||||
log('摄像头容器不存在', 'warning');
|
log('摄像头容器不存在', 'warning');
|
||||||
@@ -162,6 +175,7 @@ class UIController {
|
|||||||
log('startCamera函数未定义', 'warning');
|
log('startCamera函数未定义', 'warning');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, 300);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user