From 6d031ae866deb1f917b748cf908a0fb9e2ab3474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B1=A0?= Date: Sat, 10 Feb 2024 00:46:19 +0800 Subject: [PATCH] `Shamrock`: fix disable lost connection detection --- .../service/api/WebSocketTransmitServlet.kt | 40 +++++-------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/WebSocketTransmitServlet.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/WebSocketTransmitServlet.kt index 9f83dca2..c91ecb1d 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/WebSocketTransmitServlet.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/WebSocketTransmitServlet.kt @@ -9,10 +9,11 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json -import moe.fuqiuluo.shamrock.helper.Level -import moe.fuqiuluo.shamrock.helper.LogCenter import moe.fuqiuluo.shamrock.remote.action.ActionManager import moe.fuqiuluo.shamrock.remote.action.ActionSession +import moe.fuqiuluo.shamrock.remote.structures.EmptyObject +import moe.fuqiuluo.shamrock.remote.structures.Status +import moe.fuqiuluo.shamrock.remote.structures.resultToString import moe.fuqiuluo.shamrock.remote.service.config.ShamrockConfig import moe.fuqiuluo.shamrock.remote.service.data.BotStatus import moe.fuqiuluo.shamrock.remote.service.data.Self @@ -20,21 +21,12 @@ import moe.fuqiuluo.shamrock.remote.service.data.push.MetaEventType import moe.fuqiuluo.shamrock.remote.service.data.push.MetaSubType import moe.fuqiuluo.shamrock.remote.service.data.push.PostType import moe.fuqiuluo.shamrock.remote.service.data.push.PushMetaEvent -import moe.fuqiuluo.shamrock.remote.structures.EmptyObject -import moe.fuqiuluo.shamrock.remote.structures.Status -import moe.fuqiuluo.shamrock.remote.structures.resultToString -import moe.fuqiuluo.shamrock.tools.EmptyJsonObject -import moe.fuqiuluo.shamrock.tools.EmptyJsonString import moe.fuqiuluo.shamrock.tools.GlobalJson -import moe.fuqiuluo.shamrock.tools.asJsonObject -import moe.fuqiuluo.shamrock.tools.asJsonObjectOrNull -import moe.fuqiuluo.shamrock.tools.asString -import moe.fuqiuluo.shamrock.tools.asStringOrNull +import moe.fuqiuluo.shamrock.tools.* +import moe.fuqiuluo.shamrock.helper.Level +import moe.fuqiuluo.shamrock.helper.LogCenter import moe.fuqiuluo.shamrock.xposed.helper.AppRuntimeFetcher import org.java_websocket.WebSocket -import org.java_websocket.framing.Framedata -import org.java_websocket.framing.PingFrame -import org.java_websocket.framing.PongFrame import org.java_websocket.server.WebSocketServer import java.net.InetSocketAddress import java.net.URI @@ -50,7 +42,9 @@ internal abstract class WebSocketTransmitServlet( protected val eventReceivers: MutableList = Collections.synchronizedList(mutableListOf()) init { - connectionLostTimeout = 0 + if (connectionLostTimeout != 0) { + connectionLostTimeout = 0 + } } override val address: String @@ -145,22 +139,6 @@ internal abstract class WebSocketTransmitServlet( initTransmitter() } - override fun onWebsocketPong(conn: WebSocket, f: Framedata) { - super.onWebsocketPong(conn, f) - } - - override fun onWebsocketPing(conn: WebSocket, f: Framedata) { - conn.sendFrame(PongFrame(f as PingFrame)) - val path = URI.create(conn.resourceDescriptor).path - runCatching { - conn.remoteSocketAddress.address.hostAddress to conn.remoteSocketAddress.port - }.onSuccess { - LogCenter.log({ "WSServer pong -> ${it.first}:${it.second}$path" }, Level.WARN) - }.onFailure { - LogCenter.log({ "WSServer pong -> $conn" }, Level.WARN) - } - } - protected suspend inline fun pushTo(body: T) { if(!allowTransmit()) return try {