Skip to content
This repository was archived by the owner on Oct 5, 2020. It is now read-only.

Commit 91e4e4c

Browse files
dinuchiriacjoextodd
authored andcommitted
wrap sdk callbacks jobs on UI thread
1 parent 37a5d83 commit 91e4e4c

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

android/src/main/kotlin/io/chirp/chirpsdk/ChirpsdkPlugin.kt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,49 @@ class ChirpsdkPlugin(val activity: Activity) : MethodCallHandler {
7171
* onSending is called when a send event begins.
7272
* The data argument contains the payload being sent.
7373
*/
74-
sendingStreamHandler.send(payload, channel)
74+
activity.runOnUiThread {
75+
sendingStreamHandler.send(payload, channel)
76+
}
7577
}
7678
chirpConnect.onSent { payload: ByteArray, channel: Int ->
7779
/**
7880
* onSent is called when a send event has completed.
7981
* The payload argument contains the payload data that was sent.
8082
*/
81-
sentStreamHandler.send(payload, channel)
83+
activity.runOnUiThread {
84+
sentStreamHandler.send(payload, channel)
85+
}
8286
}
8387
chirpConnect.onReceiving { channel: Int ->
8488
/**
8589
* onReceiving is called when a receive event begins.
8690
* No data has yet been received.
8791
*/
88-
receivingStreamHandler.send(channel)
92+
activity.runOnUiThread {
93+
receivingStreamHandler.send(channel)
94+
}
8995
}
9096
chirpConnect.onReceived { payload: ByteArray?, channel: Int ->
9197
/**
9298
* onReceived is called when a receive event has completed.
9399
* If the payload was decoded successfully, it is passed in payload.
94100
* Otherwise, payload is null.
95101
*/
96-
if (payload != null) {
97-
receivedStreamHandler.send(payload, channel)
98-
} else {
99-
errorStreamHandler.send(0, "Chirp: Decode failed.")
102+
activity.runOnUiThread {
103+
if (payload != null) {
104+
receivedStreamHandler.send(payload, channel)
105+
} else {
106+
errorStreamHandler.send(0, "Chirp: Decode failed.")
107+
}
100108
}
101109
}
102110
chirpConnect.onStateChanged { oldState: ChirpConnectState, newState: ChirpConnectState ->
103111
/**
104112
* onStateChanged is called when the SDK changes state.
105113
*/
106-
stateStreamHandler.send(oldState.code, newState.code)
114+
activity.runOnUiThread {
115+
stateStreamHandler.send(oldState.code, newState.code)
116+
}
107117
}
108118
chirpConnect.onSystemVolumeChanged { oldVolume: Float, newVolume: Float ->
109119
/**

0 commit comments

Comments
 (0)