mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-12 12:13:46 +08:00
在进行 socket 连接前先关闭之前连接。实现新建会话功能。
This commit is contained in:
@@ -238,6 +238,7 @@ export default defineComponent({
|
||||
connectingMessageBox: null, // 保存重连的消息框对象
|
||||
errorMessage: null, // 错误信息提示框
|
||||
socket: null,
|
||||
activelyClose: false, // 主动关闭
|
||||
mainWinHeight: 0, // 主窗口高度
|
||||
chatBoxHeight: 0, // 聊天内容框高度
|
||||
leftBoxHeight: 0,
|
||||
@@ -284,6 +285,12 @@ export default defineComponent({
|
||||
},
|
||||
// 创建 socket 会话连接
|
||||
connect: function () {
|
||||
// 先关闭已有连接
|
||||
if (this.socket !== null) {
|
||||
this.activelyClose = true;
|
||||
this.socket.close();
|
||||
}
|
||||
|
||||
// 初始化 WebSocket 对象
|
||||
const sessionId = getSessionId();
|
||||
const socket = new WebSocket(process.env.VUE_APP_WS_HOST + `/api/chat?sessionId=${sessionId}&role=${this.role}`);
|
||||
@@ -303,6 +310,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
this.sending = false; // 允许用户发送消息
|
||||
this.activelyClose = false;
|
||||
if (this.errorMessage !== null) {
|
||||
this.errorMessage.close(); // 关闭错误提示信息
|
||||
}
|
||||
@@ -359,6 +367,10 @@ export default defineComponent({
|
||||
});
|
||||
|
||||
socket.addEventListener('close', () => {
|
||||
if (this.activelyClose) { // 忽略主动关闭
|
||||
return;
|
||||
}
|
||||
|
||||
// 停止送消息
|
||||
this.sending = true;
|
||||
this.checkSession();
|
||||
|
||||
Reference in New Issue
Block a user