Commit 85e5b838 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Adds a timer to call the updateJitsiTimeout

parent f4a743d4
...@@ -11,7 +11,9 @@ import chat.rocket.core.internal.realtime.updateJitsiTimeout ...@@ -11,7 +11,9 @@ import chat.rocket.core.internal.realtime.updateJitsiTimeout
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.util.*
import javax.inject.Inject import javax.inject.Inject
import kotlin.concurrent.timer
class VideoConferencingPresenter @Inject constructor( class VideoConferencingPresenter @Inject constructor(
private val view: VideoConferencingView, private val view: VideoConferencingView,
...@@ -25,6 +27,7 @@ class VideoConferencingPresenter @Inject constructor( ...@@ -25,6 +27,7 @@ class VideoConferencingPresenter @Inject constructor(
private lateinit var client: RocketChatClient private lateinit var client: RocketChatClient
private lateinit var publicSettings: PublicSettings private lateinit var publicSettings: PublicSettings
private lateinit var chatRoomId: String private lateinit var chatRoomId: String
private lateinit var timer: Timer
fun setup(chatRoomId: String) { fun setup(chatRoomId: String) {
currentServerRepository.get()?.let { currentServerRepository.get()?.let {
...@@ -48,14 +51,19 @@ class VideoConferencingPresenter @Inject constructor( ...@@ -48,14 +51,19 @@ class VideoConferencingPresenter @Inject constructor(
chatRoomId chatRoomId
) )
) )
updateJitsiTimeout()
} }
client.updateJitsiTimeout(chatRoomId)
} }
} }
// Jitsi update call needs to be called every 10 seconds to make sure call is not ended and is available to web users.
private fun updateJitsiTimeout() { private fun updateJitsiTimeout() {
GlobalScope.launch(Dispatchers.IO + strategy.jobs) { timer = timer(daemon = false, initialDelay = 0L, period = 10000) {
client.updateJitsiTimeout(chatRoomId) GlobalScope.launch(Dispatchers.IO + strategy.jobs) {
client.updateJitsiTimeout(chatRoomId)
}
} }
} }
fun invalidateTimer() = timer.cancel()
} }
...@@ -32,5 +32,10 @@ class VideoConferencingActivity : JitsiMeetActivity(), VideoConferencingView { ...@@ -32,5 +32,10 @@ class VideoConferencingActivity : JitsiMeetActivity(), VideoConferencingView {
presenter.setupVideoConferencing() presenter.setupVideoConferencing()
} }
override fun onDestroy() {
super.onDestroy()
presenter.invalidateTimer()
}
override fun startVideoConferencing(url: URL) = loadURL(url) override fun startVideoConferencing(url: URL) = loadURL(url)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment