update heartbeat check

This commit is contained in:
2023-11-13 21:31:37 +08:00
parent 0847af205e
commit 7e6ae3afa7
2 changed files with 20 additions and 8 deletions

View File

@@ -152,19 +152,31 @@ function updateUsers() {
} }
async function start() { async function start() {
if (!chatClient) { if (!chatClient) {
const auth = await get() await connectRoom()
if (auth) {
authResult.value = auth
} else {
return
}
initChatClient()
isConnected.value = true isConnected.value = true
setInterval(() => { setInterval(() => {
QueryPostAPI<OpenLiveInfo>(OPEN_LIVE_API_URL + 'heartbeat', authInfo.value) if (chatClient) {
QueryPostAPI<OpenLiveInfo>(OPEN_LIVE_API_URL + 'heartbeat', authInfo.value).then((data) => {
if (data.code != 200) {
console.error('[OPEN-LIVE] 心跳失败: ' + data.message)
chatClient.stop()
chatClient = null
connectRoom()
}
})
}
}, 20 * 1000) }, 20 * 1000)
} }
} }
async function connectRoom() {
const auth = await get()
if (auth) {
authResult.value = auth
} else {
return
}
initChatClient()
}
async function initChatClient() { async function initChatClient() {
chatClient = new ChatClientDirectOpenLive(authResult.value) chatClient = new ChatClientDirectOpenLive(authResult.value)