-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallback.kt
More file actions
41 lines (34 loc) · 963 Bytes
/
Callback.kt
File metadata and controls
41 lines (34 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package io.agora.rtc.base
import io.agora.rtc.Constants
import io.agora.rtc.RtcEngine
import kotlin.math.abs
abstract class Callback {
fun code(code: Int?, runnable: ((Int?) -> Any?)? = null) {
if (code == null || code < 0) {
val newCode = abs(code ?: Constants.ERR_NOT_INITIALIZED)
failure(newCode.toString(), RtcEngine.getErrorDescription(newCode))
return
}
val res = if (runnable != null) runnable(code) else Unit
if (res is Unit) {
success(null)
} else {
success(res)
}
}
fun <T> resolve(source: T?, runnable: (T) -> Any?) {
if (source == null) {
val code = Constants.ERR_NOT_INITIALIZED
failure(code.toString(), RtcEngine.getErrorDescription(code))
return
}
val res = runnable(source)
if (res is Unit) {
success(null)
} else {
success(res)
}
}
abstract fun success(data: Any?)
abstract fun failure(code: String, message: String)
}