websocket
This commit is contained in:
@@ -207,11 +207,16 @@ class ListenActivity : AppCompatActivity() {
|
||||
sendBroadcast(Intent(Constant.WEWORK_NOTIFY).apply {
|
||||
putExtra("type", "modify_channel")
|
||||
})
|
||||
if (WeworkController.isServiceReady()) {
|
||||
runCatching {
|
||||
WeworkController.weworkService.reconnectWebSocket("modify_channel_direct")
|
||||
}.onFailure {
|
||||
LogUtils.w("重置后直连重连失败,等待广播触发: ${it.message}")
|
||||
}
|
||||
} else {
|
||||
ToastUtils.showLong("无障碍服务未运行,请先开启后再重置")
|
||||
LogUtils.w("重置时服务未就绪,无法触发直连重连")
|
||||
}
|
||||
HttpUtil.getMyConfig(toast = false)
|
||||
MobclickAgent.onProfileSignIn(channel)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ object WeworkController {
|
||||
/** 是否正在等待回复 - 等待时会暂停主循环扫描新消息 */
|
||||
var waitingForReply = false
|
||||
|
||||
fun isServiceReady(): Boolean = ::weworkService.isInitialized
|
||||
|
||||
/**
|
||||
* 交互通知
|
||||
* @see WeworkMessageBean.TYPE_CONSOLE_TOAST
|
||||
|
||||
@@ -123,9 +123,7 @@ class WeworkService : AccessibilityService() {
|
||||
|
||||
inner class EchoWebSocketListener : WebSocketListener() {
|
||||
private val TAG = "WeworkService.EchoWebSocketListener"
|
||||
private lateinit var socket: WebSocket
|
||||
override fun onOpen(webSocket: WebSocket, response: Response) {
|
||||
socket = webSocket
|
||||
Log.e(TAG, "连接建立")
|
||||
val robotId = Constant.robotId
|
||||
val appVersion = SPUtils.getInstance().getString("appVersion", "")
|
||||
@@ -157,14 +155,14 @@ class WeworkService : AccessibilityService() {
|
||||
|
||||
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
|
||||
super.onClosing(webSocket, code, reason)
|
||||
socket.close(code, reason)
|
||||
webSocket.close(code, reason)
|
||||
Log.e(TAG, "服务端关闭连接 $code: $reason")
|
||||
sendBroadcast(false)
|
||||
}
|
||||
|
||||
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
|
||||
//服务器中断
|
||||
Log.e(TAG, "连接错误: " + t.toString() + response.toString())
|
||||
Log.e(TAG, "连接错误: ${t.message} response=${response?.code}")
|
||||
sendBroadcast(false)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user