Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Shamrock: fix disable lost connection detection
Browse files Browse the repository at this point in the history
  • Loading branch information
whitechi73 committed Feb 9, 2024
1 parent dc034a8 commit 6d031ae
Showing 1 changed file with 9 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,24 @@ 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
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
Expand All @@ -50,7 +42,9 @@ internal abstract class WebSocketTransmitServlet(
protected val eventReceivers: MutableList<WebSocket> = Collections.synchronizedList(mutableListOf<WebSocket>())

init {
connectionLostTimeout = 0
if (connectionLostTimeout != 0) {
connectionLostTimeout = 0
}
}

override val address: String
Expand Down Expand Up @@ -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 <reified T> pushTo(body: T) {
if(!allowTransmit()) return
try {
Expand Down

0 comments on commit 6d031ae

Please sign in to comment.