client: 自动进行重新验证
This commit is contained in:
@@ -24,11 +24,39 @@ class Client {
|
||||
session_id: this.sessionId,
|
||||
},
|
||||
})
|
||||
this.socket!.on("connect", async () => {
|
||||
this.socket!.on("connect", () => {
|
||||
const auth = async () => {
|
||||
this.connected = true
|
||||
const re = await this.auth(data.access_token as string)
|
||||
if (re.code != 200)
|
||||
checkApiSuccessOrSncakbar(re, "重连失败")
|
||||
const s = snackbar({
|
||||
message: '重新验证中...',
|
||||
placement: 'top',
|
||||
autoCloseDelay: 0,
|
||||
})
|
||||
let i = 1
|
||||
const id = setInterval(() => {
|
||||
s.textContent = `重新验证中... (${i}s)`
|
||||
i++
|
||||
}, 1000)
|
||||
const re = await this.auth(data.access_token as string, 6000)
|
||||
if (re.code != 200) {
|
||||
if (re.code == -1) {
|
||||
auth()
|
||||
} else if (re.code != 401) {
|
||||
const s2 = checkApiSuccessOrSncakbar(re, "重新验证失败")
|
||||
s2!.autoCloseDelay = 0
|
||||
s2!.action = "重试"
|
||||
s2!.addEventListener('action-click', () => {
|
||||
auth()
|
||||
})
|
||||
this.socket!.once("disconnect", () => {
|
||||
s2!.open = false
|
||||
})
|
||||
}
|
||||
}
|
||||
s.open = false
|
||||
clearTimeout(id)
|
||||
}
|
||||
auth()
|
||||
})
|
||||
this.socket!.on("disconnect", () => {
|
||||
this.connected = false
|
||||
|
||||
Reference in New Issue
Block a user