forked from arekolek/simple-phone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OngoingCall.kt
35 lines (29 loc) · 855 Bytes
/
OngoingCall.kt
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
package com.github.arekolek.phone
import android.telecom.Call
import android.telecom.VideoProfile
import io.reactivex.subjects.BehaviorSubject
import timber.log.Timber
object OngoingCall {
val state: BehaviorSubject<Int> = BehaviorSubject.create()
private val callback = object : Call.Callback() {
override fun onStateChanged(call: Call, newState: Int) {
Timber.d(call.toString())
state.onNext(newState)
}
}
var call: Call? = null
set(value) {
field?.unregisterCallback(callback)
value?.let {
it.registerCallback(callback)
state.onNext(it.state)
}
field = value
}
fun answer() {
call!!.answer(VideoProfile.STATE_AUDIO_ONLY)
}
fun hangup() {
call!!.disconnect()
}
}