|
|
@ -22,12 +22,12 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) : |
|
|
|
|
|
|
|
|
|
|
|
override fun onOpen() { |
|
|
|
override fun onOpen() { |
|
|
|
launch(IO) { |
|
|
|
launch(IO) { |
|
|
|
do { |
|
|
|
kotlin.runCatching { |
|
|
|
delay(30000) |
|
|
|
while (isOpen) { |
|
|
|
runCatching { |
|
|
|
|
|
|
|
ping("ping".toByteArray()) |
|
|
|
ping("ping".toByteArray()) |
|
|
|
|
|
|
|
delay(30000) |
|
|
|
} |
|
|
|
} |
|
|
|
} while (isOpen) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -42,19 +42,21 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) : |
|
|
|
|
|
|
|
|
|
|
|
override fun onMessage(message: NanoWSD.WebSocketFrame) { |
|
|
|
override fun onMessage(message: NanoWSD.WebSocketFrame) { |
|
|
|
if (!message.textPayload.isJson()) return |
|
|
|
if (!message.textPayload.isJson()) return |
|
|
|
kotlin.runCatching { |
|
|
|
launch(IO) { |
|
|
|
val debugBean = GSON.fromJsonObject<Map<String, String>>(message.textPayload) |
|
|
|
kotlin.runCatching { |
|
|
|
if (debugBean != null) { |
|
|
|
val debugBean = GSON.fromJsonObject<Map<String, String>>(message.textPayload) |
|
|
|
val tag = debugBean["tag"] |
|
|
|
if (debugBean != null) { |
|
|
|
val key = debugBean["key"] |
|
|
|
val tag = debugBean["tag"] |
|
|
|
if (tag.isNullOrBlank() || key.isNullOrBlank()) { |
|
|
|
val key = debugBean["key"] |
|
|
|
send(App.INSTANCE.getString(R.string.cannot_empty)) |
|
|
|
if (tag.isNullOrBlank() || key.isNullOrBlank()) { |
|
|
|
close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false) |
|
|
|
send(App.INSTANCE.getString(R.string.cannot_empty)) |
|
|
|
return |
|
|
|
close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false) |
|
|
|
} |
|
|
|
return@launch |
|
|
|
App.db.bookSourceDao.getBookSource(tag)?.let { |
|
|
|
} |
|
|
|
Debug.callback = this |
|
|
|
App.db.bookSourceDao.getBookSource(tag)?.let { |
|
|
|
Debug.startDebug(this, WebBook(it), key) |
|
|
|
Debug.callback = this@SourceDebugWebSocket |
|
|
|
|
|
|
|
Debug.startDebug(this, WebBook(it), key) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -69,11 +71,15 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) : |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun printLog(state: Int, msg: String) { |
|
|
|
override fun printLog(state: Int, msg: String) { |
|
|
|
kotlin.runCatching { |
|
|
|
launch(IO) { |
|
|
|
send(msg) |
|
|
|
runCatching { |
|
|
|
if (state == -1 || state == 1000) { |
|
|
|
send(msg) |
|
|
|
Debug.cancelDebug(true) |
|
|
|
if (state == -1 || state == 1000) { |
|
|
|
close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false) |
|
|
|
Debug.cancelDebug(true) |
|
|
|
|
|
|
|
close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.onFailure { |
|
|
|
|
|
|
|
it.printStackTrace() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|