mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-23 16:21:26 +01:00
Renew turnserver credentials when ttl runs out
The previous implementation caches the turnserver response indefinitely.
This breaks VoIP calls as soon as the ttl of the received turnserver
credentials runs out. So, take care to renew the turnserver credentials
by allowing the cache to expire.
Fixes: d8cf44fdc9
("Simple cache of turn server response")
Signed-off-by: Thomas Zeitlhofer <tz+github@ze-it.at>
This commit is contained in:
parent
29e4a64475
commit
a7ee7d5bad
@ -58,18 +58,32 @@ internal class DefaultCallSignalingService @Inject constructor(
|
||||
|
||||
private val activeCalls = mutableListOf<MxCall>()
|
||||
|
||||
private var cachedTurnServerResponse: TurnServerResponse? = null
|
||||
private var cachedTurnServerResponse = object {
|
||||
|
||||
private val MIN_TTL = 60
|
||||
|
||||
private val now = { System.currentTimeMillis() / 1000 }
|
||||
|
||||
private var expiresAt: Long = 0
|
||||
|
||||
var data: TurnServerResponse? = null
|
||||
get() = if (expiresAt > now()) field else null
|
||||
set(value) {
|
||||
expiresAt = now() + (value?.ttl ?: 0) - MIN_TTL
|
||||
field = value
|
||||
}
|
||||
}
|
||||
|
||||
override fun getTurnServer(callback: MatrixCallback<TurnServerResponse>): Cancelable {
|
||||
if (cachedTurnServerResponse != null) {
|
||||
cachedTurnServerResponse?.let { callback.onSuccess(it) }
|
||||
if (cachedTurnServerResponse.data != null) {
|
||||
cachedTurnServerResponse.data?.let { callback.onSuccess(it) }
|
||||
return NoOpCancellable
|
||||
}
|
||||
return turnServerTask
|
||||
.configureWith(GetTurnServerTask.Params) {
|
||||
this.callback = object : MatrixCallback<TurnServerResponse> {
|
||||
override fun onSuccess(data: TurnServerResponse) {
|
||||
cachedTurnServerResponse = data
|
||||
cachedTurnServerResponse.data = data
|
||||
callback.onSuccess(data)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user