mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 17:43:55 +08:00
优化:拆分test_page.html,把一部分document操作的代码提取出来,减少单个文件大小,且把logger.js和xiaoZhiConnect.js也提取出来
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
// DOM元素
|
||||||
|
const connectButton = document.getElementById('connectButton');
|
||||||
|
const serverUrlInput = document.getElementById('serverUrl');
|
||||||
|
const connectionStatus = document.getElementById('connectionStatus');
|
||||||
|
const messageInput = document.getElementById('messageInput');
|
||||||
|
const sendTextButton = document.getElementById('sendTextButton');
|
||||||
|
const recordButton = document.getElementById('recordButton');
|
||||||
|
const stopButton = document.getElementById('stopButton');
|
||||||
|
const conversationDiv = document.getElementById('conversation');
|
||||||
|
const logContainer = document.getElementById('logContainer');
|
||||||
|
let visualizerCanvas = document.getElementById('audioVisualizer');
|
||||||
|
|
||||||
|
// ota 是否连接成功,修改成对应的样式
|
||||||
|
export function otaStatusStyle (flan) {
|
||||||
|
if(flan){
|
||||||
|
document.getElementById('otaStatus').textContent = 'ota已连接';
|
||||||
|
document.getElementById('otaStatus').style.color = 'green';
|
||||||
|
}else{
|
||||||
|
document.getElementById('otaStatus').textContent = 'ota未连接';
|
||||||
|
document.getElementById('otaStatus').style.color = 'red';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ota 是否连接成功,修改成对应的样式
|
||||||
|
export function getLogContainer (flan) {
|
||||||
|
return logContainer;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
const logContainer = document.getElementById('logContainer');
|
import { getLogContainer } from '../document.js'
|
||||||
|
|
||||||
|
const logContainer = getLogContainer();
|
||||||
|
// 日志记录函数
|
||||||
export function log(message, type = 'info') {
|
export function log(message, type = 'info') {
|
||||||
// 将消息按换行符分割成多行
|
// 将消息按换行符分割成多行
|
||||||
const lines = message.split('\n');
|
const lines = message.split('\n');
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { log } from './utils/logger.js';
|
import { log } from './utils/logger.js';
|
||||||
|
import { otaStatusStyle } from './document.js'
|
||||||
|
|
||||||
// WebSocket 连接
|
// WebSocket 连接
|
||||||
export async function webSocketConnect(otaUrl,wsUrl,config){
|
export async function webSocketConnect(otaUrl,wsUrl,config){
|
||||||
@@ -88,12 +89,10 @@ async function sendOTA(otaUrl, config) {
|
|||||||
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
||||||
|
|
||||||
const result = await res.json();
|
const result = await res.json();
|
||||||
document.getElementById('otaStatus').textContent = 'ota已连接';
|
otaStatusStyle(true)
|
||||||
document.getElementById('otaStatus').style.color = 'green';
|
|
||||||
return true; // 成功
|
return true; // 成功
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
document.getElementById('otaStatus').textContent = 'ota未连接';
|
otaStatusStyle(false)
|
||||||
document.getElementById('otaStatus').style.color = 'red';
|
|
||||||
return false; // 失败
|
return false; // 失败
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user