This commit is contained in:
zhangzheng
2026-03-10 19:09:41 +08:00
parent ca23a771b3
commit b4c41e42c9
4 changed files with 73 additions and 46 deletions

View File

@@ -15,25 +15,25 @@ let connectionId = "";
/**
* 初始化应用
*/
function initApp() {
// 初始化渲染器
renderer = new UIRenderer(store);
// function initApp() {
// // 初始化渲染器
// renderer = new UIRenderer(store);
// 初始化WebSocket连接
wsManager.connect();
// // 初始化WebSocket连接
// wsManager.connect();
// 绑定WebSocket事件
bindWebSocketEvents();
// // 绑定WebSocket事件
// bindWebSocketEvents();
// 绑定DOM事件
bindDomEvents();
// // 绑定DOM事件
// bindDomEvents();
// 初始化WebRTC (如果需要)
// initWebRTC();
// // 初始化WebRTC (如果需要)
// // initWebRTC();
console.log('App initialized');
}
// console.log('App initialized');
// }
/**
* 绑定WebSocket事件
@@ -92,14 +92,22 @@ function bindWebSocketEvents() {
console.log('Call request received:', data);
// 显示通话请求弹窗
if (window.showCallRequest) {
const caller = {
name: mockCallSession.remoteUser.name,
avatar:mockCallSession.remoteUser.avatar
};
const caller = {
name: mockCallSession.remoteUser.name,
avatar: mockCallSession.remoteUser.avatar
};
window.showCallRequest(caller);
connectionId =data.connectionId;
connectionId = data.connectionId;
}
});
//处理发送消息响应
wsManager.on('chat-message', (data) => {
console.log('chat-message:', data);
// 显示消息
store.addMessage({
data: data.message,
});
});
}
/**
@@ -221,9 +229,12 @@ function bindDomEvents() {
store.addMessage(newMessage);
chatInput.value = '';
const message = {
connectionId: connectionId,
message: newMessage
};
// 发送消息到服务器
// wsManager.send('send-message', newMessage);
wsManager.send('chat-message', message);
}
};