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(
|
internal class WebSocketService(
|
||||||
host: String,
|
host: String,
|
||||||
port: Int,
|
port: Int,
|
||||||
val heartbeatInterval: Long,
|
heartbeatInterval: Long,
|
||||||
): WebSocketTransmitServlet(host, port) {
|
): WebSocketTransmitServlet(host, port, heartbeatInterval) {
|
||||||
private val eventJobList = mutableSetOf<Job>()
|
private val eventJobList = mutableSetOf<Job>()
|
||||||
|
|
||||||
override fun submitFlowJob(job: Job) {
|
override fun submitFlowJob(job: Job) {
|
||||||
@ -85,7 +85,6 @@ internal class WebSocketService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun pushMetaLifecycle() {
|
private fun pushMetaLifecycle() {
|
||||||
if (heartbeatInterval <= 0) return
|
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
val runtime = AppRuntimeFetcher.appRuntime
|
val runtime = AppRuntimeFetcher.appRuntime
|
||||||
pushTo(PushMetaEvent(
|
pushTo(PushMetaEvent(
|
||||||
|
@ -35,7 +35,8 @@ import kotlin.concurrent.timer
|
|||||||
|
|
||||||
internal abstract class WebSocketTransmitServlet(
|
internal abstract class WebSocketTransmitServlet(
|
||||||
host:String,
|
host:String,
|
||||||
port: Int
|
port: Int,
|
||||||
|
protected val heartbeatInterval: Long,
|
||||||
) : BaseTransmitServlet, WebSocketServer(InetSocketAddress(host, port)) {
|
) : BaseTransmitServlet, WebSocketServer(InetSocketAddress(host, port)) {
|
||||||
private val sendLock = Mutex()
|
private val sendLock = Mutex()
|
||||||
protected val eventReceivers: MutableList<WebSocket> = Collections.synchronizedList(mutableListOf<WebSocket>())
|
protected val eventReceivers: MutableList<WebSocket> = Collections.synchronizedList(mutableListOf<WebSocket>())
|
||||||
@ -56,20 +57,27 @@ internal abstract class WebSocketTransmitServlet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
timer("heartbeat", true, 0, 1000L * 5) {
|
if (heartbeatInterval > 0) {
|
||||||
val runtime = AppRuntimeFetcher.appRuntime
|
timer("heartbeat", true, 0, heartbeatInterval) {
|
||||||
val curUin = runtime.currentAccountUin
|
val runtime = AppRuntimeFetcher.appRuntime
|
||||||
broadcastAnyEvent(PushMetaEvent(
|
val curUin = runtime.currentAccountUin
|
||||||
time = System.currentTimeMillis() / 1000,
|
broadcastAnyEvent(
|
||||||
selfId = app.longAccountUin,
|
PushMetaEvent(
|
||||||
postType = PostType.Meta,
|
time = System.currentTimeMillis() / 1000,
|
||||||
type = MetaEventType.Heartbeat,
|
selfId = app.longAccountUin,
|
||||||
subType = MetaSubType.Connect,
|
postType = PostType.Meta,
|
||||||
status = BotStatus(
|
type = MetaEventType.Heartbeat,
|
||||||
Self("qq", curUin.toLong()), runtime.isLogin, status = "正常", good = true
|
subType = MetaSubType.Connect,
|
||||||
),
|
status = BotStatus(
|
||||||
interval = 15000
|
Self("qq", curUin.toLong()),
|
||||||
))
|
runtime.isLogin,
|
||||||
|
status = "正常",
|
||||||
|
good = true
|
||||||
|
),
|
||||||
|
interval = heartbeatInterval
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +120,7 @@ internal abstract class WebSocketTransmitServlet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
LogCenter.log("WSServer start running on ws://0.0.0.0:$port!")
|
LogCenter.log("WSServer start running on ws://${getAddress()}!")
|
||||||
initTransmitter()
|
initTransmitter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user