Skip to content

Commit 61f79e1

Browse files
committed
Small fix
1 parent 24524f2 commit 61f79e1

File tree

3 files changed

+48
-26
lines changed

3 files changed

+48
-26
lines changed

.idea/gradle.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/main/java/com/omegar/libs/testconnect/SocketClient.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,6 @@ internal class SocketClient(
5353
}
5454
}
5555

56-
override fun onClose(code: Int, reason: String?, remote: Boolean) {
57-
waitAndReconnect()
58-
}
59-
60-
override fun onError(ex: Exception?) {
61-
// nothing
62-
}
63-
64-
private fun waitAndReconnect() {
65-
reconnectJob = launch {
66-
delay(2000)
67-
reconnect()
68-
}
69-
}
70-
7156
fun sendLog(logText: String) {
7257
if (!isClosed) {
7358
send("$HEADER_LOG:$logText")
@@ -83,6 +68,21 @@ internal class SocketClient(
8368
}
8469
}
8570

71+
override fun onError(ex: Exception?) {
72+
// nothing
73+
}
74+
75+
override fun onClose(code: Int, reason: String?, remote: Boolean) {
76+
waitAndReconnect()
77+
}
78+
79+
private fun waitAndReconnect() {
80+
reconnectJob = launch {
81+
delay(2000)
82+
reconnect()
83+
}
84+
}
85+
8686
interface Callback {
8787

8888
fun startLog()

lib/src/main/java/com/omegar/libs/testconnect/TestConnector.kt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal object TestConnector : Callback, CoroutineScope {
2727

2828
private var socketClient: SocketClient? = null
2929
private var activityCatcher: ActivityCatcher? = null
30-
private val logCatcher = LogCatcher()
30+
private var logCatcher: LogCatcher? = null
3131

3232
private var logJob: Job? = null
3333
set(value) {
@@ -62,21 +62,24 @@ internal object TestConnector : Callback, CoroutineScope {
6262
}
6363

6464
fun init(context: Context) {
65-
socketClient = SocketClient(
66-
url = "ws://192.168.10.57:8080/ws",
67-
deviceName = context.deviceName,
68-
appName = context.appName,
69-
appVersion = context.appVersion,
70-
callback = this
71-
).apply {
72-
connect()
65+
if (BuildConfig.DEBUG) {
66+
logCatcher = LogCatcher()
67+
socketClient = SocketClient(
68+
url = "ws://192.168.10.57:8080/ws",
69+
deviceName = context.deviceName,
70+
appName = context.appName,
71+
appVersion = context.appVersion,
72+
callback = this
73+
).apply {
74+
connect()
75+
}
76+
activityCatcher = ActivityCatcher(context)
7377
}
74-
activityCatcher = ActivityCatcher(context)
7578
}
7679

7780
override fun startLog() {
7881
logJob = launch {
79-
logCatcher.flow.collect {
82+
logCatcher?.flow?.collect {
8083
socketClient?.sendLog(it)
8184
}
8285
}

0 commit comments

Comments
 (0)