Skip to content

Commit

Permalink
try fix not reconnect when code is NORMAL(1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXiaoM committed Aug 14, 2024
1 parent b2f92a1 commit e2ed65e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion onebot/src/main/kotlin/client/connection/WSClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WSClient(
header: Map<String, String> = mapOf(),
) : WebSocketClient(uri, header), IAdapter {
private var retryCount = 0
private var scheduleClose = false
@OptIn(InternalCoroutinesApi::class)
private val connectDef = CompletableDeferred<Boolean>(config.parentJob).apply {
invokeOnCompletion(
Expand All @@ -48,6 +49,16 @@ class WSClient(
logger.info("▌ 已连接到服务器 ┈━═☆")
}

override fun connect() {
scheduleClose = false
super.connect()
}

override fun close() {
scheduleClose = true
super.close()
}

override fun onMessage(message: String) = onReceiveMessage(message)

override fun onClose(code: Int, reason: String, remote: Boolean) {
Expand All @@ -59,7 +70,7 @@ class WSClient(
unlockMutex()

// 自动重连
if (code != CloseFrame.NORMAL) retry()
if (!scheduleClose) retry()
}

private fun retry() {
Expand Down

0 comments on commit e2ed65e

Please sign in to comment.