mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-05-30 21:00:30 +08:00
fix: auto-repair origin not allowed in connect handshake + cleanup duplicate listeners
This commit is contained in:
@@ -172,9 +172,9 @@ export class WsClient {
|
||||
const errCode = msg.error?.code
|
||||
console.error('[ws] connect 失败:', errMsg, errCode)
|
||||
|
||||
// 如果是配对错误,尝试自动配对
|
||||
if (errCode === 'NOT_PAIRED' || errCode === 'PAIRING_REQUIRED') {
|
||||
console.log('[ws] 检测到未配对,尝试自动配对...')
|
||||
// 如果是配对/origin 错误,尝试自动配对
|
||||
if (errCode === 'NOT_PAIRED' || errCode === 'PAIRING_REQUIRED' || /origin not allowed/i.test(errMsg)) {
|
||||
console.log('[ws] 检测到配对/origin 错误,尝试自动修复...', errCode || errMsg)
|
||||
this._autoPairAndReconnect()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ function bindConnectOverlay(page) {
|
||||
if (desc) desc.textContent = '修复完成,正在重连...'
|
||||
// 断开旧连接,重新发起
|
||||
wsClient.disconnect()
|
||||
setTimeout(() => connectGateway(), 1000)
|
||||
setTimeout(() => connectGateway(), 3000)
|
||||
} catch (e) {
|
||||
if (desc) desc.textContent = '修复失败: ' + (e.message || e)
|
||||
} finally {
|
||||
@@ -304,6 +304,11 @@ function renderAttachments() {
|
||||
|
||||
async function connectGateway() {
|
||||
try {
|
||||
// 清理旧的订阅,避免重复监听
|
||||
if (_unsubStatus) { _unsubStatus(); _unsubStatus = null }
|
||||
if (_unsubReady) { _unsubReady(); _unsubReady = null }
|
||||
if (_unsubEvent) { _unsubEvent(); _unsubEvent = null }
|
||||
|
||||
// 订阅状态变化(订阅式,返回 unsub)
|
||||
_unsubStatus = wsClient.onStatusChange((status, errorMsg) => {
|
||||
if (!_pageActive) return
|
||||
|
||||
Reference in New Issue
Block a user