reconnect

This commit is contained in:
2026-05-11 14:52:26 +08:00
parent 473e2c2d89
commit 81615a27d9
2 changed files with 14 additions and 3 deletions

View File

@@ -207,6 +207,11 @@ class ListenActivity : AppCompatActivity() {
sendBroadcast(Intent(Constant.WEWORK_NOTIFY).apply { sendBroadcast(Intent(Constant.WEWORK_NOTIFY).apply {
putExtra("type", "modify_channel") putExtra("type", "modify_channel")
}) })
runCatching {
WeworkController.weworkService.reconnectWebSocket("modify_channel_direct")
}.onFailure {
LogUtils.w("重置后直连重连失败,等待广播触发: ${it.message}")
}
HttpUtil.getMyConfig(toast = false) HttpUtil.getMyConfig(toast = false)
MobclickAgent.onProfileSignIn(channel) MobclickAgent.onProfileSignIn(channel)
} }

View File

@@ -50,9 +50,7 @@ class WeworkService : AccessibilityService() {
registerReceiver(object : BroadcastReceiver() { registerReceiver(object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
if (intent.getStringExtra("type") == "modify_channel") { if (intent.getStringExtra("type") == "modify_channel") {
LogUtils.e("更新channel") reconnectWebSocket("modify_channel")
webSocketManager.close(1000, "modify_channel")
initWebSocket()
} }
} }
}, IntentFilter(Constant.WEWORK_NOTIFY)) }, IntentFilter(Constant.WEWORK_NOTIFY))
@@ -65,6 +63,14 @@ class WeworkService : AccessibilityService() {
webSocketManager = WebSocketManager(url, listener) webSocketManager = WebSocketManager(url, listener)
} }
fun reconnectWebSocket(reason: String) {
LogUtils.i("reconnectWebSocket: $reason")
if (::webSocketManager.isInitialized) {
webSocketManager.close(1000, reason)
}
initWebSocket()
}
private fun initObserver() { private fun initObserver() {
if (!Constant.pushImage) return if (!Constant.pushImage) return
try { try {