mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: アクティブWebSocketハートビートの修復
This commit is contained in:
parent
679b7619ce
commit
c758b1576d
@ -24,8 +24,8 @@ import java.net.URI
|
||||
internal class WebSocketService(
|
||||
host: String,
|
||||
port: Int,
|
||||
val heartbeatInterval: Long,
|
||||
): WebSocketTransmitServlet(host, port) {
|
||||
heartbeatInterval: Long,
|
||||
): WebSocketTransmitServlet(host, port, heartbeatInterval) {
|
||||
private val eventJobList = mutableSetOf<Job>()
|
||||
|
||||
override fun submitFlowJob(job: Job) {
|
||||
@ -85,7 +85,6 @@ internal class WebSocketService(
|
||||
}
|
||||
|
||||
private fun pushMetaLifecycle() {
|
||||
if (heartbeatInterval <= 0) return
|
||||
GlobalScope.launch {
|
||||
val runtime = AppRuntimeFetcher.appRuntime
|
||||
pushTo(PushMetaEvent(
|
||||
|
@ -35,7 +35,8 @@ import kotlin.concurrent.timer
|
||||
|
||||
internal abstract class WebSocketTransmitServlet(
|
||||
host:String,
|
||||
port: Int
|
||||
port: Int,
|
||||
protected val heartbeatInterval: Long,
|
||||
) : BaseTransmitServlet, WebSocketServer(InetSocketAddress(host, port)) {
|
||||
private val sendLock = Mutex()
|
||||
protected val eventReceivers: MutableList<WebSocket> = Collections.synchronizedList(mutableListOf<WebSocket>())
|
||||
@ -56,20 +57,27 @@ internal abstract class WebSocketTransmitServlet(
|
||||
}
|
||||
|
||||
init {
|
||||
timer("heartbeat", true, 0, 1000L * 5) {
|
||||
if (heartbeatInterval > 0) {
|
||||
timer("heartbeat", true, 0, heartbeatInterval) {
|
||||
val runtime = AppRuntimeFetcher.appRuntime
|
||||
val curUin = runtime.currentAccountUin
|
||||
broadcastAnyEvent(PushMetaEvent(
|
||||
broadcastAnyEvent(
|
||||
PushMetaEvent(
|
||||
time = System.currentTimeMillis() / 1000,
|
||||
selfId = app.longAccountUin,
|
||||
postType = PostType.Meta,
|
||||
type = MetaEventType.Heartbeat,
|
||||
subType = MetaSubType.Connect,
|
||||
status = BotStatus(
|
||||
Self("qq", curUin.toLong()), runtime.isLogin, status = "正常", good = true
|
||||
Self("qq", curUin.toLong()),
|
||||
runtime.isLogin,
|
||||
status = "正常",
|
||||
good = true
|
||||
),
|
||||
interval = 15000
|
||||
))
|
||||
interval = heartbeatInterval
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,7 +120,7 @@ internal abstract class WebSocketTransmitServlet(
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
LogCenter.log("WSServer start running on ws://0.0.0.0:$port!")
|
||||
LogCenter.log("WSServer start running on ws://${getAddress()}!")
|
||||
initTransmitter()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user