mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-06 17:23:42 +08:00
opt: add heartbeat message for websocket connects
This commit is contained in:
@@ -543,6 +543,7 @@ const lineBuffer = ref(''); // 输出缓冲行
|
||||
const socket = ref(null);
|
||||
const activelyClose = ref(false); // 主动关闭
|
||||
const canSend = ref(true);
|
||||
const heartbeatHandle = ref(null)
|
||||
const connect = function (chat_id, role_id) {
|
||||
let isNewChat = false;
|
||||
if (!chat_id) {
|
||||
@@ -589,6 +590,14 @@ const connect = function (chat_id, role_id) {
|
||||
loadChatHistory(chat_id);
|
||||
}
|
||||
|
||||
// 发送心跳消息
|
||||
clearInterval(heartbeatHandle.value)
|
||||
heartbeatHandle.value = setInterval(() => {
|
||||
if (socket.value !== null) {
|
||||
socket.value.send(JSON.stringify({type: "heartbeat", content: "ping"}))
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
});
|
||||
|
||||
_socket.addEventListener('message', event => {
|
||||
@@ -718,7 +727,7 @@ const sendMessage = function () {
|
||||
|
||||
showHello.value = false
|
||||
disableInput(false)
|
||||
socket.value.send(prompt.value);
|
||||
socket.value.send(JSON.stringify({type: "chat", content: prompt.value}));
|
||||
previousText.value = prompt.value;
|
||||
prompt.value = '';
|
||||
return true;
|
||||
|
||||
@@ -200,6 +200,7 @@ const lineBuffer = ref(''); // 输出缓冲行
|
||||
const socket = ref(null);
|
||||
const activelyClose = ref(false); // 主动关闭
|
||||
const canSend = ref(true);
|
||||
const heartbeatHandle = ref(null)
|
||||
const connect = function (chat_id, role_id) {
|
||||
let isNewChat = false;
|
||||
if (!chat_id) {
|
||||
@@ -238,6 +239,14 @@ const connect = function (chat_id, role_id) {
|
||||
orgContent: role.helloMsg,
|
||||
})
|
||||
}
|
||||
|
||||
// 发送心跳消息
|
||||
clearInterval(heartbeatHandle.value)
|
||||
heartbeatHandle.value = setInterval(() => {
|
||||
if (socket.value !== null) {
|
||||
socket.value.send(JSON.stringify({type: "heartbeat", content: "ping"}))
|
||||
}
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
_socket.addEventListener('message', event => {
|
||||
@@ -370,7 +379,7 @@ const sendMessage = () => {
|
||||
})
|
||||
|
||||
disableInput(false)
|
||||
socket.value.send(prompt.value);
|
||||
socket.value.send(JSON.stringify({type: "chat", content: prompt.value}));
|
||||
previousText.value = prompt.value;
|
||||
prompt.value = '';
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user